Make WordPress Core


Ignore:
Timestamp:
10/15/2018 11:45:16 AM (8 years ago)
Author:
flixos90
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.

Props flixos90, spacedmonkey.
Fixes #44467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/post.php

    r43710 r43729  
    17851785function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
    17861786        // Make sure meta is added to the post, not a revision.
    1787         if ( $the_post = wp_is_post_revision($post_id) )
     1787        $the_post = wp_is_post_revision( $post_id );
     1788        if ( $the_post ) {
    17881789                $post_id = $the_post;
    1789 
    1790         $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    1791         if ( $added ) {
    1792                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1793         }
    1794         return $added;
     1790        }
     1791
     1792        return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    17951793}
    17961794
    … …  
    18121810function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
    18131811        // Make sure meta is added to the post, not a revision.
    1814         if ( $the_post = wp_is_post_revision($post_id) )
     1812        $the_post = wp_is_post_revision( $post_id );
     1813        if ( $the_post ) {
    18151814                $post_id = $the_post;
    1816 
    1817         $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    1818         if ( $deleted ) {
    1819                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1820         }
    1821         return $deleted;
     1815        }
     1816
     1817        return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    18221818}
    18231819
    … …  
    18581854function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
    18591855        // Make sure meta is added to the post, not a revision.
    1860         if ( $the_post = wp_is_post_revision($post_id) )
     1856        $the_post = wp_is_post_revision( $post_id );
     1857        if ( $the_post ) {
    18611858                $post_id = $the_post;
    1862 
    1863         $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    1864         if ( $updated ) {
    1865                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1866         }
    1867         return $updated;
     1859        }
     1860
     1861        return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    18681862}
    18691863
    … …  
    18771871 */
    18781872function delete_post_meta_by_key( $post_meta_key ) {
    1879         $deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
    1880         if ( $deleted ) {
    1881                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1882         }
    1883         return $deleted;
     1873        return delete_metadata( 'post', null, $post_meta_key, '', true );
    18841874}
    18851875
    … …  
    64766466        return $clauses;
    64776467}
     6468
     6469/**
     6470 * Sets the last changed time for the 'posts' cache group.
     6471 *
     6472 * @since 5.0.0
     6473 */
     6474function wp_cache_set_posts_last_changed() {
     6475        wp_cache_set( 'last_changed', microtime(), 'posts' );
     6476}
Note: See TracChangeset for help on using the changeset viewer.