Skip to:
Content
Pages
Categories
Search
Top
Bottom

If user has X number of posts?

  • @mllapan

    Participant

    How do I check if user has X number of posts inside bbpress forum to allow him to see blog post.
    For example, for logged in user, it would be like:

    function show_to_logged( $atts, $content = null ) {
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';
    };
    
    add_shortcode('show_to_logged', 'show_to_logged');
    function show_to_bbpress_user_with_x_posts( $atts, $content = null ) {
    if ( user_has_X_BBPRESS_topics_or_topic_replies() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';
    };
    
    add_shortcode('show_to_bbpress_user_with_x_posts', 'show_to_bbpress_user_with_x_posts');

    What would be correct function for user_has_X_BBPRESS_topics_or_topic_replies?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @robin-w

    Moderator

    so something like

    $user_id = get_current_user_id()  ;
    $topic_count  = bbp_get_user_topic_count_raw( $user_id);
    $reply_count = bbp_get_user_reply_count_raw( $user_id);
    $post_count   = (int) $topic_count + $reply_count;		
    if ($post_count > 150) { 
    //show here
    }

    @mllapan

    Participant

    Thanks @robin-w, can you also tell me how to apply this only on users that are not blocked?

    If user has no BLOCKED role and has 5 posts show them this.

    @robin-w

    Moderator
    $role = bbp_get_user_role( $user_id );
    if ($role == 'bbp_blocked' && $post_count > 4)

    @mllapan

    Participant

    Thanks again for the answer.
    Your code check if user is blocked.

    Should I write like if ($role == 'bbp_keymaster' || $role == 'bbp_moderator'|| $role == 'bbp_participant'|| $role == 'bbp_spectator' && $post_count > 4)

    Or I can use ! as counter statement to blocked somewhere in your code?

    @robin-w

    Moderator

    sorry shoudl be != means not equal

    $role = bbp_get_user_role( $user_id );
    if ($role != 'bbp_blocked' && $post_count > 4)
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar