fep_filter_read_receipt example and message recipient


Home Forums Front End PM PRO fep_filter_read_receipt example and message recipient

This topic is: Resolved
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #39489
    little.chimp
    Participant

    1. Can you show me an example of a filter for this? I’m looking just to show…

    <b>Read</b> 18:55

    Or if it’s not the same day…

    <b>Read</b> Mon 21 Jul 14, 21:55

    2. Also is there a simple call for the recipient of a message?

    To: fep_user_name( fep_get_message_field( ‘mgs_author’ ) );
    From: ????

    #39495
    little.chimp
    Participant

    Sorry, just to clarify, I was looking for an example of the fep_filter_read_receipt filter in use as I couldn’t decipher it from the core code to make customisations.

    #39503
    shamim
    Keymaster

    You can use like following

    add_filter( 'fep_filter_read_receipt_individual', function( $receipt, $time, $participant ){
        //here use your logic to change $receipt
        return $receipt;
    }, 10, 3);
    

    Let me know if you understand.

    #39528
    little.chimp
    Participant

    So this will filter the name and date, time.

    add_filter( 'fep_filter_read_receipt_individual', function( $receipt, $time, $participant ){
        if ($time > strtotime('-1 day')) {
    		$time = sprintf( __( '%s', 'front-end-pm' ), date("G:i", $time) );
    		// $time = sprintf( __( '%s ago', 'front-end-pm' ), human_time_diff($time) );
    	} elseif ($time > strtotime('-6 day')) {
    		$time = sprintf( __( '%s', 'front-end-pm' ), date("D G:i", $time) );
    	} else { 
    		$time = sprintf( __( '%s', 'front-end-pm' ), date("j M Y, G:i", $time) );
    	}
    	return '<b>Read</b> ' . $time;
    }, 10, 3);
    

    // Read 21:18

    How do I filter out the <hr /><div class=”fep-read-receipt”>…</div>?

    This was what I came up with before you pointed me towards the _individual filter…

    add_filter( 'fep_filter_read_receipt', function(){	
    	$participants = FEP_Participants::init()->get( fep_get_the_id(), false, true );
    	$time = array();
    	foreach ( $participants as $participant ) {
    		if ( ! $participant->mgs_read ) {
    			continue;
    		}
    		if ( fep_get_message_field( 'mgs_author' ) == $participant->mgs_participant ) {
    			continue;
    		}
    		$time = $participant->mgs_read;
    	}
    	return 'Read ' . date('G:i', $time);
    }, 10, 2);
    

    But I know that’s not the right way to do it. I’m still trying to feel my way through the plugin, but getting there.

    #39530
    shamim
    Keymaster

    You can use fep_filter_read_receipt_individual as you already wrote (can change $time variable to something else) and fep_filter_read_receipt like following

    add_filter( 'fep_filter_read_receipt', function( $output, $receipt ){
    	return implode( '', $receipt );
    }, 10, 2);
    
    #39533
    little.chimp
    Participant

    It’s easy when you know how. Much appreciated.

    Final code in my front-end-pm-mod plugin.

    add_filter( 'fep_filter_read_receipt_individual', function( $receipt, $time, $participant ){
        if ($time > strtotime('-1 day')) {
        	$time = sprintf( __( '%s', 'front-end-pm' ), date("G:i", $time) );
    		// $time = sprintf( __( '%s ago', 'front-end-pm' ), human_time_diff($time) );
    	} elseif ($time > strtotime('-6 day')) {
    		$time = sprintf( __( '%s', 'front-end-pm' ), date("D G:i", $time) );
    	} else { 
    		$time = sprintf( __( '%s', 'front-end-pm' ), date("j M Y, G:i", $time) );
    	}
    	if ( $participant == get_current_user_id()) {
    		return '';
    	} else {
    		return '<div class="fep-msg-read fep-msg-read-pad"><b>Read</b> ' . $time. '</div>';
    	}
    }, 10, 3);
    
    add_filter( 'fep_filter_read_receipt', function( $output, $receipt ){
    	return implode( '', $receipt );
    }, 10, 2);

    And in related to the other question I asked, how do I get the recipient name (To:). This was as part of a custom template version of veiw-message-content.php.

    echo '<div class="fep-msg-author"><b>' . fep_user_name( fep_get_message_field( 'mgs_author' ) ) . '</b></div>';
    			$recipients = fep_get_participants( fep_get_the_id( $mgs_id ) );
    			foreach ( $recipients as $recipient ) {
    				if( fep_get_message_field( 'mgs_author', $mgs_id ) != $recipient )
    				echo '<div class="fep-msg-recipient">to ' . fep_user_name( $recipient ) . '</div>';
    			}
Viewing 6 posts - 1 through 6 (of 6 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.