• Resolved Jack

    (@jack1132132)


    Hello,

    I’m trying to add a textbox next to the Private Messaging button on the members profile, where a user can fill in the box before hitting the button and the chat will open with the message already filled in.

    I’ve implemented it on the previous version, but I’m wondering if with the new version there’s anything to facilitate doing this?

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author wordplus

    (@wordplus)

    Thread Starter Jack

    (@jack1132132)

    Hello,


    I’m using the latest plugin 2.0.90?version.

    The ‘New conversation screen’ code block doesn’t seem to fill in the user and the message. The other block is more what I’m looking for but it says message doesn’t work on that mode.

    Using $_GET doesn’t work due to the redirect, otherwise I could use something like document.querySelector(‘.bm-editor-content’).innerHTML = <?php echo esc_attr($_GET[‘msg’]); ?>

    I’ll try something else.


    Thank you.

    • This reply was modified 1 year, 10 months ago by Jack.
    Plugin Author wordplus

    (@wordplus)

    I would recommend to learn which link is generating by that function provided in docs, for the developer it should explain how to create filled new conversation link for the BM 2.0.

    Thread Starter Jack

    (@jack1132132)

    Hello,

    I’ve added the following code:

    function bp_better_messages_filledout_msg($url_overwritten, $user_id ){
    
    	if( isset($_GET['message']) ) { 
    	
    		$message = sanitize_text_field(strip_tags(htmlspecialchars($_GET['message'])));	
    	
    		$args_ = ['message' => $message] ;
    		
    		$url_overwritten = add_query_arg($args_, $url_overwritten);	
    	}
    	
    	return $url_overwritten;
    }
    add_filter( 'bp_better_messages_page', 'bp_better_messages_filledout_msg', 9999, 2 );

    This way it carries the message after the redirect, then on the chat page I add:

    		if(void 0===waitForElm)function waitForElm(e){return new Promise((t=>{if(document.querySelector(e))return t(document.querySelector(e));const o=new MutationObserver((r=>{document.querySelector(e)&&(t(document.querySelector(e)),o.disconnect())}));o.observe(document.body,{childList:!0,subtree:!0})}))}
    
    if(isset($_GET['message'])){
    			$msg_ = sanitize_text_field((strip_tags(htmlspecialchars($_GET['message']))));
    			
    			?>
    			<script> waitForElm('.bm-editor-content').then((elm) => { elm.innerHTML = '<?php echo $msg_; ?>';}); </script>
    			<?php
    		}
    

    So it fills in the message.

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pre-fill message box on opening chat’ is closed to new replies.