How to schedule multiple posts while adding new

Here’s a sketch of another idea, where we create scheduling shortcuts to make it easier for the users:

scheduling shortcuts

We can use the post_submitbox_misc_actions to add extra fields to the submit box:

/**
 * Scheduling-Shortcuts fields.
 *
 * @see http://wordpress.stackexchange.com/a/168748/26350
 */

add_action( 'post_submitbox_misc_actions', function() {

    if( ! current_user_can( 'publish_posts' ) ) 
        return;
?>
    <div style="padding: 2px 10px;">
        <h4><?php _e( 'Scheduling shortcuts:' ); ?></h4>
        <ul class="schedule-shortcuts">
            <li>
                <input type="radio" value="current" 
                       name="wpse_schedule_shortcut" 
                       id="shcedule-shortcut-0" checked="checked" />
                <label for="shcedule-shortcut-0"><?php _e( 'Current settings' );?></label>
            </li>
            <li>
                <input type="radio" value="tomorrow_at_12"   
                       name="wpse_schedule_shortcut" id="shcedule-shortcut-1" />
                <label for="shcedule-shortcut-1"><?php _e( 'Tomorrow @12' );?></label>
            </li>
        </ul>
        <?php wp_nonce_field( 'schedule_shortcut_action','schedule_shortcut_field'); ?>
    </div>
<?php
});

where we can then modify the insert post data accordingly via the wp_insert_post_data filter:

/**
 * Scheduling-Shortcuts post data handling.
 *
 * @see http://wordpress.stackexchange.com/a/168748/26350
 */

add_filter( 'wp_insert_post_data', function( $data, $postarr ) {

    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return $data;

    if( ! current_user_can( 'publish_posts' ) )
        return $data; 

    if( ! isset( $postarr['post_type'] ) || 'post' !== $postarr['post_type'] )
        return $data;

    if( ! isset( $postarr['action'] ) || 'editpost' !== $postarr['action'] )
        return $data;

    if ( ! isset( $postarr['schedule_shortcut_field'] ) 
         || !wp_verify_nonce($postarr['schedule_shortcut_field'],'schedule_shortcut_action')
    ) 
        return $data;

    if( isset( $postarr['wpse_schedule_shortcut'] ) 
        && 'tomorrow_at_12' === $postarr['wpse_schedule_shortcut'] 
    )
    {
        $data['post_status']     = 'future';
        $data['post_date']       = date( 'Y-m-d H:i:s',   strtotime( "+1 day 00:00" ) );
        $data['post_date_gmt']   = gmdate( 'Y-m-d H:i:s', strtotime( "+1 day 00:00" ) );
    }       
    return $data;
}, 10, 2 );

Hopefully you can adjust this further to your needs.

Leave a Comment