Plugin Directory

Changeset 382440


Ignore:
Timestamp:
05/08/2011 01:26:11 PM (15 years ago)
Author:
tetele
Message:

FIX: Plugin used to schedule posts when updating. This was incorrect. Now plugin only *attempts* to schedule posts upon publishing.
FEATURE: ability to choose whether to schedule posts or not with a checkbox in the post submit box.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • automatic-post-scheduler/trunk/plugin.php

    r313569 r382440  
    1616add_action( 'init', 'aps_init' );
    1717function aps_init() {
    18     add_filter( 'wp_insert_post_data', 'aps_check_and_schedule' );
     18    // Attach checkbox to publish box on edit post page
     19    add_action( 'post_submitbox_misc_actions', 'aps_publish_box' );
     20   
     21    // Actually delay/schedule post publishing
     22    add_filter( 'wp_insert_post_data', 'aps_check_and_schedule', 10, 2 );
    1923}
    2024
     
    2630 *
    2731 * @param object $data Post object
     32 * @param object $postarr Raw HTTP POST data
    2833 * @return object Filtered post object
    2934 */
    30 function aps_check_and_schedule( $data ) {
     35function aps_check_and_schedule( $data, $postarr ) {
     36    // check if scheduling should occur
     37    if( !( isset( $postarr['aps_schedule_post'] ) && $postarr['aps_schedule_post'] ) )
     38        return $data;
     39   
    3140    // post_status is definately set, since we're using sanitized data. No check necessary
    3241    $post_status = $data['post_status'];
    3342   
     43    // only invoke upon publishing
    3444    if ( $post_status != 'publish' )
    3545        return $data;
     
    4757   
    4858    return $data;
     59}
     60
     61/**
     62 * Adds schedule checkbox on post page, in publish box (aka post submit box)
     63 *
     64 * @since 0.9.1
     65 */
     66function aps_publish_box() {
     67    global $post;
     68    if ( !current_user_can( 'publish_posts' ) || in_array( $post->post_status, array( 'publish', 'future' ) ) )
     69        return;
     70?>
     71<div class="misc-pub-section" id="aps_schedule_post">
     72    <label><input type="checkbox" id="aps_schedule_post" name="aps_schedule_post" <?php echo ( $post->post_status == 'publish' ) ? '' : 'checked="checked"'; ?>/> <?php _e( 'Schedule as soon as posible', 'autoscheduler' ); ?></label>
     73</div>
     74<?php
    4975}
    5076
Note: See TracChangeset for help on using the changeset viewer.