Allow users only who posted at least one listing


Home Forums Front End PM PRO Allow users only who posted at least one listing

This topic is: Resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22835
    peri2616
    Participant

    Hello Shamim,

    We want to allow only the users, who have posted at least one listing under the specific custom post type, to access Private Message. If the user posted no listing under the specific custom post type, then we do not want to allow the user to access Private Message.

    We want to execute the following or similar code to check if the number of listing under the specific custom post type for the current user is zero, then display the error message and exit Private Message.

    if (count_user_posts(get_current_user_id(), ‘jobs’) == 0) {
    echo ‘You do not have permission to access message system’;
    /* exit Private Message */
    }

    Please suggest a code to achieve the above check.

    Thanks.

    #22843
    shamim
    Keymaster

    Add following code in your theme’s (child theme’s if you are using) functions.php

    add_filter( 'fep_current_user_can', function( $can, $cap, $id ){
    	if( 'access_message' !== $cap || ! $can ) {
    		return $can;
    	}
    	if ( ! count_user_posts( get_current_user_id(), 'jobs' ) ) {
    		$can = false;
    	}
    
    	return $can;
    }, 10, 3);
    
    #22878
    peri2616
    Participant

    Thanks Shamim for the code.

    The Code works as expected.

Viewing 3 posts - 1 through 3 (of 3 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.