Make WordPress Core

Ticket #24266: 24266.3.diff

File 24266.3.diff, 2.8 KB (added by nofearinc, 11 years ago)
  • wp-includes/meta.php

     
    104104        $mid = (int) $wpdb->insert_id;
    105105
    106106        wp_cache_delete($object_id, $meta_type . '_meta');
     107       
     108        // Don't fire for comment or user meta
     109        if ( 'post' === $meta_type ) {
     110                _collect_updated_postmeta_post_ids( $object_id );
     111        }
    107112
    108113        /**
    109114         * Fires immediately after meta of a specific type is added.
     
    268273                 * @param string $meta_key   Meta key.
    269274                 * @param mixed  $meta_value Meta value.
    270275                 */
     276                _collect_updated_postmeta_post_ids( $object_id );
    271277                do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    272278        }
    273279
     
    411417
    412418        // Old-style action.
    413419        if ( 'post' == $meta_type ) {
     420                if ( $delete_all ) {
     421                        foreach ( (array) $object_ids as $o_id ) {
     422                                _collect_updated_postmeta_post_ids( $o_id );
     423                        }
     424                } else {
     425                        _collect_updated_postmeta_post_ids( $object_id );
     426                }
    414427                /**
    415428                 * Fires immediately after deleting metadata for a post.
    416429                 *
  • 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