Make WordPress Core


Ignore:
Timestamp:
12/12/2018 03:02:00 AM (7 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/meta.php

    r43582 r43982  
    614614    $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';
    615615
     616    /**
     617     * Filters whether to retrieve metadata of a specific type by meta ID.
     618     *
     619     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     620     * object type (comment, post, term, or user). Returning a non-null value
     621     * will effectively short-circuit the function.
     622     *
     623     * @since 5.0.0
     624     *
     625     * @param mixed $value    The value get_metadata_by_mid() should return.
     626     * @param int   $meta_id  Meta ID.
     627     */
     628    $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id );
     629    if ( null !== $check ) {
     630        return $check;
     631    }
     632
    616633    $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) );
    617634
     
    660677    $column    = sanitize_key( $meta_type . '_id' );
    661678    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
     679
     680    /**
     681     * Filters whether to update metadata of a specific type by meta ID.
     682     *
     683     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     684     * object type (comment, post, term, or user). Returning a non-null value
     685     * will effectively short-circuit the function.
     686     *
     687     * @since 5.0.0
     688     *
     689     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     690     * @param int         $meta_id    Meta ID.
     691     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     692     * @param string|bool $meta_key   Meta key, if provided.
     693     */
     694    $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key );
     695    if ( null !== $check ) {
     696        return (bool) $check;
     697    }
    662698
    663699    // Fetch the meta and go on if it's found.
     
    755791    $column    = sanitize_key( $meta_type . '_id' );
    756792    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
     793
     794    /**
     795     * Filters whether to delete metadata of a specific type by meta ID.
     796     *
     797     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     798     * object type (comment, post, term, or user). Returning a non-null value
     799     * will effectively short-circuit the function.
     800     *
     801     * @since 5.0.0
     802     *
     803     * @param null|bool $delete  Whether to allow metadata deletion of the given type.
     804     * @param int       $meta_id Meta ID.
     805     */
     806    $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id );
     807    if ( null !== $check ) {
     808        return (bool) $check;
     809    }
    757810
    758811    // Fetch the meta and go on if it's found.
     
    841894
    842895    $object_ids = array_map( 'intval', $object_ids );
     896
     897    /**
     898     * Filters whether to update the metadata cache of a specific type.
     899     *
     900     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     901     * object type (comment, post, term, or user). Returning a non-null value
     902     * will effectively short-circuit the function.
     903     *
     904     * @since 5.0.0
     905     *
     906     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     907     * @param array $object_ids Array of object IDs to update the meta cache for.
     908     */
     909    $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );
     910    if ( null !== $check ) {
     911        return (bool) $check;
     912    }
    843913
    844914    $cache_key = $meta_type . '_meta';
Note: See TracChangeset for help on using the changeset viewer.