Making WordPress.org


Ignore:
Timestamp:
04/11/2017 04:28:33 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: The plugin post_type's post_modified date should only ever be changed in response to a SVN action, and not just because wp_update_post() was called.
This moves the code responsible for handling this special case from the plugin importer to globally affecting the site.

See #2605

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r5315 r5316  
    5757        add_action( 'rest_api_init', array( __NAMESPACE__ . '\API\Base', 'load_routes' ) );
    5858
     59        // Allow post_modified not to be modified when we don't specifically bump it.
     60        add_filter( 'wp_insert_post_data', array( $this, 'filter_wp_insert_post_data' ), 10, 2 );
     61
    5962        // Work around caching issues
    6063        add_filter( 'pre_option_jetpack_sync_full__started' , array( $this, 'bypass_options_cache' ), 10, 2 );
     
    8487        register_activation_hook( PLUGIN_FILE, array( $this, 'activate' ) );
    8588        register_deactivation_hook( PLUGIN_FILE, array( $this, 'deactivate' ) );
     89    }
     90
     91    /**
     92     * Filters `wp_insert_post()` to respect the presented data.
     93     * This function overrides `wp_insert_post()`s constant updating of
     94     * the post_modified fields.
     95     *
     96     * @param array $data    The data to be inserted into the database.
     97     * @param array $postarr The raw data passed to `wp_insert_post()`.
     98     *
     99     * @return array The data to insert into the database.
     100     */
     101    public function filter_wp_insert_post_data( $data, $postarr ) {
     102        if ( 'plugin' === $postarr['post_type'] ) {
     103            $data['post_modified']     = $postarr['post_modified'];
     104            $data['post_modified_gmt'] = $postarr['post_modified_gmt'];
     105        }
     106        return $data;
    86107    }
    87108
Note: See TracChangeset for help on using the changeset viewer.