如何为登录用户禁用内容警告对话框

时间:2016-11-22 作者:vinpinadu

插件如下:https://wordpress.org/plugins/content-warning-v2/

我不想为登录用户显示它。

插件开发人员告诉我:https://wordpress.org/support/topic/how-to-dont-show-this-box-to-logged-in-users/#post-8411866

基本上,不用检查post ID,而是查看用户是否登录。

在此代码上:

/**
 * Maybe Show Dialog
 * @param  bool $bool    Default true
 * @param  WP_Post  $post_ob A WP_Post object
 * @return bool           True to show the dialog, false to hide it.
 */
function maybe_show_dialog( $bool = true, $post_ob = null ) {
    if ( isset( $post_obj->ID ) && 1 == $post_obj->ID ) {
        return false;
    }

    return $bool;
}
add_filter( \'cwv3_should_gate\', \'maybe_show_dialog\', 10, 2 );
那么,我该怎么做呢?如何更改对登录上述代码的用户的post id php代码的查找?

1 个回复
SO网友:Benoti

要检查用户是否已登录,可以使用is_user_logged_in() 这只会返回true或false。您可以将语句与get_current_user_id(), 如果返回值为0,则用户不是log。

if(is_user_logged_in() && get_current_user_id()!=0 && isset( $post_obj->ID ) && 1 == $post_obj->ID){
    return false;
}
return $bool;

相关推荐