Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active January 3, 2026 13:41
Show Gist options
  • Select an option

  • Save yuriinalivaiko/18e00e66a8ba5663c91400cfafd1b4f0 to your computer and use it in GitHub Desktop.

Select an option

Save yuriinalivaiko/18e00e66a8ba5663c91400cfafd1b4f0 to your computer and use it in GitHub Desktop.
Code snippets for the "Private Messages" extension
<?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 );
}
<?php
// Disable emojis for specific roles.
add_action( 'um_after_template_part', 'um_messaging_disable_emojis', 10, 2 );
function um_messaging_disable_emojis( $template_name, $path ) {
// List the roles for which emojis should be disabled.
$roles = array(
'contributor',
'um_member',
'um_pending-member',
);
if ( 'emoji.php' === $template_name && 'um-messaging' === $path ) {
$current_roles = (array) um_user( 'roles' );
if ( array_intersect( $roles, $current_roles ) ) {
?>
<style type="text/css">
.um-message-footer .um-message-emoji {
display: none;
}
.um-message-footer .um-message-limit {
flex-grow: 1;
}
</style>
<?php
}
}
}
<?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