Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.