我在WP仪表板上收到以下错误:
Warning: First parameter must either be an object or the name of an existing class
in /home/content/88/11746388/html/wp-content/plugins/pluginname/pluginname.php on
line 136
这些是我从130到140的台词。有什么想法吗?
function get_latest_version($plugin_file) {
$latest_version = '';
$sr_plugin_info = get_site_transient ( 'update_plugins' );
// if ( property_exists($sr_plugin_info, 'response [$plugin_file]') && property_exists('response [$plugin_file]', 'new_version') ) {
if ( property_exists($sr_plugin_info, 'response [$plugin_file]') ) {
$latest_version = $sr_plugin_info->response [$plugin_file]->new_version;
}
return $latest_version;
}
这一行似乎有错误:
if ( property_exists($sr_plugin_info, 'response [$plugin_file]') ) {
property_exists—检查对象或类是否具有属性。
并且CCD_ 1不是类的有效属性名称。
老实说,代码有好几个伤口在流血。
a.(get_site_transient不能保证返回对象,property_exists需要一个
b.(您尝试检查具有propertyexists的属性中是否存在数组键。我很确定property_exists不能做到这一点——您应该只使用它检查response
属性,并将isset()
用于$plugin_file
索引。
function get_latest_version($plugin_file) {
$latest_version = '';
$sr_plugin_info = get_site_transient ( 'update_plugins' );
// if ( property_exists($sr_plugin_info, response[$plugin_file]) && property_exists(response[$plugin_file], 'new_version') ) {
if ( property_exists($sr_plugin_info, response[$plugin_file]) ) {
$latest_version = $sr_plugin_info->response[$plugin_file]->new_version;
}
return $latest_version;
}