This topic has 11 replies, 2 voices, and was last updated 10 years by sharmstr.

  • Author
  • #87673
     Oscar570
    Participant

    Hi !

    I’d like to insert a button to ask a member for a CHAT instead of SEND A PUBLIC MESSAGE. I’m using COMETCHAT. I contacted them and they said to me :

    “<span style=”color: #333333;font-family: Verdana, sans-serif;font-size: 11px”> </span><span style=”color: #333333;font-family: Verdana, sans-serif;font-size: 11px”>Add button or link with below code on click of which it should open chat window for the user.
    </span>

    <span style=”color: #333333;font-family: Verdana, sans-serif;font-size: 11px”>Chat with me“</span>

     

    BUT I don’t know to do it.

    How can I do this ? Can you help me?

    Thanks a lot

    Regards

    Nathalie

    #87689
     sharmstr
    Moderator

    I obviously cant test this, but something like this should work. Put it in your child theme’s functions.php file.

    COPY CODE
    // Removing public message option
    
    function remove_public_message_button() {
        remove_filter( 'bp_member_header_actions','bp_send_public_message_button', 20);
        // Add chat button
        add_action( 'bp_member_header_actions','add_chat_button',20);
    
    }
    add_action( 'bp_member_header_actions', 'remove_public_message_button' );
    
    function add_chat_button() {
        echo '<div class="generic-button"><a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.chatWith(userid);">Chat with me</a></div>';
    }
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #87698
     Oscar570
    Participant

    Dear Sharmstr,

    The button is remove by “CHATTER” (instead of CHAT WITH ME) but nothing is happening…

    #87700
     sharmstr
    Moderator

    Perhaps because of their code. How are they getting ‘userid’?

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #87701
     Oscar570
    Participant

    Dear Sharmstr,

    This is their answer to my question : How can I insert a button on Buddypress for asking a chat to a member? :

    “Is it possible to insert “CHAT” to the buddypress menu. And when you click on you can ask chat with somebody ?

    Please follow below steps to implement chatWith API on profile page of a user:

    a. Make sure CometChat footer code is added in your site’s template file so the CometChat bar is visible on your site.
    b. Add button or link with below code on click of which it should open chat window for the user.

    Chat with me

    You can access userid by following methods, for example:

    1. If userid is passed in URL when you are on other user’s profile page then you can access userid from URL and then pass it to chatWith() function.

    2. If you are having a hidden field on profile page which stores userid of the user on whose profile page we are, then you can access that hidden field by its attribute (example id) and pass it to chatWith() function

    3. If Profile picture or name on profile page of that user has a field that can allow us to access userid id then you can pass that userid to chatWith() with help of field or function( example get_the_author_meta() function in wordpress).”

    #87703
     Oscar570
    Participant

    Also this on their support : (screenshot)

    #87705
     sharmstr
    Moderator

    bp_displayed_user_id() will return the userid of the profile you are viewing. So, you can try the following. If it doesnt work, you’ll have to hire someone to get it working for you.

    COPY CODE
    // Removing public message option
    
    function remove_public_message_button() {
        remove_filter( 'bp_member_header_actions','bp_send_public_message_button', 20);
        // Add chat button
        add_action( 'bp_member_header_actions','add_chat_button',20);
    
    }
    add_action( 'bp_member_header_actions', 'remove_public_message_button' );
    
    function add_chat_button() {
        echo '<div class="generic-button"><a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.chatWith(' . bp_displayed_user_id() . ');">Chat with me</a></div>';
    }
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #87707
     Oscar570
    Participant

    ok Where must I add this code please ?

    #87708
     sharmstr
    Moderator

    In the same place you did before. I gave you updated code that uses bp_displayed_user_id to get the userid. So delete the old code and add the new code.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #87711
     Oscar570
    Participant

    Perfect !
    Thanks a lot!

    #87827
     Oscar570
    Participant

    Dear Sharmstr,

    I used COMETCHAT.
    From the side menu (who become my mobile menu) I’d like to insert a button on this menu to launch COMETCHAT Application. How can I do this please ?

    #87875
     sharmstr
    Moderator

    What’s the code you need to use? The code you gave me before was to launch a chat with a specific user. That wont work in the side menu since the side menu shows on every page.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 12 posts - 1 through 12 (of 12 total)

The forum ‘Plugins questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?