2014-04-15 48 views

回答

2

假設您的插件位於WordPress存儲庫中,那麼您可以通過掛接WordPress更新功能來完成此操作。需要注意的是get_site_transient()總是使用回落到get_option()當它不是一個多站點安裝..

// Your plugin file 
$plugin = 'plugin-dir/plugin-file.php'; 

// Check for Plugin updates, if you want to (not recommended for all pages) 
// wp_update_plugins(); 

// Results of the update check 
$update_plugins = get_site_transient('update_plugins'); 
if (isset($update_plugins->response[ $plugin ])) { 
    // Your plugin needs an update 
} 

update_plugins$update_plugins->response結果爲array(),這將是這樣的:

'response' => 
    array (
    'plugin-dir/plugin-file.php' => 
    stdClass::__set_state(array(
     'id' => '12345', 
     'slug' => 'plugin-file', 
     'plugin' => 'plugin-dir/plugin-file.php', 
     'new_version' => '1.2.3', 
     'url' => 'https://wordpress.org/plugins/plugin-dir/', 
     'package' => 'https://downloads.wordpress.org/plugin/plugin-dir.1.2.3.zip', 
    )), 
),