Home › Forums › Front End PM PRO › fep_filter_read_receipt example and message recipient
Tagged: date, fep_filter_read_receipt, fep_filter_read_receipt_individual, mgs_author, Read by, time
- This topic has 9 replies, 3 voices, and was last updated 3 years, 7 months ago by Shamim Hasan.
-
AuthorPosts
-
July 21, 2020 at 7:15 pm #39489little.chimpParticipant
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: ????July 21, 2020 at 8:41 pm #39495little.chimpParticipantSorry, 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.
July 22, 2020 at 12:53 am #39503Shamim HasanKeymasterYou 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.
July 22, 2020 at 4:14 pm #39528little.chimpParticipantSo 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.
July 22, 2020 at 6:35 pm #39530Shamim HasanKeymasterYou can use
fep_filter_read_receipt_individual
as you already wrote (can change $time variable to something else) andfep_filter_read_receipt
like followingadd_filter( 'fep_filter_read_receipt', function( $output, $receipt ){ return implode( '', $receipt ); }, 10, 2);
July 22, 2020 at 8:29 pm #39533little.chimpParticipantIt’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>'; }
March 31, 2021 at 4:29 am #42818massimo.mancaParticipanthi,
i have a question.
why is the message displayed 2 hours in advance?April 1, 2021 at 6:49 pm #42834Shamim HasanKeymasterIs it only for this code or all other places as well?
Is your timezone setup correct in settings page?April 1, 2021 at 6:55 pm #42838massimo.mancaParticipantjust by entering this code.
if I remove it, it returns the correct timeApril 1, 2021 at 7:03 pm #42843Shamim HasanKeymaster$time is GMT time. You need to convert it to your local time.
-
AuthorPosts
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.