Plugin Directory

Changeset 3693243


Ignore:
Timestamp:
09/13/2026 01:50:14 AM (2 months ago)
Author:
techygeekshome
Message:

Bug fixes.

Location:
controlled-draft-publisher
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • controlled-draft-publisher/trunk/controlled-draft-publisher.php

    r3692231 r3693243  
    44 * Plugin Name: Controlled Draft Publisher
    55 * Description: Publishes draft posts on a configurable interval per post type, with a "Next Up" dashboard preview, a per-post auto-publish exclude option, optional publishing-window/weekend restrictions, email alerts, and logging.
    6  * Version: 1.7.6
     6 * Version: 1.7.7
    77 * Requires at least: 5.0
    88 * Tested up to: 7.0.2
    … …  
    7777    add_option( 'cdp_posts_per_run', 1 );
    7878    add_option( 'cdp_gap_seconds', 0 );
     79    add_option( 'cdp_stamp_publish_date', true );
    7980    add_option( 'cdp_categories', [] );
    8081    add_option( 'cdp_post_type_intervals', [] );
    … …  
    367368 */
    368369function cdp_publish_one_post( $id ) {
    369     $result = wp_update_post( [ 'ID' => $id, 'post_status' => 'publish' ], true );
     370    $postarr = [ 'ID' => $id, 'post_status' => 'publish' ];
     371
     372    /*
     373     * WordPress only moves a draft's date to now when that draft has never had a
     374     * date of its own, which it signals with an empty post_date_gmt. See the
     375     * $clear_date branch in wp_update_post().
     376     *
     377     * Plenty of drafts fail that test and keep a real post_date_gmt: anything
     378     * that was scheduled and then put back to draft, anything reverted from
     379     * published, imported content, and posts created through the REST API or
     380     * wp_insert_post with a date. Publishing one of those with nothing but a
     381     * status change leaves it dated whenever that date was set, so it goes live
     382     * part way down the blog instead of at the top.
     383     *
     384     * Stamping the date here makes every post this plugin publishes carry the
     385     * time it actually went live, which is what a drip publisher should do.
     386     */
     387    if ( get_option( 'cdp_stamp_publish_date', true ) ) {
     388        $now = current_time( 'mysql' );
     389        $postarr['post_date']     = $now;
     390        $postarr['post_date_gmt'] = get_gmt_from_date( $now );
     391        $postarr['edit_date']     = true;
     392    }
     393
     394    $result = wp_update_post( $postarr, true );
    370395
    371396    if ( is_wp_error( $result ) ) {
    … …  
    11581183        update_option( 'cdp_gap_seconds', $new_gap );
    11591184
     1185        update_option( 'cdp_stamp_publish_date', isset( $_POST['cdp_stamp_publish_date'] ) );
     1186
    11601187        $raw_categories = filter_input( INPUT_POST, 'cdp_categories', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
    11611188        if ( $raw_categories === null ) {
    … …  
    12141241    $posts_per_run = intval( get_option( 'cdp_posts_per_run', 1 ) );
    12151242    $gap_seconds = intval( get_option( 'cdp_gap_seconds', 0 ) );
     1243    $stamp_date = get_option( 'cdp_stamp_publish_date', true );
    12161244    $selected_categories = get_option( 'cdp_categories', [] );
    12171245    $categories = get_categories( [ 'hide_empty' => false ] );
    … …  
    12311259    echo '<tr><th scope="row">' . esc_html__( 'Posts Per Run', 'controlled-draft-publisher' ) . '</th><td><input type="number" name="cdp_posts_per_run" value="' . esc_attr( $posts_per_run ) . '" min="1" /></td></tr>';
    12321260    echo '<tr><th scope="row">' . esc_html__( 'Gap Between Posts (seconds)', 'controlled-draft-publisher' ) . '</th><td><input type="number" name="cdp_gap_seconds" value="' . esc_attr( $gap_seconds ) . '" min="0" max="3600" /><p class="description">' . esc_html__( 'Only applies when Posts Per Run is more than 1. The first post of a run publishes straight away and the rest are spaced out by this many seconds. 0 publishes them all at once.', 'controlled-draft-publisher' ) . '</p><p class="description">' . esc_html__( 'WordPress cron only runs when someone visits the site, so the gap is a minimum rather than a guarantee. On a quiet site set up a real server cron for accurate spacing.', 'controlled-draft-publisher' ) . '</p></td></tr>';
     1261    echo '<tr><th scope="row">' . esc_html__( 'Publish Date', 'controlled-draft-publisher' ) . '</th><td><label><input type="checkbox" name="cdp_stamp_publish_date" ' . checked( $stamp_date, true, false ) . '> ' . esc_html__( 'Date each post when it is published', 'controlled-draft-publisher' ) . '</label><p class="description">' . esc_html__( 'Recommended. WordPress keeps the old date on any draft that already has one, which includes drafts that were once scheduled, reverted from published, or imported. Those posts go live part way down the blog. Untick this only if you want the date already on the draft to be kept.', 'controlled-draft-publisher' ) . '</p></td></tr>';
    12331262    echo '<tr><th scope="row">' . esc_html__( 'Post Types', 'controlled-draft-publisher' ) . '</th><td>';
    12341263    foreach ( $post_types as $type ) {
  • controlled-draft-publisher/trunk/readme.txt

    r3692231 r3693243  
    66Tested up to: 7.0.2
    77Requires PHP: 8.0
    8 Stable tag: 1.7.6
     8Stable tag: 1.7.7
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    7272
    7373== Changelog ==
     74
     75= 1.7.7 =
     76* Fixed: posts published by the plugin could go live carrying an old date instead of the date they were published, so they appeared part way down the blog. WordPress only moves a draft's date forward when that draft has never had a date of its own, which leaves out anything that was scheduled and then put back to draft, reverted from published, or imported. The plugin now stamps the publish date itself.
     77* New setting: Publish Date. On by default. Untick it if you would rather keep whatever date is already on the draft.
     78* Thanks to @gamark on the support forum for spotting it and for the patch.
    7479
    7580= 1.7.6 =
Note: See TracChangeset for help on using the changeset viewer.