Help with this code
-
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 );
-
Wrap the message button between this code.
<?php if ( is_user_logged_in() ) { // your code here } ?>
Hi @macpresss
Thanks, but is_user_logged… does not work.is_user_logged_in()
is a WordPress function. It’ll returntrue
if the user is authenticated andfalse
if not.bp_loggedin_user_id()
will return the ID of the BuddyPress member currently logged in.The two functions are different.
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.
@r-a-y Help!
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 );
Other option can be: If the button is visible, and you are not a member, redirect to Register Page after you click on this.
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 );
- You must be logged in to reply to this topic.