4

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
  • If I understand well: you want that default behaviour is to schedule posts instead of publishing them immediately and that the date / time of schedule should be configurable sitewide. Am I right? – gmazzap Nov 18 '14 at 10:25
  • No, that may always NOT the case. Because sometimes they may need to publish an article immediately. I think it'd better if we think a chunk of posts to be scheduled but not all. Or, whether can it be done by creating a session when to schedule for a certain period? – Mayeenul Islam Nov 18 '14 at 10:36
6

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.

9
  • This is a good one. But how to get rid of the undefined index generating from if( 'editpost' !== $postarr['action'] ) return $data;? – Mayeenul Islam Nov 19 '14 at 7:27
  • ahh, please check out the update ;-) – birgire Nov 19 '14 at 7:38
  • add_action()'s ending tags are not ended correctly. ...After scheduling posts in this way when I changed the PC date, they got published - everthing's ok. But why the Missed schedule warning is there always (screenshot)? – Mayeenul Islam Nov 19 '14 at 7:58
  • Pardon me please. But did you get time to have a look? – Mayeenul Islam Nov 22 '14 at 17:41
  • 1
    IS the PERFECT answer now. Thanks a lot @birgire for your time and effort. It's working excellent now after I've changed the hour from 12:00 to 00:00. Thank you soo much. :) – Mayeenul Islam Dec 13 '14 at 19:02
1

Okay, got a temporary solution, suggested by one of my non-WP colleague, Mr. Shamim. And tested in WP 4.0 with success — It's the bulk publish from drafts.

bulk draft selection to edit

bulk publish multiple drafts

The idea is, whatever the series of posts or bunch of posts are to publish, first save 'em as a draft. Then on the time, when it's time, check all of them in a bunch, choose Edit from the Bulk Actions dropdown menu, and then on the expanded panel, choose "Published" from the status, and finally hit Update.

But it has one drawback, you have to come back to the post list when you want to publish them all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.