Make WordPress Core

Ticket #24266: 24266.2.diff

File 24266.2.diff, 2.7 KB (added by nofearinc, 11 years ago)

updated logic

  • wp-includes/meta.php

     
    104104        $mid = (int) $wpdb->insert_id;
    105105
    106106        wp_cache_delete($object_id, $meta_type . '_meta');
     107        _collect_updated_postmeta_post_ids( $object_id );
    107108
    108109        /**
    109110         * Fires immediately after meta of a specific type is added.
     
    241242                return false;
    242243
    243244        wp_cache_delete($object_id, $meta_type . '_meta');
     245        _collect_updated_postmeta_post_ids( $object_id );
    244246
    245247        /**
    246248         * Fires immediately after updating metadata of a specific type.
     
    389391        if ( $delete_all ) {
    390392                foreach ( (array) $object_ids as $o_id ) {
    391393                        wp_cache_delete($o_id, $meta_type . '_meta');
     394                        _collect_updated_postmeta_post_ids( $o_id );
    392395                }
    393396        } else {
    394397                wp_cache_delete($object_id, $meta_type . '_meta');
     398                _collect_updated_postmeta_post_ids( $object_id );
    395399        }
    396400
    397401        /**
  • wp-includes/post.php

     
    54825482}
    54835483
    54845484/**
     5485 * Internal function that collects all updated post IDs when meta was changed.
     5486 *
     5487 * Modified post date will be updated later on the shutdown hook.
     5488 *
     5489 * @since 4.1
     5490 *
     5491 * @param int $post_id the ID of the modified Post object.
     5492 */
     5493function _collect_updated_postmeta_post_ids( $post_id ) {
     5494        global $updated_post_ids;
     5495       
     5496        if ( empty( $updated_post_ids ) ) {
     5497                $updated_post_ids = array();
     5498        }
     5499        if ( ! in_array( $post_id, $updated_post_ids ) ) {
     5500                $updated_post_ids[] = $post_id;
     5501        }
     5502}
     5503
     5504/**
     5505 * Helper function for updating the post modified date.
     5506 *
     5507 * Iterates over all post IDs updated during the request when meta has been changed.
     5508 * 
     5509 * @since 4.1
     5510 *
     5511 */
     5512function update_post_modified_dates() {
     5513        global $updated_post_ids;
     5514       
     5515        // Check whether posts' metadata has been changed during the request
     5516        if ( ! empty( $updated_post_ids ) && is_array( $updated_post_ids ) ) {
     5517                $post_modified     = current_time( 'mysql' );
     5518                $post_modified_gmt = current_time( 'mysql', 1 );
     5519                global $wpdb;
     5520               
     5521                $updated_fields = array(
     5522                        'post_modified' => $post_modified,
     5523                        'post_modified_gmt' => $post_modified_gmt
     5524                );
     5525               
     5526                // Update the post_modified dates for each modified post
     5527                foreach ( $updated_post_ids as $post_id ) {
     5528                        $where = array( 'ID' => $post_id );
     5529                        $wpdb->update( $wpdb->posts, $updated_fields, $where );
     5530                       
     5531                        clean_post_cache( $post_id );
     5532                }
     5533        }
     5534}
     5535add_action( 'shutdown', 'update_post_modified_dates' );
     5536
     5537/**
    54855538 * Call major cache updating functions for list of Post objects.
    54865539 *
    54875540 * @since 1.5.0