mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
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
This commit is contained in:
parent
d5e14166f3
commit
da40e89d06
@ -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 );
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user