Make WordPress Core


Ignore:
Timestamp:
12/12/2018 03:02:00 AM (8 years ago)
Author:
jeremyfelt
Message:

REST API: Move object type-specific metadata integrations from the wrapper functions to the low-level Meta API functions.

Object type-specific actions that should happen before or after modification of metadata have so far been part of the respective wrapper functions. By using action and filter hooks, this changeset ensures they are always executed, even when calling the lower-level Meta API functions directly, which the REST API does as a prime example.

Merges [43729] to trunk.

Props flixos90, spacedmonkey.
Fixes #44467.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/post.php

    r43638 r43982  
    19071907function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
    19081908        // Make sure meta is added to the post, not a revision.
    1909         if ( $the_post = wp_is_post_revision( $post_id ) ) {
     1909        $the_post = wp_is_post_revision( $post_id );
     1910        if ( $the_post ) {
    19101911                $post_id = $the_post;
    19111912        }
    19121913
    1913         $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    1914         if ( $added ) {
    1915                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1916         }
    1917         return $added;
     1914        return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    19181915}
    19191916
    … …  
    19351932function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
    19361933        // Make sure meta is added to the post, not a revision.
    1937         if ( $the_post = wp_is_post_revision( $post_id ) ) {
     1934        $the_post = wp_is_post_revision( $post_id );
     1935        if ( $the_post ) {
    19381936                $post_id = $the_post;
    19391937        }
    19401938
    1941         $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    1942         if ( $deleted ) {
    1943                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1944         }
    1945         return $deleted;
     1939        return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    19461940}
    19471941
    … …  
    19821976function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
    19831977        // Make sure meta is added to the post, not a revision.
    1984         if ( $the_post = wp_is_post_revision( $post_id ) ) {
     1978        $the_post = wp_is_post_revision( $post_id );
     1979        if ( $the_post ) {
    19851980                $post_id = $the_post;
    19861981        }
    19871982
    1988         $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    1989         if ( $updated ) {
    1990                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1991         }
    1992         return $updated;
     1983        return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    19931984}
    19941985
    … …  
    20021993 */
    20031994function delete_post_meta_by_key( $post_meta_key ) {
    2004         $deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
    2005         if ( $deleted ) {
    2006                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    2007         }
    2008         return $deleted;
     1995        return delete_metadata( 'post', null, $post_meta_key, '', true );
    20091996}
    20101997
    … …  
    67866773        return $clauses;
    67876774}
     6775
     6776/**
     6777 * Sets the last changed time for the 'posts' cache group.
     6778 *
     6779 * @since 5.0.0
     6780 */
     6781function wp_cache_set_posts_last_changed() {
     6782        wp_cache_set( 'last_changed', microtime(), 'posts' );
     6783}
Note: See TracChangeset for help on using the changeset viewer.