Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Add support for registering customize post meta via register_meta() #232

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

westonruter
Copy link
Contributor

  • Allow meta to be registered for the customizer via register_meta()
  • Throw a doing_it_wrong if auth_callback is passed among the customize_setting_args.
  • Throw a doing_it_wrong if register_meta() was not called with a sanitize_callback.

Example of registering new postmeta along with customizer support. First, given that the post type support has been assigned to the appropriate post types, for example:

add_action( 'init', function() {
    add_post_type_support( 'post', 'greeting' );
}, 1 );

Current (old) way to register postmeta in the customizer:

register_meta( 'post', 'greeting', 'wp_kses_post' );

add_action( 'customize_posts_register_meta', function( WP_Customize_Posts $customize_posts ) {
    foreach ( get_post_types_by_support( 'greeting' ) as $post_type ) {
        $customize_posts->register_post_type_meta( $post_type, 'greeting', array(
            'post_type_supports' => 'greeting',
            'transport' => 'postMessage',
        ) );
    }
} );

New experimental unified way to register postmeta:

register_meta( 'post', 'greeting', array(
    'sanitize_callback' => 'wp_kses_post',

    // Additional props not possible before.
    'type' => 'string',
    'description' => __( 'Greeting', 'my-plugin' ),
    'single' => true,
    'show_in_rest' => true,

    // Extensions to register_meta().
    'show_in_customizer' => true,
    'post_type_supports' => 'greeting',
    'customize_setting_args' => array(
        'transport' => 'postMessage',
    ),
) );

Fixes #192

@westonruter westonruter modified the milestone: 0.8 Aug 29, 2016
@westonruter westonruter added this to the 1.0.0 milestone Sep 1, 2016
@westonruter
Copy link
Contributor Author

Moving this to future release because I don't want to prematurely modify how register_meta is interacted with.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant