Skip to:
Content
Pages
Categories
Search
Top
Bottom

send private message button, possible to make shortcode?

Viewing 2 replies - 1 through 2 (of 2 total)

  • danbp
    Moderator

    @danbp

    To create a shortcode, you use the same function as in the mentionned topic and instead echoing, you return what you need. Like this:

    function bpfr_message_shortcode() {	
    $author = get_the_author();
    $message = 'Login to send a message to this author !';
    
    if( is_user_logged_in() ) {
    	return '<a href=" '.wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . $author ) .' title="Private Message to Author" ">Contact the author</a>';
     } else {
        return $message;
     }
    } 
    add_shortcode( 'ksam', 'bpfr_message_shortcode' );

    Add this to bp-custom.php or your child-theme functions.php.

    Use the shortcode [ksam] at the place you want and you’ll see a Contact the author link.

    Note that I tested it only within a post, meaning you need to be in a post loop to fetch an author.


    thekristensam
    Participant

    @ksamsmile

    Dan, can I hire to create this functionality for me on my clients site?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘send private message button, possible to make shortcode?’ is closed to new replies.
Skip to toolbar