Make WordPress Core


Ignore:
Timestamp:
10/07/2015 09:52:18 PM (9 years ago)
Author:
johnbillion
Message:

Pass the $post parameter to the _wp_post_revision_fields filter. This provides more context to the filter, which allows for different fields to be displayed on the revisions screen depending on the post.

The _wp_post_revision_fields() function now also accepts a WP_Post object (in addition to an array of post fields) to facilitate this change.

Fixes #13382
Props adamsilverstein

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/revision.php

    r33734 r34917  
    1515 *
    1616 * @since 2.6.0
     17 * @since 4.4.0 A `WP_Post` object can now be passed to the `$post` parameter.
    1718 * @access private
    1819 *
    1920 * @staticvar array $fields
    2021 *
    21  * @param array $post     Optional. A post array to be processed for insertion as a post revision.
    22  * @param bool  $autosave Optional. Is the revision an autosave?
     22 * @param array|WP_Post $post     Optional. A post array, or a WP_Post object to be processed for insertion as a post revision.
     23 * @param bool          $autosave Optional. Is the revision an autosave? Default false.
    2324 * @return array Post array ready to be inserted as a post revision or array of fields that can be versioned.
    2425 */
    2526function _wp_post_revision_fields( $post = null, $autosave = false ) {
    2627    static $fields = null;
     28
     29    if ( is_object( $post ) ) {
     30        $post = get_post( $post, ARRAY_A );
     31    }
    2732
    2833    if ( is_null( $fields ) ) {
     
    4449         *
    4550         * @since 2.6.0
     51         * @since 4.4.0 The `$post` parameter was added.
    4652         *
    4753         * @param array $fields List of fields to revision. Contains 'post_title',
    4854         *                      'post_content', and 'post_excerpt' by default.
     55         * @param array $post   A post array being processed for insertion as a post revision.
    4956         */
    50         $fields = apply_filters( '_wp_post_revision_fields', $fields );
     57        $fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
    5158
    5259        // WP uses these internally either in versioning or elsewhere - they cannot be versioned
     
    128135            $post_has_changed = false;
    129136
    130             foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
     137            foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
    131138                if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
    132139                    $post_has_changed = true;
     
    334341
    335342    if ( !is_array( $fields ) )
    336         $fields = array_keys( _wp_post_revision_fields() );
     343        $fields = array_keys( _wp_post_revision_fields( $revision ) );
    337344
    338345    $update = array();
Note: See TracChangeset for help on using the changeset viewer.