Weekly Email of Upcoming Scheduled Posts
Emails editors and the admin every Monday with the posts scheduled to publish in the coming week, so everyone knows what is going live and when.
Opens WPIDE on
Code
add_action( 'init', function () {
if ( wp_next_scheduled( 'wpide_scheduled_posts_email' ) ) {
return;
}
$next = new DateTime( 'monday this week 08:00', wp_timezone() );
if ( $next->getTimestamp() <= time() ) {
$next->modify( '+1 week' );
}
wp_schedule_event( $next->getTimestamp(), 'weekly', 'wpide_scheduled_posts_email' );
} );
add_action( 'wpide_scheduled_posts_email', function () {
$posts = get_posts( array(
'post_type' => 'any',
'post_status' => 'future',
'numberposts' => 100,
'orderby' => 'date',
'order' => 'ASC',
'no_found_rows' => true,
'date_query' => array( array( 'before' => gmdate( 'Y-m-d H:i:s', time() + WEEK_IN_SECONDS ), 'column' => 'post_date_gmt' ) ),
) );
if ( ! $posts ) {
return;
}
$lines = array( 'Scheduled to publish in the next 7 days:', '' );
foreach ( $posts as $post ) {
$lines[] = sprintf( '• %s – %s (%s)', get_the_date( 'D j M, H:i', $post ), wp_strip_all_tags( get_the_title( $post ) ), get_the_author_meta( 'display_name', $post->post_author ) );
}
$to = array_merge( array( get_option( 'admin_email' ) ), wp_list_pluck( get_users( array( 'role' => 'editor', 'fields' => array( 'user_email' ) ) ), 'user_email' ) );
wp_mail( array_unique( $to ), sprintf( '[%s] %d post(s) scheduled this week', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), count( $posts ) ), implode( "\n", $lines ) );
} );
Notes
Goes to every user with the Editor role plus the admin email; nothing is sent when no posts are scheduled.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.