Home / Admin / Allow Staff to view-only email logs content without the ability to delete
Duplicate Snippet

Embed Snippet on Your Site

Allow Staff to view-only email logs content without the ability to delete

Lets staff (Editors and above) open the Email Log and read the emails that were sent. Deleting, resending and exporting logs stay limited to administrators. Requires WP Mail SMTP Pro.

<10
Code Preview
php
<?php
/**
 * Let staff view the WP Mail SMTP Email Log and read sent emails, without being able
 * to delete, resend or export logs.
 * Edition: Pro (email logs are a Pro feature). Change 'edit_others_posts' to the
 * capability your staff role has (edit_others_posts = Editors and above).
 */
// Open the Email Log list and single log pages to staff.
add_filter( 'wp_mail_smtp_admin_area_get_logs_access_capability', function () {
	return 'edit_others_posts';
} );
// Lend the "manage" capability only to the email preview request so staff can read the email.
// Delete, resend, export and re-check stay admin-only, and their buttons stay hidden.
add_filter( 'wp_mail_smtp_pro_emails_logs_logs_get_manage_capability', function ( $capability ) {
	if (
		is_admin() &&
		isset( $_GET['page'], $_GET['mode'] ) &&
		$_GET['page'] === 'wp-mail-smtp-logs' &&
		$_GET['mode'] === 'preview' &&
		current_user_can( 'edit_others_posts' )
	) {
		return 'edit_others_posts';
	}
	return $capability;
} );

Comments

Add a Comment