【发布时间】:2017-12-19 11:19:35
【问题描述】:
这是一个删除一些横幅的函数,我知道错误发生在 if ( !in_array( $current_screen->post_type, $post_types ) ) 周围,但我不知道如何正确修复它。
function lsx_tec_disable_lsx_banner( $disabled ) {
global $current_screen;
$post_types = apply_filters( 'tribe_is_post_type_screen_post_types', Tribe__Main::get_post_types() );
if ( ! in_array( $current_screen->post_type, $post_types ) ) {
$disabled = true;
}
if ( is_null( $id ) && false !== strpos( $current_screen->id, 'tribe' ) )
{
$disabled = true;
}
if ( is_single() && tribe_is_event() ) {
$disabled = true;
}
return $disabled;
}
【问题讨论】:
-
这一行有问题 "if ( !in_array( $current_screen->post_type, $post_types ) ) {"
-
有什么问题?我尝试了一些东西,但得到了错误
-
你可以尝试打印 $current_screen->post_type 和 $post_types 吗?你可以看到问题。您已尝试从非对象中获取数据。
-
$current_screen可能没有定义。该变量是在哪里创建的,是在全局范围内创建的吗?
标签: php wordpress function object plugins