Make WordPress Core


Ignore:
Timestamp:
10/15/2018 11:45:16 AM (5 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/meta.php

    r43706 r43729  
    587587    $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';
    588588
     589    /**
     590     * Filters whether to retrieve metadata of a specific type by meta ID.
     591     *
     592     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     593     * object type (comment, post, term, or user). Returning a non-null value
     594     * will effectively short-circuit the function.
     595     *
     596     * @since 5.0.0
     597     *
     598     * @param mixed $value    The value get_metadata_by_mid() should return.
     599     * @param int   $meta_id  Meta ID.
     600     */
     601    $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id );
     602    if ( null !== $check ) {
     603        return $check;
     604    }
     605
    589606    $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) );
    590607
     
    631648    $column = sanitize_key($meta_type . '_id');
    632649    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
     650
     651    /**
     652     * Filters whether to update metadata of a specific type by meta ID.
     653     *
     654     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     655     * object type (comment, post, term, or user). Returning a non-null value
     656     * will effectively short-circuit the function.
     657     *
     658     * @since 5.0.0
     659     *
     660     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     661     * @param int         $meta_id    Meta ID.
     662     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     663     * @param string|bool $meta_key   Meta key, if provided.
     664     */
     665    $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key );
     666    if ( null !== $check ) {
     667        return (bool) $check;
     668    }
    633669
    634670    // Fetch the meta and go on if it's found.
     
    725761    $column = sanitize_key($meta_type . '_id');
    726762    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
     763
     764    /**
     765     * Filters whether to delete metadata of a specific type by meta ID.
     766     *
     767     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     768     * object type (comment, post, term, or user). Returning a non-null value
     769     * will effectively short-circuit the function.
     770     *
     771     * @since 5.0.0
     772     *
     773     * @param null|bool $delete  Whether to allow metadata deletion of the given type.
     774     * @param int       $meta_id Meta ID.
     775     */
     776    $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id );
     777    if ( null !== $check ) {
     778        return (bool) $check;
     779    }
    727780
    728781    // Fetch the meta and go on if it's found.
     
    811864
    812865    $object_ids = array_map('intval', $object_ids);
     866
     867    /**
     868     * Filters whether to update the metadata cache of a specific type.
     869     *
     870     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     871     * object type (comment, post, term, or user). Returning a non-null value
     872     * will effectively short-circuit the function.
     873     *
     874     * @since 5.0.0
     875     *
     876     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     877     * @param array $object_ids Array of object IDs to update the meta cache for.
     878     */
     879    $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );
     880    if ( null !== $check ) {
     881        return (bool) $check;
     882    }
    813883
    814884    $cache_key = $meta_type . '_meta';
Note: See TracChangeset for help on using the changeset viewer.