답변:
functions.php에서 질문의 코드를 사용하는 대신 다음과 같이 바꾸십시오.
/**
* Prevent certain plugins from receiving automatic updates, and auto-update the rest.
*
* To auto-update certain plugins and exclude the rest, simply remove the "!" operator
* from the function.
*
* Also, by using the 'auto_update_theme' or 'auto_update_core' filter instead, certain
* themes or Wordpress versions can be included or excluded from updates.
*
* auto_update_$type filter: applied on line 1772 of /wp-admin/includes/class-wp-upgrader.php
*
* @since 3.8.2
*
* @param bool $update Whether to update (not used for plugins)
* @param object $item The plugin's info
*/
function exclude_plugins_from_auto_update( $update, $item ) {
return ( ! in_array( $item->slug, array(
'akismet',
'buddypress',
) ) );
}
add_filter( 'auto_update_plugin', 'exclude_plugins_from_auto_update', 10, 2 );
이 코드는 테마 및 핵심 업데이트를 사용자 정의하기 위해 쉽게 조정할 수 있습니다.
플러그인 및 테마 업데이트 통계가 Wordpress 3.8.2 ( 27905 )에 추가되었습니다 . 위의 함수는 슬러그를 사용하여 플러그인을 식별하지만 객체 정보 ($ item)를 사용할 수 있습니다.
[id] => 15
[slug] => akismet
[plugin] => akismet/akismet.php
[new_version] => 3.0.0
[url] => https://wordpress.org/plugins/akismet/
[package] => https://downloads.wordpress.org/plugin/akismet.3.0.0.zip
Wordpress 3.8.1 이하의 경우이 기능을 대신 사용하십시오.
function exclude_plugins_from_auto_update( $update, $item ) {
return ( ! in_array( $item, array(
'akismet/akismet.php',
'buddypress/bp-loader.php',
) ) );
}
add_filter( 'auto_update_plugin', 'exclude_plugins_from_auto_update', 10, 2 );
WP 3.8.2로 변경 사항을 지적하기 위해 소품은 @ WiseOwl9000으로 이동하십시오.
wordpress 3.8.2부터이 함수에 전달 된 플러그인 항목의 유형이 변경되었으며 이제는 객체입니다.
/**
* @package Plugin_Filter
* @version 2.0
*/
/*
Plugin Name: Plugin Filter
Plugin URI: http://www.brideonline.com.au/
Description: Removes certain plugins from being updated.
Author: Ben Wise
Version: 2.0
Author URI: https://github.com/WiseOwl9000
*/
/**
* @param $update bool Ignore this it just is set to whether the plugin should be updated
* @param $plugin object Indicates which plugin will be upgraded. Contains the directory name of the plugin followed by / followed by the filename containing the "Plugin Name:" parameters.
*/
function filter_plugins_example($update, $plugin)
{
$pluginsNotToUpdate[] = "phpbb-single-sign-on/connect-phpbb.php";
// add more plugins to exclude by repeating the line above with new plugin folder / plugin file
if (is_object($plugin))
{
$pluginName = $plugin->plugin;
}
else // compatible with earlier versions of wordpress
{
$pluginName = $plugin;
}
// Allow all plugins except the ones listed above to be updated
if (!in_array(trim($pluginName),$pluginsNotToUpdate))
{
// error_log("plugin {$pluginName} is not in list allowing");
return true; // return true to allow update to go ahead
}
// error_log("plugin {$pluginName} is in list trying to abort");
return false;
}
// Now set that function up to execute when the admin_notices action is called
// Important priority should be higher to ensure our plugin gets the final say on whether the plugin can be updated or not.
// Priority 1 didn't work
add_filter( 'auto_update_plugin', 'filter_plugins_example' ,20 /* priority */,2 /* argument count passed to filter function */);
$ plugin 객체는 다음과 같습니다.
stdClass Object
(
[id] => 10696
[slug] => phpbb-single-sign-on
[plugin] => phpbb-single-sign-on/connect-phpbb.php
[new_version] => 0.9
[url] => https://wordpress.org/plugins/phpbb-single-sign-on/
[package] => https://downloads.wordpress.org/plugin/phpbb-single-sign-on.zip
)