2017-05-12 57 views
0

有一些不支持自動更新的第三方WordPress插件。所以,如果你已經安裝了一個插件的v1.0和您嘗試安裝新版本(例如V1.1),你最終會得到消息:有沒有辦法強制Wordpress在安裝時覆蓋插件文件?

Destination folder already exists. /home/.../.../... 

這留下兩個選擇,既不我想使用:卸載&重新安裝插件,或通過FTP手動上傳新文件。

在/wp-admin/includes/class-wp-upgrader.php線428我看到這個代碼:

public function install_package($args = array()) { 
    global $wp_filesystem, $wp_theme_directories; 

    $defaults = array(
     'source' => '', // Please always pass this 
     'destination' => '', // and this 
     'clear_destination' => false, 
     'clear_working' => false, 
     'abort_if_destination_exists' => true, 
     'hook_extra' => array() 
    ); 

    $args = wp_parse_args($args, $defaults); 

    ... 

是否可以添加一行到我的主題的functions.php文件重新聲明'clear_destination'爲true,從而迫使Wordpress在我上傳插件文件時覆蓋它們?

謝謝

回答

0

不,這是不可能的。您需要編輯核心文件。

但是你可以在相關的網站(s)表示,將採取照顧的問題上爲您安裝一個插件:http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/

或者你可以在你的插件,這使得它能夠以服務的更新中包含的更新框架從私人回購(例如不是WP):https://github.com/afragen/github-updater

或者,您可以使用類似WPPusher的東西,它可以在更新推送到Github/BitBucket時自動更新插件。我個人使用這個插件來測試我正在構建的插件版本。

1

我不斷挖掘,並認爲我找到了解決方案。如果我創建自定義插件,則可以使用'upgrader_package_options'過濾器重新聲明選項:

function override_plugins($options) { 

    $options['clear_destination'] = true; 
    $options['abort_if_destination_exists'] = false; 

    return $options; 
} 
add_filter('upgrader_package_options', 'override_plugins'); 
相關問題