Last active
May 16, 2025 12:15
-
-
Save yuriinalivaiko/18e00e66a8ba5663c91400cfafd1b4f0 to your computer and use it in GitHub Desktop.
Code snippets for the "Private Messages" extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Delete private messages after 6 months. | |
add_action( 'um_daily_scheduled_events', 'um_messaging_autodelete' ); | |
function um_messaging_autodelete() { | |
global $wpdb; | |
$timestamp = strtotime( '6 months ago'); | |
$sql = $wpdb->prepare( | |
"DELETE FROM %i WHERE `time` < %s", | |
$wpdb->prefix . 'um_messages', | |
wp_date( 'Y-m-d H:i:s', $timestamp ) | |
); | |
return $wpdb->query( $sql ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Replace a function that sends the "Private Messages - New Message" email. | |
// New function supports the {message} placeholder used to add the message content. | |
remove_action( 'um_after_new_conversation', 'um_messaging_mail_notification', 20, 3 ); | |
add_action( 'um_after_new_conversation', 'um_messaging_mail_notification_custom', 20, 3 ); | |
function um_messaging_mail_notification_custom( $to, $from, $conversation_id, $template = 'new_message' ) { | |
if ( ! UM()->Messaging_API()->api()->enabled_email( $to, '_enable_new_pm' ) ) { | |
return; | |
} | |
// send a mail notification | |
um_fetch_user( $to ); | |
$recipient_e = um_user('user_email'); | |
$recipient = um_user('display_name'); | |
$message_history = add_query_arg('profiletab', 'messages', um_user_profile_url() ); | |
// who sends the message | |
um_fetch_user( $from ); | |
$sender = um_user('display_name'); | |
$mail_args = array( | |
$recipient_e, | |
$template, | |
array( | |
'plain_text' => 1, | |
'path' => um_messaging_path . 'templates/email/', | |
'tags' => array( | |
'{recipient}', | |
'{message_history}', | |
'{sender}', | |
'{message}', | |
), | |
'tags_replace' => array( | |
$recipient, | |
$message_history, | |
$sender, | |
sanitize_textarea_field( $_POST['content'] ), | |
), | |
), | |
); | |
UM()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', $mail_args ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment