From 40d834dfc71d0c93d4f7e262e0768b2aeaf977e4 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Thu, 30 Jun 2016 18:59:49 +0000 Subject: [PATCH] Meta registration: Ensure `$args` is an array and simplify compat logic. props ocean90, sc0ttkclark. see #35658. git-svn-id: https://develop.svn.wordpress.org/trunk@37933 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/meta.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index 59915c4a7c..50aa75b2c5 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -980,8 +980,6 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = * @param string $object_subtype Object subtype. */ return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type, $object_subtype ); - - } /** @@ -1003,13 +1001,13 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = * @type string $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks. * @type bool $show_in_rest Whether data associated with this meta key can be considered public. * } - * @param string|array $auth_callback Deprecated. Use `$args` instead. + * @param string|array $deprecated Deprecated. Use `$args` instead. * * @return bool True if the meta key was successfully registered in the global array, false if not. * Registering a meta key with distinct sanitize and auth callbacks will fire those * callbacks, but will not add to the global registry as it requires a subtype. */ -function register_meta( $object_type, $meta_key, $args, $auth_callback = null ) { +function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { global $wp_meta_keys; if ( ! is_array( $wp_meta_keys ) ) { @@ -1030,20 +1028,21 @@ function register_meta( $object_type, $meta_key, $args, $auth_callback = null ) 'show_in_rest' => false, ); - $passed_args = array_slice( func_get_args(), 2 ); - // There used to be individual args for sanitize and auth callbacks $has_old_sanitize_cb = false; - if ( is_callable( $passed_args[0] ) ) { - $args['sanitize_callback'] = $passed_args[0]; + if ( is_callable( $args ) ) { + $args = array( + 'sanitize_callback' => $args, + ); + $has_old_sanitize_cb = true; } else { - $args = $passed_args[0]; + $args = (array) $args; } - if ( isset( $passed_args[1] ) && is_callable( $passed_args[1] ) ) { - $args['auth_callback'] = $passed_args[1]; + if ( is_callable( $deprecated ) ) { + $args['auth_callback'] = $deprecated; } $args = wp_parse_args( $args, $defaults );