diff --git a/wp-includes/meta.php b/wp-includes/meta.php
index ff32086..bfbc61b 100644
|
a
|
b
|
function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = |
| 1005 | 1005 | * } |
| 1006 | 1006 | * @param string|array $deprecated Deprecated. Use `$args` instead. |
| 1007 | 1007 | * |
| 1008 | | * @return bool|WP_error True if the meta key was successfully registered in the global array, WP_Error if not. |
| | 1008 | * @return bool|_doing_it_wrong True if the meta key was successfully registered in the global array, _doing_it_wrong() if not. |
| 1009 | 1009 | * Registering a meta key with distinct sanitize and auth callbacks will fire those |
| 1010 | 1010 | * callbacks, but will not add to the global registry as it requires a subtype. |
| 1011 | 1011 | */ |
| … |
… |
function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { |
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | if ( ! wp_object_type_exists( $object_type ) ) { |
| 1020 | | return new WP_Error( 'register_meta_failed', __( 'Meta can only be registered against a core object type.' ) ); |
| | 1020 | _doing_it_wrong( __FUNCTION__, __( 'Meta can only be registered against a core object type.' ), '4.6.0' ); |
| | 1021 | return false; |
| 1021 | 1022 | } |
| 1022 | 1023 | |
| 1023 | 1024 | $defaults = array( |
| … |
… |
function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { |
| 1065 | 1066 | |
| 1066 | 1067 | // Object subtype is required if using the args style of registration |
| 1067 | 1068 | if ( ! $has_old_sanitize_cb && ! $has_old_auth_cb && empty( $args['object_subtype'] ) ) { |
| 1068 | | return new WP_Error( 'register_meta_failed', __( 'Meta must be registered against an object subtype.' ) ); |
| | 1069 | _doing_it_wrong( __FUNCTION__, __( 'Meta must be registered against an object subtype.' ), '4.6.0' ); |
| | 1070 | return false; |
| 1069 | 1071 | } |
| 1070 | 1072 | |
| 1071 | 1073 | // If `auth_callback` is not provided, fall back to `is_protected_meta()`. |
| … |
… |
function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { |
| 1109 | 1111 | return true; |
| 1110 | 1112 | } |
| 1111 | 1113 | |
| 1112 | | return new WP_Error( 'register_meta_failed', __( 'Sanitize and auth callbacks registered; meta key not registered.' ) ); |
| | 1114 | _doing_it_wrong( __FUNCTION__, __( 'Sanitize and auth callbacks are already registered, but meta key not yet registered.' ), '4.6.0' ); |
| | 1115 | return false; |
| 1113 | 1116 | } |
| 1114 | 1117 | |
| 1115 | 1118 | /** |
| … |
… |
function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { |
| 1121 | 1124 | * @param string $object_subtype The subtype of the object type. |
| 1122 | 1125 | * @param string $meta_key The meta key. |
| 1123 | 1126 | * |
| 1124 | | * @return bool|WP_error True if the meta key is registered to the object type and subtype. False if not. |
| 1125 | | * WP_Error if an invalid object type is passed. |
| | 1127 | * @return bool|_doing_it_wrong True if the meta key is registered to the object type and subtype. False if not. |
| | 1128 | * _doing_it_wrong() if an invalid object type is passed. |
| 1126 | 1129 | */ |
| 1127 | 1130 | function registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) { |
| 1128 | 1131 | global $wp_meta_keys; |
| … |
… |
function registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) |
| 1133 | 1136 | |
| 1134 | 1137 | // Only specific core object types are supported. |
| 1135 | 1138 | if ( ! wp_object_type_exists( $object_type ) ) { |
| 1136 | | return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) ); |
| | 1139 | _doing_it_wrong( __FUNCTION__, __( 'Object type is invalid, it must be a core object type.' ), '4.6.0' ); |
| | 1140 | return false; |
| 1137 | 1141 | } |
| 1138 | 1142 | |
| 1139 | 1143 | if ( ! isset( $wp_meta_keys[ $object_type ] ) ) { |
| … |
… |
function registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) |
| 1160 | 1164 | * @param string $object_subtype The subtype of the object type. |
| 1161 | 1165 | * @param string $meta_key The meta key. |
| 1162 | 1166 | * |
| 1163 | | * @return bool|WP_Error True if successful. WP_Error if the meta key is invalid. |
| | 1167 | * @return bool|_doing_it_wrong True if successful. _doing_it_wrong() if the meta key is invalid. |
| 1164 | 1168 | */ |
| 1165 | 1169 | function unregister_meta_key( $object_type, $object_subtype, $meta_key ) { |
| 1166 | 1170 | global $wp_meta_keys; |
| 1167 | 1171 | |
| 1168 | 1172 | if ( ! registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) ) { |
| 1169 | | return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key' ) ); |
| | 1173 | _doing_it_wrong( __FUNCTION__, __( 'Invalid meta key' ), '4.6.0' ); |
| | 1174 | return false; |
| 1170 | 1175 | } |
| 1171 | 1176 | |
| 1172 | 1177 | $args = $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ]; |
| … |
… |
function get_registered_meta_keys( $object_type, $object_subtype = '' ) { |
| 1232 | 1237 | * @param string $meta_key Optional. Registered metadata key. If not specified, retrieve all registered |
| 1233 | 1238 | * metadata for the specified object. |
| 1234 | 1239 | * |
| 1235 | | * @return mixed|WP_Error |
| | 1240 | * @return mixed|_doing_it_wrong |
| 1236 | 1241 | */ |
| 1237 | 1242 | function get_registered_metadata( $object_type, $object_subtype, $object_id, $meta_key = '' ) { |
| 1238 | 1243 | global $wp_meta_keys; |
| 1239 | 1244 | |
| 1240 | 1245 | if ( ! is_array( $wp_meta_keys ) ) { |
| 1241 | | return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) ); |
| | 1246 | _doing_it_wrong( __FUNCTION__, __( 'Invalid meta key, it is not registered yet.' ), '4.6.0' ); |
| | 1247 | return false; |
| 1242 | 1248 | } |
| 1243 | 1249 | |
| 1244 | 1250 | if ( ! wp_object_type_exists( $object_type ) ) { |
| 1245 | | return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) ); |
| | 1251 | _doing_it_wrong( __FUNCTION__, __( 'Object type is invalid, it must be a core object type.' ), '4.6.0' ); |
| | 1252 | return false; |
| 1246 | 1253 | } |
| 1247 | 1254 | |
| 1248 | 1255 | if ( ! empty( $meta_key ) ) { |
| 1249 | 1256 | if ( ! registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) ) { |
| 1250 | | return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) ); |
| | 1257 | _doing_it_wrong( __FUNCTION__, __( 'Invalid meta key, it is not registered yet.' ), '4.6.0' ); |
| | 1258 | return false; |
| 1251 | 1259 | } |
| 1252 | 1260 | $meta_keys = get_registered_meta_keys( $object_type, $object_subtype ); |
| 1253 | 1261 | $meta_key_data = $meta_keys[ $meta_key ]; |