In a WordPress powered news portal, they need to upload many news at a time on a certain period of a day, in most of the cases, after 10pm (today). But they are actually inserting news for the next day (tomorrow). So in WordPress way they need to schedule the news (post) each time when publishing.

scheduling a post

The same repeating job – edit the time, change the date to the upcoming date (i.e. 19), change the Hour to 12, and Minute to 01. That’s time consuming and a bit of disturbing too.

Is there a way I can make a common thing for them so that they can set it once and upload all the posts to the newly set time? And can reset the timing anytime?

2 s
2

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 Reply

Your email address will not be published. Required fields are marked *