Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'private message button'

Viewing 25 results - 51 through 75 (of 201 total)
  • Author
    Search Results
  • #274732
    RT77
    Participant

    anyone? this is on buddypress profiles.. all plugins are deactivated so nothing is interfering as far as I know. When the “Private Message” Button is clicked it does not open the compose message with the user name in the title.. I think it might be a bug?

    RT77
    Participant

    Hello I think I have a bug here, ok I am on buddypress Version 3.1.0 and logged in as admin I click on a member in the members directory and it has a button for “private message”, when clicked on I am assuming it is supposed to open the compose message box with the members name in the send to field but it is not doing that for some reason. I am assuming this also because of the url link. https://www.theexample.com/members/admin/messages/compose?r=thememberid
    So is this a bug and how can I fix this if it is?

    #272468
    taskemann
    Participant

    Hi Venutis! Thank you for the tip 🙂

    But I found this code online created by a fellower named Brajesh Singh that worked very well. I just pasted it into my child theme’s functions.php

    //////////////////////////////////////////////////////////////////
    // BuddyPress send private message button
    //////////////////////////////////////////////////////////////////
    
    /**
     * Get a link to send PM to the given User.
     *
     * @param int $user_id user id.
     *
     * @return string
     */
    function buddydev_get_send_private_message_to_user_url( $user_id ) {
        return wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( $user_id ) );
    }
    
    /**
     * Shortcode [bp-pm-button username=optional_some_user_name]
     *
     * @param array $atts shortcode attributes.
     * @param string $content content.
     *
     * @return string
     */
    function buddydev_private_message_button_shortcode( $atts, $content = '' ) {
        // User is not logged in.
        if ( ! is_user_logged_in() ) {
            return '';
        }
     
        $atts = shortcode_atts( array(
            'user_id'   => '',
            'username'  => '',
            'label'     => 'Send Private Message',
        ), $atts );
     
        $user_id = absint( $atts['user_id'] );
        $user_login = $atts['username'];
     
        // if the username is given, override the user id.
        if ( $user_login ) {
            $user = get_user_by( 'login', $user_login );
            if ( ! $user ) {
                return '';
            }
            $user_id = $user->ID;
        }
     
        if ( ! $user_id ) {
            if ( ! in_the_loop() ) {
                return '';
            }
     
            $user_id = get_the_author_meta('ID' );
        }
        // do not show the PM button for the user, if it is aimed at them.
        if ( bp_loggedin_user_id() === $user_id ) {
            return '';
        }
     
        // if we are here, generate the button.
        $button = sprintf('<a href="%1$s">%2$s</a>', buddydev_get_send_private_message_to_user_url( $user_id ), $atts['label'] );
     
        return $button . $content;
    }
     
    add_shortcode( 'bp-pm-button', 'buddydev_private_message_button_shortcode' );
    naomibuch
    Participant

    Hello,

    I am new to Buddypress and this is my first post, I am new to web development also, and my PhP coding is not all that great, my years as a software developer was strictly in a windows environment (vb.net and sql)

    I developed my own website and I am using Buddypress as part of my social media for users to connect with each other.

    I have spent endless hours researching a fix, and I have not been able to find anything php file that I can edit in File Manager to edit or remove the line of code.

    When a user updates an Activity, it updates in three places:

    1. The Activity Stream (which is what I want)
    2. The Member’s Profile where the Activity tab was (now removed, which is what I want)
    3. Under the Member’s profile cover, with that pesky “view link” (which I DO NOT want to show)

    And the “view link” is a bit buggy also, sometimes when a user clicks on it, it throws a 404 error, sometimes it opens up a blank page, and sometimes it opens up the recent activity that they posted in the Activity Stream.

    Also in the members directory I have a button to send the user a private message whether or not they are friends.

    When I click on a user name from the member’s directory, it take me to the compose a message like it is suppose to do, and the user name appears , but it does not save the user name in the send to box, do you have a fix for this also?

    Thank you very much, a fix to these problems are greatly appreciated.

    Naomi

    #268891
    Boone Gorges
    Keymaster

    @louisarthur – Thanks for sending me credentials. I’ve logged into your site to have a look.

    As you note in your email, there’s no href attribute on these links. It’s not clear to me how this would be the case, but I can give you a starting point for looking into it yourself. Briefly, the buttons will be built without an href if the button constructing function passes an empty link_href parameter to the BP_Button class. The functions used in the two cases are different:

    Message public: https://buddypress.trac.wordpress.org/browser/tags/2.9.2/src/bp-activity/bp-activity-template.php?marks=3090#L3079

    Message privé: https://buddypress.trac.wordpress.org/browser/tags/2.9.2/src/bp-messages/bp-messages-template.php?marks=1362#L1360

    The logic in each case is different, but since neither is showing up, I’m guessing that one of two things is happening:

    1. One of the conditional checks shared between them is failing for some reason: bp_is_my_profile(), is_user_logged_in().

    2. Something on your installation – perhaps your theme but probably a plugin (since you said Twenty Seventeen was exhibiting the problem as well) – is filtering both ‘bp_get_send_private_message_link’ and ‘bp_get_send_public_message_link’, and then incorrect returning empty strings.

    To test idea #2, you might try – if you can – searching through your codebase for those filter names.

    paksunny
    Participant

    Hi,

    I am trying to make the below two changes but tried all different solutions available on this form non worked.

    1) Make the friend tab only visible to the account owner / logged-in user.
    2) only friends can use and see the send private message button.

    Can someone guide me to getting this accomplished. Most of the privacy settings I was able to integrate through plugins.

    #268350

    In reply to: Help with this code

    livingflame
    Participant

    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 );
    
    
    #268216
    lofiz
    Participant

    I am trying to build a contact form that I can load on any page that would send a private message to a user. I already have the selected user/s in an array and now I would like to take that plus form data to (I’m guessing) message_new_message

    Sample HTML Form

    <form>
    <label>Subject</label>
    <input id="subjec_input" name="subject_input" type="text">
    <label>Message Body</label>
    <textarea id="body_input" name="body_input"></textarea>
    <button id="submit_btn" name="submit_btn">Submit</button>
    </form>

    How I think arguments are given to the function

    `messages_new_message( $args = array( ‘recipients’ => $user_id, ‘subject’ => $title, ‘content’ => $message );

    Any help would be appreciated. Thanks

    #268157

    In reply to: Help with this code

    livingflame
    Participant

    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

    danbp
    Participant
    #261060
    empressdianna
    Participant

    Thank you so much for this code! I’ve spent several hours trying to use other people’s code to hide the button and even tried to make my own but nothing worked until I found your code. I just switched it around because I only wanted one particular group to not be able to send messages while the rest can.

    Posting in case someone in the future needs the opposite of your code:

    add_filter( 'bp_get_send_message_button', function( $array ) {
        if ( pmpro_hasMembershipLevel('NAMEOFPMPLEVEL') ) {
            return '';
        } else {
            return $array;
        }
    } );

    Also, I am looking for the same code as you to restrict non-paying users from sending private messages. I found a code that looks promising but unfortunately doesn’t work. It sees if the user is logged in and if not redirects them. Then if the person is logged in it checks their role but if they’re not that role they’re supposed to be redirected. But it just breaks my whole site. Any ideas?

    function my_function() {
    
        if ( ! is_user_logged_in() && bp_is_current_component( 'messages' ) ) {
            // Current user is not logged in so don't let them see stuff. In this case, private messages 
            wp_redirect( home_url() );
            exit;
        }
            
        $flag = false;
        // Get current user info.
        $user = wp_get_current_user();
    
        if ( ! in_array( 'student', $user->roles ) ) {
            // The current member is not a student.
            $flag = true;
        }
    
        if ( $flag && bp_is_current_component( 'messages' )  ) {
            The currently logged-in member is not a student and is trying to view private messaging. Let's redirect them away.
            wp_redirect( home_url() );
            exit;
        }
    }
    add_action( 'init', 'my_function' );
    #260857
    maccast
    Participant

    This works and hides the button, but I’m curious. Can someone still send a private message to another user when they are “not” friends using URL manipulation or should the _wpnonce stop that?

    #260568
    danbp
    Participant

    hi @masoud1111,

    all i found was how to hide that button, or remove it.
    but not show it only on some profiles

    You just need to add some conditionnals.

    Try this (in bp-custom.php) and give feed back if it works.

    function bpex_private_message_button( $button ) {
    $user = bp_loggedin_user_id();
    
        if ( is_super_admin() ) { 
    		return $button;
    	}
    
    	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    
    		if ( $role == 'subscriber' || $role == 'contributor' || $role == 'author' || $role == 'editor' )  {
    			// hide button for these roles
    			$button = '';
    		}
    	}
    
    	// allow the button to appear on admin's profile only
    	if ( bp_is_active( 'xprofile' ) && bp_is_user() )  {	
    		$user_id = bp_displayed_user_id();	
    		// assuming admin's ID is 1
    		if ( $user_id == 1 ) {
    			return $button;
    		}
    
    	}
    
    }
    add_filter( 'bp_get_send_message_button', 'bpex_private_message_button', 1 , 1 );
    danbp
    Participant

    The function is working correctly on my install.

    Perhaps you have an issue with quotes, ie after copy/pasting the snippet from a topic where the code whas inserted without using the code button.
    Which software do you use to publish bp-custom ?

    Copy/paste following and give a try:

    function buddydev_hide_members_directory_from_all_except_admin() {
    
    if ( bp_is_members_directory() && ! is_super_admin() ) {
    //should we add a message too?
    //bp_core_add_message( 'Private page.', 'error' );
    bp_core_redirect( site_url('/') );
    }
    }
    add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
    danbp
    Participant

    This topic is titled “Function to hide private message depending of user role”.

    and the snippet does that ! Subscribers have no access to the button. So far i remember it is also the default role in WordPress. You change that to your need.

    The first condition in the snippet allows some users (by ID) to access the button, whatever their role.

    If you want to add other WP roles, you simply copy the 2nd conditionnal if(role=='') and add another role if(role=='mamamouchi") { //do something }.

    Or you use only the user ID if you have only a few members allowed to access. I litle understanding of php is of course a + to do that.
    You have the basics in the snippet. Now, it’s to you now to make it work for your need.

    Raphael.v
    Participant

    Thank you @danbp, this work ! I’m pretty sure this will help a lot (and not only me).

    I’am asking something more : can this be adapt to allow only some user role to use private message ? (and not only some users ?) As the second part of the code you wrote, it remove the button to susbscriber.

    (I’m learning PHP, I’ve tried to change the code but did not succeed to have it work…)

    danbp
    Participant

    Hi,

    try this (goes to bp-custom.php)

    function bpex_remove_private_message_button( $button ) {
    $user = bp_loggedin_user_id();
    
        if ( $user == '4' || $user == '7' || $user == '25'  ) { // the allowed user ID's
    	 return $button;
    	}
    
    	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    
    		if ( $role == 'subscriber') {
    			$button = '';
    		}
    	}
    }
    add_filter( 'bp_get_send_message_button', 'bpex_remove_private_message_button', 1 , 1 );

    No idea how to get specifically a pmpro defined user ID – you have to check their doc to adjust the above snippet. Note that it works on a standart install – without pmpro.

    #259414
    danbp
    Participant

    Hi @koded1999,

    please, use the <code> button to insert snippets. Also avoid double posting.
    Closing this topic as duplicate.
    Conversation goes ahead here:

    Disable or Hide Private Message Button

    #259413
    koded1999
    Participant

    @henrywright i managed to fix that and is working perfectly.

    but i have another problem.

    i will like to populate the subject automatically when user click the private message button from post

    pls how can i achieve this.

    thank you

    #259410
    koded1999
    Participant

    @henrywright Please i will like to add private message button in post side bar. i used the code below it works but doesnt populate the author automatically. how can i fix this thanks in advance.

    function bpfr_message_shortcode() {	
    $author = get_the_author();
    $message = 'Login to contact advertiser!';
    
    if( is_user_logged_in() ) {
    	return '<a>MESSAGE ADVERTISER</a>';
     } else {
        return $message;
     }
    } 
    add_shortcode( 'ksam', 'bpfr_message_shortcode' );
    #258281
    danbp
    Participant

    Hi,

    you can try to remove the private message button from the template or hide it with CSS.
    And add a custom one who leads to admin inbox.

    The link should look like
    http://your-site.com/members/YOU/messages/compose/?r=THE ADMIN&_wpnonce=an_alpha_numeric_value

    See here how you may code this

    Codex and Forum are your friends to search about template customization.

    #258149
    danbp
    Participant

    You’re welcome. 😉
    In case of, here’s another trick.

    #258094

    In reply to: New Privacy Plugin

    danbp
    Participant

    hi @fencer04,

    thank for sharing your work. Well done, but it needs some revision (sorry).
    At his activation on 2 test sites (one with 4.5.3/bp 2.6.1, other 4.6/bp2.6.2) i got a notice.
    Array to string conversion in buddypress/bp-core/classes/class-bp-core-nav.php on line 279from

    sbpp04_privacy_check( )	..\plugin.php:525
    sbpp04_privacy_redirect( )	..\buddypress-profile-privacy.php:176
    bp_core_remove_nav_item( )	..\buddypress-profile-privacy.php:184
    BP_Core_Nav->delete_nav( )	..\bp-core-buddybar.php:798

    Another point concerning UI/UX is the Private button appearing on buddybar.
    On this tab, a default message says Friends Only.
    USERNAME has chosen to limit profile access to friends only.
    That’s wrong! Because this appear on each profile, even if the owner hasn’t setup anything about his profile privacy.

    So far i understand its fonctionality, this plugin let each member decide to show or not his whole profile page to friends or members only or to everyone (bp default).

    – imo this tab should show “This profile is private” to anybody who is concerned by a privacy setting and should not appear at all if “Everyone” is set.
    – the original BP Add as friend button on profile header or members directory is still there. This means that there is no need to go on Private tab to ask forfriendship.
    This is a little confusing !

    If the plugin is to extend profile settings, it should appear in profile settings only. And as it doesn’t superseed BP, there is no real reason to give him an extra tab on buddybar outside of the settings scope. A template notice could be enough to tell visitors what’s going on on such a profile.

    Just my 2 cents.

    danbp
    Participant

    Try this:

    function mohammad_remove_private_message_button( $button ) {
    $user_id = bp_loggedin_user_id();
    
        if ( $user_id == '37' ) // the user ID
    	$button = '';
    
         return $button;
    }
    add_filter( 'bp_get_send_message_button', 'mohammad_remove_private_message_button', 1 , 1 );

    More details here:

    [Resolved] how hide tab only for user? not remove/disable

    danbp
    Participant

    I tested your code and got first a page not found error while trying to send a private message from the new position.
    I deactivated both action hook in cover and home files.
    Disallowed cover image option. And tested again and everithing worked.
    Allowed cover image and worked also.

    So i confirm that your code works and all buttons show up (with active href’s), at least with Twenty Sixteen theme, at the members profile page bottom.

    In resume, the only thing you have to do is to deactivate the original action hook in both files (so you can allow/disallow cover images).

    Forgot to mention that there is a litle error in your code line 133
    <?= wpautop(xprofile_get_field_data("About me", bp_displayed_user_id() ) ); ?>

    Should be
    <?php wpautop(xprofile_get_field_data("About me", bp_displayed_user_id() ) ); ?>

Viewing 25 results - 51 through 75 (of 201 total)
Skip to toolbar