From da40e89d06299b70d9c65b55d56c9a3e2f140b29 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Wed, 13 Jul 2016 04:46:28 +0000 Subject: [PATCH] Meta: Ensure filters are backwards compatible for pre-4.6 style meta registration. When using `register_meta()` with the function signature from 4.5 and earlier, the `auth_{$type}_meta_{$key}` and `sanitize_{$type}_meta_{$key}` filters are used. Any calls to `register_meta()` expecting this behavior should continue to work. The new filters, which take advantage of object subtypes, should not be added unless the proper `$args` array is passed. See #35658. Built from https://develop.svn.wordpress.org/trunk@38041 git-svn-id: http://core.svn.wordpress.org/trunk@37982 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 15 +++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index e341bd2bcc..ff32086725 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -1032,6 +1032,7 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { // There used to be individual args for sanitize and auth callbacks $has_old_sanitize_cb = false; + $has_old_auth_cb = false; if ( is_callable( $args ) ) { $args = array( @@ -1045,6 +1046,7 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { if ( is_callable( $deprecated ) ) { $args['auth_callback'] = $deprecated; + $has_old_auth_cb = true; } $args = wp_parse_args( $args, $defaults ); @@ -1062,7 +1064,7 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { $args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key ); // Object subtype is required if using the args style of registration - if ( ! $has_old_sanitize_cb && empty( $args['object_subtype'] ) ) { + if ( ! $has_old_sanitize_cb && ! $has_old_auth_cb && empty( $args['object_subtype'] ) ) { return new WP_Error( 'register_meta_failed', __( 'Meta must be registered against an object subtype.' ) ); } @@ -1081,11 +1083,16 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { $object_subtype = $args['object_subtype']; } - // Back-compat: old sanitize and auth callbacks applied to all of an object type - if ( $has_old_sanitize_cb ) { + // Back-compat: old sanitize and auth callbacks are applied to all of an object type. + if ( $has_old_sanitize_cb && is_callable( $args['sanitize_callback'] ) ) { add_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'], 10, 4 ); + } + + if ( $has_old_auth_cb && is_callable( $args['auth_callback'] ) ) { add_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'], 10, 6 ); - } else { + } + + if ( ! $has_old_auth_cb && ! $has_old_sanitize_cb) { if ( is_callable( $args['sanitize_callback'] ) ) { add_filter( "sanitize_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['sanitize_callback'], 10, 4 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 64bf163f19..67fb0d52ee 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta2-38040'; +$wp_version = '4.6-beta2-38041'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.