Changeset 37991
- Timestamp:
- 07/06/2016 06:08:55 PM (8 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r37985 r37991 5357 5357 return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted ); 5358 5358 } 5359 5360 /** 5361 * Check if an object type exists. By default, these are `post`, `comment`, `user`, and `term`. 5362 * 5363 * @param string $object_type Object type to check. 5364 * @return bool True if the object type exists, false if not. 5365 */ 5366 function wp_object_type_exists( $object_type ) { 5367 /** 5368 * Filters WordPress object types. 5369 * 5370 * @since 4.6.0 5371 * 5372 * @param array $types Array of object types. 5373 */ 5374 $types = apply_filters( 'wp_object_types', array( 'post', 'comment', 'user', 'term' ) ); 5375 5376 if ( in_array( $object_type, $types ) ) { 5377 return true; 5378 } 5379 5380 return false; 5381 } -
trunk/src/wp-includes/meta.php
r37990 r37991 1005 1005 * @param string|array $deprecated Deprecated. Use `$args` instead. 1006 1006 * 1007 * @return bool True if the meta key was successfully registered in the global array, falseif not.1008 * Registering a meta key with distinct sanitize and auth callbacks will fire those1009 * 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. 1010 1010 */ 1011 1011 function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { … … 1016 1016 } 1017 1017 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.' ) ); 1021 1020 } 1022 1021 … … 1064 1063 // Object subtype is required if using the args style of registration 1065 1064 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.' ) ); 1067 1066 } 1068 1067 … … 1103 1102 } 1104 1103 1105 return false;1104 return new WP_Error( 'register_meta_failed', __( 'Sanitize and auth callbacks registered; meta key not registered.' ) ); 1106 1105 } 1107 1106 … … 1115 1114 * @param string $meta_key The meta key. 1116 1115 * 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. 1118 1118 */ 1119 1119 function registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) { … … 1125 1125 1126 1126 // 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.' ) ); 1129 1129 } 1130 1130 … … 1224 1224 } 1225 1225 1226 if ( ! in_array( $object_type, array( 'post', 'comment', 'user', 'term' )) ) {1226 if ( ! wp_object_type_exists( $object_type ) ) { 1227 1227 return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) ); 1228 1228 }
Note: See TracChangeset
for help on using the changeset viewer.