毫无疑问,我错过了一些明显的东西。。。
以下将正文类添加到管理页的代码将生成此错误通知:
Notice: Trying to get property of non-object in /.../box.php on line 103
如何摆脱请。提前感谢!
public function admin_body_class($classes) {
global $wpdb, $post;
$screen = get_current_screen();
/* Line 103 */ if ($post->post_parent > 0 ) {
$status = \'child-\';
} else {
$status = \'parent-\';
}
$classes .= \' \' . $status . $screen->post_type;
return $classes;
}
最合适的回答,由SO网友:Shrikant D 整理而成
将代码替换为,如下所述:
public function admin_body_class($classes) {
global $wpdb, $post;
$screen = get_current_screen();
$status = \'parent-\';
if( isset( $post->post_parent ) && $post->post_parent > 0 ) {
$status = \'child-\';
}
$classes .= \' \' . $status . $screen->post_type;
return $classes;
}