WordPress.org

Making WordPress.org

Changeset 5685


Ignore:
Timestamp:
07/17/2017 10:24:58 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Keep the original post date when approving a pending post.

Set a non-empty post_date_gmt for pending posts to prevent wp_update_post() from overwriting the post date on approving.

Fixes #2963.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r5662 r5685  
    1212        add_filter( 'pre_option__bbp_edit_lock',      array( $this, 'increase_edit_lock_time' ) );
    1313        add_filter( 'redirect_canonical',             array( $this, 'disable_redirect_guess_404_permalink' ) );
     14        add_filter( 'wp_insert_post_data',            array( $this, 'set_post_date_gmt_for_pending_posts' ) );
    1415        add_action( 'wp_print_footer_scripts',        array( $this, 'replace_quicktags_blockquote_button' ) );
    1516
     
    119120
    120121        return $redirect_url;
     122    }
     123
     124    /**
     125     * Keep the original post date when approving a pending post.
     126     *
     127     * Sets a non-empty 'post_date_gmt' for pending posts to prevent wp_update_post()
     128     * from overwriting the post date on approving.
     129     *
     130     * @param array $data An array of post data.
     131     * @return array Filtered post data.
     132     */
     133    public function set_post_date_gmt_for_pending_posts( $data ) {
     134        if (
     135            in_array( $data['post_type'], array( 'topic', 'reply' ) )
     136        &&
     137            'pending' === $data['post_status']
     138        &&
     139            '0000-00-00 00:00:00' === $data['post_date_gmt']
     140        ) {
     141            $data['post_date_gmt'] = get_gmt_from_date( $data['post_date'] );
     142        }
     143
     144        return $data;
    121145    }
    122146
Note: See TracChangeset for help on using the changeset viewer.