I'm working on a client website where the framework requires a specific plugin version to work properly.
With the follow lines of code in my functions.php file, it stops the plugin from updating itself and displaying an update message to the admin user:
// 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']);
}
}
The code above works fine, however, it will sometimes throw a PHP error message when making certain changes from the WordPress backend menu, and doesn't seem to be consistant on a specific change:
"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"
Viewing the above file, line 63 is:
if ($response['response']['code']!='200') {
return;
}
And the entire function it is within is:
// 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;
}
}
How would I be able to stop the plugin from updating, displaying an update message to the admin user, as well as not throw any PHP errors?