• Resolved hadivi

    (@hadivi)


    Hi Greg,

    WP-Advert is a great plugin to create classified site for me. I’m working well on it.
    Now I have a requirement to hide “Show contact information” button in detail ad page to visitor and only be accessed by a specify user role.

    Please give me instruction in need.

    Thank you very much.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i am glad WPAdverts is working well for you so far :). To show the contact information only to users with some specific capability/role you can add the code below in your theme functions.php file

    
    add_filter( "wp", "paying_members_only_init", 50 );
    function paying_members_only_init() {
        if( is_singular( 'advert' ) && !current_user_can( "custom_capability" ) ) {
            remove_action( 'adverts_tpl_single_bottom', 'adverts_single_contact_information' );
            remove_action( 'adverts_tpl_single_bottom', 'adext_contact_form' );
            remove_action( 'adverts_tpl_single_bottom', 'adext_bp_send_private_message_button', 50 );
    
            add_action( 'adverts_tpl_single_bottom', "paying_members_only", 5 );
        }
    }
    function paying_members_only( $post_id ) {
        $flash = array( "error" => array(), "info" => array(), "warn" => array() );
        $flash["warn"][] = array(
            "message" => __( "Only users with paid membership can contact sellers." ),
            "icon" => "adverts-icon-block"
        );
        adverts_flash( $flash );
    }
    

    Just replace “custom_capability” with actual capability you want to use.

    Thread Starter hadivi

    (@hadivi)

    Great support!

    I applied your instruction and it’s doing so well. Thank you very much.
    Wish you have more success!

    Hi Greg,
    here you mentioned the members who paid for membership.
    What if I want just block access to the seller’s contact details from non-logged in users?
    Thanks.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    if you want the contact details to be visible to any logged in user only then in the code above replace custom_capability with read.

    OK, thanks.
    So we have the following:
    ////////////////////////////////////////

    add_filter( “wp”, “paying_members_only_init”, 50 );
    function paying_members_only_init() {
    if( is_singular( ‘advert’ ) && !current_user_can( “read” ) ) {
    remove_action( ‘adverts_tpl_single_bottom’, ‘adverts_single_contact_information’ );
    remove_action( ‘adverts_tpl_single_bottom’, ‘adext_contact_form’ );
    remove_action( ‘adverts_tpl_single_bottom’, ‘adext_bp_send_private_message_button’, 50 );

    add_action( ‘adverts_tpl_single_bottom’, “paying_members_only”, 5 );
    }
    }
    function paying_members_only( $post_id ) {
    $flash = array( “error” => array(), “info” => array(), “warn” => array() );
    $flash[“warn”][] = array(
    “message” => __( “Only logged in users can contact sellers.” ),
    “icon” => “adverts-icon-block”
    );
    adverts_flash( $flash );
    }

    ////////////////////

    What about this line: “paying_members_only”?

    Plugin Author Greg Winiarski

    (@gwin)

    It’s just a function name, you can change it to something else, as long you change it here

    
    add_action( ‘adverts_tpl_single_bottom’, “paying_members_only”, 5 );
    

    and here

    
    function paying_members_only( $post_id ) {
    

    simply super running well.i need same thing for perticular category.i mean only selected categories contact info should be visible to logged users.how to do this ?
    thanks in advance

    Plugin Author Greg Winiarski

    (@gwin)

    To show contact info only if the Ad is assigned to category with (for example) Ids: 100 and 200 you would need to replace the line

    
    if( is_singular( ‘advert’ ) && !current_user_can( “read” ) ) {
    

    with

    
    $allowed = array( 100, 200 );
    $term_list = wp_get_post_terms( get_the_ID(), 'advert_category', array( 'fields' => 'ids' ) );
    if( count( array_intersect( $term_list, $allowed ) ) > 0 ) {
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to set restriction for “Show contact infomation” button’ is closed to new replies.