Make WordPress Core


Ignore:
Timestamp:
07/06/2016 06:08:55 PM (9 years ago)
Author:
helen
Message:

Meta: Make registration error conditions return consistently.

In doing this, non-core object types are no longer forcibly blocked and are instead checked against wp_object_type_exists() which has a filterable return value. Still, filter that at your own risk.

props Faison for the initial patch.
see 35658.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta.php

    r37990 r37991  
    10051005 * @param string|array $deprecated Deprecated. Use `$args` instead.
    10061006 *
    1007  * @return bool True if the meta key was successfully registered in the global array, false if not.
    1008  *              Registering a meta key with distinct sanitize and auth callbacks will fire those
    1009  *              callbacks, but will not add to the global registry as it requires a subtype.
     1007 * @return bool|WP_error True if the meta key was successfully registered in the global array, WP_Error if not.
     1008 *                       Registering a meta key with distinct sanitize and auth callbacks will fire those
     1009 *                       callbacks, but will not add to the global registry as it requires a subtype.
    10101010 */
    10111011function register_meta( $object_type, $meta_key, $args, $deprecated = null ) {
     
    10161016    }
    10171017
    1018     /* translators: object type name */
    1019     if ( ! in_array( $object_type, array( 'post', 'comment', 'user', 'term' ) ) ) {
    1020         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid object type: %s.' ), $object_type ), '4.6.0' );
     1018    if ( ! wp_object_type_exists( $object_type ) ) {
     1019        return new WP_Error( 'register_meta_failed', __( 'Meta can only be registered against a core object type.' ) );
    10211020    }
    10221021
     
    10641063    // Object subtype is required if using the args style of registration
    10651064    if ( ! $has_old_sanitize_cb && empty( $args['object_subtype'] ) ) {
    1066         return false;
     1065        return new WP_Error( 'register_meta_failed', __( 'Meta must be registered against an object subtype.' ) );
    10671066    }
    10681067
     
    11031102    }
    11041103
    1105     return false;
     1104    return new WP_Error( 'register_meta_failed', __( 'Sanitize and auth callbacks registered; meta key not registered.' ) );
    11061105}
    11071106
     
    11151114 * @param string $meta_key       The meta key.
    11161115 *
    1117  * @return bool True if the meta key is registered to the object type and subtype. False if not.
     1116 * @return bool|WP_error True if the meta key is registered to the object type and subtype. False if not.
     1117 *                       WP_Error if an invalid object type is passed.
    11181118 */
    11191119function registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) {
     
    11251125
    11261126    // Only specific core object types are supported.
    1127     if ( ! in_array( $object_type, array( 'post', 'comment', 'user', 'term' ) ) ) {
    1128         return false;
     1127    if ( ! wp_object_type_exists( $object_type ) ) {
     1128        return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) );
    11291129    }
    11301130
     
    12241224    }
    12251225
    1226     if ( ! in_array( $object_type, array( 'post', 'comment', 'user', 'term' ) ) ) {
     1226    if ( ! wp_object_type_exists( $object_type ) ) {
    12271227        return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) );
    12281228    }
Note: See TracChangeset for help on using the changeset viewer.