0

The plugin is this :https://wordpress.org/plugins/content-warning-v2/

and I dont want to show it for logged-in users.

Plugin developer told me: https://wordpress.org/support/topic/how-to-dont-show-this-box-to-logged-in-users/#post-8411866

Basically instead of checking for post ID, look for if the user is logged in.

On this code:

/**
 * 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 );

So, how can I do that? How to change looking for post id php code to users logged in on the above code?

3
  • if ( isset( $post_obj->ID ) && 1 == $post_obj->ID ) { is the bit checking post ID, I see you mention your PHP skills are weak, but any answer you get here will be a technical answer assuming basic PHP skills
    – Tom J Nowell
    Commented Nov 22, 2016 at 16:05
  • How can I change that code to logged-in users?
    – vinpinadu
    Commented Nov 22, 2016 at 16:25
  • if ( is_user_logged_in() ) { is that this?
    – vinpinadu
    Commented Nov 22, 2016 at 16:43

1 Answer 1

0

To check if an user is logged you can check with is_user_logged_in() that will only return true or false. You can combine the statement with get_current_user_id(), if the return value is 0, the user is not log.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.