Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with this code


  • livingflame
    Participant

    @livingflame

    Hi
    @r-a-y
    @shanebp

    I have this code (example img. LINK),

    But, bp_loggedin_user_id() not work.
    The Button is visible for all. Like Add Friend Button [ + ] the Message button needs to be visible only for Logged in users.

    function filter_message_button_link( $link ) {
    
        $link =  wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r='. bp_core_get_username( bp_get_member_user_id() ) );
    
    return $link;
    
    }
    
    function display_private_message_button() {
    
        if( bp_get_member_user_id() != bp_loggedin_user_id() ) {
    
            //bp_send_message_button();
            ?>
            <div id="send-private-message" class="generic-button">
    
                <div class="private-message-button generic-button" ><a href="<?php echo filter_message_button_link(); ?>" class="button small secondary radius" rel="add"><i class="icon-envelope"></i></a></div>
            </div>
    
            <?php
            add_filter('bp_get_send_private_message_link', 'filter_message_button_link', 1, 1 );
            }
    }
    add_action( 'bp_directory_members_item_last', 'display_private_message_button',9999 );
Viewing 8 replies - 1 through 8 (of 8 total)

  • Shmoo
    Participant

    @macpresss

    Wrap the message button between this code.

    
    <?php if ( is_user_logged_in() ) {
    
        // your code here
    
    }
    ?>
    
    

    livingflame
    Participant

    @livingflame

    Hi @macpresss
    Thanks, but is_user_logged… does not work.


    Henry Wright
    Moderator

    @henrywright

    is_user_logged_in() is a WordPress function. It’ll return true if the user is authenticated and false if not.

    bp_loggedin_user_id() will return the ID of the BuddyPress member currently logged in.

    The two functions are different.


    livingflame
    Participant

    @livingflame

    Hi @henrywright

    Help me with the code.
    I need the Message button visible only to logged in users (Just like the Add Friend button works).

    Check the code.


    livingflame
    Participant

    @livingflame

    @r-a-y Help!


    livingflame
    Participant

    @livingflame

    Help me with the code.
    I need the Message button visible only to logged in users (Just like the Add Friend button works).

    Check the code, please.

    // Adding message button in members loop
    
    function filter_message_button_link( $link ) {
    
        $link =  wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r='. bp_core_get_username( bp_get_member_user_id() ) );
    
    return $link;
    
    }
    
    function display_private_message_button() {
    
        if( bp_get_member_user_id() != bp_loggedin_user_id() ) {
    
            //bp_send_message_button();
            ?>
            <div id="send-private-message" class="generic-button">
    
                <div class="private-message-button generic-button" ><a href="<?php echo filter_message_button_link(); ?>" class="button small secondary radius" rel="add"><i class="icon-envelope"></i></a></div>
            </div>
    
            <?php
            add_filter('bp_get_send_private_message_link', 'filter_message_button_link', 1, 1 );
            }
    }
    add_action( 'bp_directory_members_item_last', 'display_private_message_button',9999 );
    
    

    @modemlooper
    @sbrajesh
    @mercime


    livingflame
    Participant

    @livingflame

    @shanebp

    Other option can be: If the button is visible, and you are not a member, redirect to Register Page after you click on this.


    livingflame
    Participant

    @livingflame

    Okey, here is the correct code, thanks to @brajesh

    // Adding message button in members directory 
    
    function filter_message_button_link( $link ) {
    
        $link =  wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r='. bp_core_get_username( bp_get_member_user_id() ) );
    
    return $link;
    
    }
    
    function display_private_message_button() {
    
        if( is_user_logged_in() && bp_get_member_user_id() != bp_loggedin_user_id() ) {
    
            //bp_send_message_button();
            ?>
            <div id="send-private-message" class="generic-button">
    
                <div class="private-message-button generic-button" ><a href="<?php echo filter_message_button_link(); ?>" class="button small secondary radius" rel="add"><i class="icon-envelope"></i></a></div>
            </div>
    
            <?php
            add_filter('bp_get_send_private_message_link', 'filter_message_button_link', 1, 1 );
            }
    }
    add_action( 'bp_directory_members_item_last', 'display_private_message_button',9999 );
    
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar