我正在一个客户端网站上工作,该框架需要一个特定的插件版本才能正常工作。
在我的functions.php 文件,它会阻止插件更新自身并向管理员用户显示更新消息:
// Disable Cherry Plugin Updates
function filter_plugin_updates( $value ) {
if(isset($value->response[\'cherry-plugin/cherry-plugin.php\'])) {
unset($value->response[\'cherry-plugin/cherry-plugin.php\']);
}
}
上面的代码工作正常,但是,当从WordPress后端菜单进行某些更改时,它有时会抛出PHP错误消息,并且似乎与特定更改不一致:"Fatal error: Cannot use object of type WP_Error as array in ../public_html/wp-content/plugins/cherry-plugin/admin/plugin-updater.php on line 63"
查看上述文件,第63行是:if ($response[\'response\'][\'code\']!=\'200\') {
return;
}
它的整个功能是:// Remote query, function return any data of xml file on server
function cherry_plugin_remote_query($atts){
global $wp_version;
$default = array(
\'remote_server\' => CHERRY_PLUGIN_REMOTE_SERVER,
\'data_type\' => \'\',//framework, plugin, notice, info (Or any channel in xml)
\'output_type\' => \'return\'//return, echo, notice
);
extract(array_merge($default, $atts));
if($data_type == \'framework\' && defined(\'CHERRY_VER\')){
$current_version = CHERRY_VER;
}else if($data_type == \'plugin\'){
$current_version = CHERRY_PLUGIN_VERSION;
}else{
$current_version = \'\';
}
$response = wp_remote_post( $remote_server, array(
\'body\' => array(\'data_type\' => $data_type,
\'current_version\' => $current_version,
\'api-key\' => md5(get_bloginfo(\'url\'))),
\'user-agent\' => \'WordPress/\' . $wp_version . \'; \' . get_bloginfo(\'url\')
)
);
if ($response[\'response\'][\'code\']!=\'200\') {
return;
}
$response = unserialize($response[\'body\']);
if($response==null){
return;
}
switch ($output_type) {
case \'notice\':;
if(!empty($response) && isset($response[\'action\']) && !empty($response[\'notice_content\'])){
global $notice_attr;
$notice_attr =array();
if(isset($response[\'wrapper_id\'])) $notice_attr[\'wrapper_id\'] = $response[\'wrapper_id\'] ;
if(isset($response[\'wrapper_class\'])) $notice_attr[\'wrapper_class\'] = $response[\'wrapper_class\'] ;
if(isset($response[\'notice_content\'])) $notice_attr[\'notice_content\'] = $response[\'notice_content\'] ;
add_action($response[\'action\'], \'cherry_call_function_add_notice\');
function cherry_call_function_add_notice(){
global $notice_attr;
echo cherry_add_notice($notice_attr);
}
}
break;
case \'echo\':
echo $response;
break;
default:
return $response;
break;
}
}
如何阻止插件更新,向管理员用户显示更新消息,以及不抛出任何PHP错误?