BuddyDev

Search

BP Private MSG for non logged in users

  • Participant
    Level: Master
    Posts: 392
    Daniel on #27462

    Hi

    I have tried the code from Ravi for BP Nouveau, but when clicking on the Private Message Button then the browser says that the page is not available.

    Could you please have a look at it?

    Thank you.

    Regards
    Daniel

    Here is the code I have used:

    
    /**
     * Modify private message button args.
     *
     * @param array $buttons Array.
     *
     * @return array
     */
    function buddydev_nouveau_filter_private_message_button( $buttons ) {
    
    	if ( ! isset( $buttons['private_message'] ) || is_user_logged_in() ) {
    		return $buttons;
    	}
    
    	$buttons['private_message']['must_be_logged_in']   = false;
    	$buttons['private_message']['button_attr']['href'] = wp_login_url( site_url( '?message-redirect=' . bp_displayed_user_id() ) );
    
    	return $buttons;
    }
    
    add_filter( 'bp_nouveau_get_members_buttons', 'buddydev_nouveau_filter_private_message_button' );
    
    /**
     * Redirect to the send message when the user logs in
     *
     */
    function buddydev_redirect_to_send_message_on_login() {
    
    	//make sure it is our url set in previous step
    	if ( ! is_user_logged_in() || empty( $_GET['message-redirect'] ) ) {
    		return;
    	}
    
    	//redirect to PM
    	$user_id = absint( $_GET['message-redirect'] );
    	//let us make sure that user exists
    	$user = get_user_by('id', $user_id );
    	//can not PM to invalid user
    	//also you should not send message to yourself
    	if ( ! $user || $user->ID == bp_loggedin_user_id() ) {
    		return ;
    	}
    
    	$url =  bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . $user->user_login ;
    
    	bp_core_redirect( $url );
    }
    add_action( 'bp_template_redirect', 'buddydev_redirect_to_send_message_on_login' );
    • This topic was modified 2 years, 8 months ago by Daniel.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #27465

    Hello Daniel,

    Thank you for posting. Please make sure the message component is enabled. If enabled and you still facing the issue. Please share a screenshot of the page.

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 392
    Daniel on #27466
    This reply has been marked as private.
  • Participant
    Level: Master
    Posts: 392
    Daniel on #27467

    Hi Ravi,

    It actually says this when I click on Message. It only shows a blank page with this text:

    This site can’t be reached bp-messages’s server IP address could not be found.
    Search Google for messages
    ERR_NAME_NOT_RESOLVED

    Thanks for your assistance.

    Regards,
    Daniel

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #27472

    Hello Daniel,

    It seems you have a customize message url. Please replace the following code,

    
    $url =  bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . $user->user_login ;
    

    with

    
    $url =  trailingslashit( bp_loggedin_user_domain() ) . 'bp-messages/?new-message&fast=1&to=' . $user->user_login;
    

    Please let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 392
    Daniel on #27473

    Hi Ravi,

    Thanks for your new code but unfortunately it is not working eighter.

    I receive the same error message from the browser as before.

    Might you have any other idea how to make it work?

    Thanks.

    Regards
    Daniel

  • Participant
    Level: Master
    Posts: 392
    Daniel on #27474
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 21779
    Brajesh Singh on #27484

    Hi Daniel,
    The problem is you are not using the core BuddyPress Messaging funcitonality. You are using the Bp Better Message plugin which does not confroms to the core API.

    We may not be able to help you with this as we do not use the plugin.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 392
    Daniel on #27489

    Hi Brajesh,

    Thanks for the input no problem I undersand, I have erased the code due to incompatibilty with.

    Regards,
    Daniel

  • Keymaster
    (BuddyDev Team)
    Posts: 21779
    Brajesh Singh on #27527

    Thank you for the understanding Daniel. I sincerely appreciate it.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved