BuddyDev

Search

BuddyPress public message shortcode.

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30522

    Hello,

    Please how can I get this code to work for public message instead of private messages

     function bpfr_message_shortcode() {	
    $username = bp_core_get_username( $user_id );
    $message = 'Login to message this author !';
    
    if( is_user_logged_in() ) {
    	return '<a href=" '.wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . $username ) .' class="private-message-to-author">Contact the author</a>';
     } else {
        return $message;
     }
    } 
    add_shortcode( 'bp_private_message_link', 'bpfr_message_shortcode' ); 

    Thanks

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30523

    Can you also add a css class to the link

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30545

    I found a solution

     /**
     * BuddyPress public message shortcode.
     */
    function bp_public_message_shortcode() {	
    $username = bp_core_get_username( $user_id );
    $empty = '';
    
    if( is_user_logged_in() && bp_loggedin_user_id() != get_the_author_meta( 'ID' ) ) {
    	return '<a class="inner-msg" href=" '.wp_nonce_url( site_url() . '/news-feed/?r=' . $username ) .'  ">Shoutout To Author</a>';
     } 
    if( bp_loggedin_user_id() ) {
        return $empty;
     }
     else if( !is_user_logged_in() ) {
        return '<a class="outer-msg" href=" '.esc_url( wp_login_url()) .' ">Login to follow or message this author !</a>';
     }
    } 
    add_shortcode( 'bp_public_message_link', 'bp_public_message_shortcode' ); 
  • Keymaster
    (BuddyDev Team)
    Posts: 21820
    Brajesh Singh on #30584

    Hi Tosin,
    Thank you for sharing. I am glad you found a solution.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved