WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/21/2017 03:14:52 AM (6 months ago)
Author:
boonebgorges
Message:

Introduce meta_box_sanitize_cb taxonomy argument.

The meta_box_cb argument was introduced in [25572] to allow plugin
authors to provide a custom callback for rendering their taxonomy's meta
box on the post edit screen. However, the routine used to handle the saving
of these custom taxonomy meta boxes was not customizable, but was instead
based simply on whether the taxonomy was hierarchicaly. See [13535].

The new meta_box_sanitize_cb argument defaults to the "tag" routine for
non-hierarchical taxonomies and the "category" routine for hierarchical ones,
thereby maintaining the current default behavior. Developers can override this
when the data passed from their meta_box_cb differs.

Props boonebgorges, ZaneMatthew, stephenharris.
Fixes #36514.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-taxonomy.php

    r41162 r42211  
    127127     */
    128128    public $meta_box_cb = null;
     129
     130    /**
     131     * The callback function for sanitizing taxonomy data saved from a meta box.
     132     *
     133     * @since 5.0.0
     134     * @access public
     135     * @var callable
     136     */
     137    public $meta_box_sanitize_cb = null;
    129138
    130139    /**
     
    258267            'show_admin_column'     => false,
    259268            'meta_box_cb'           => null,
     269            'meta_box_sanitize_cb'  => null,
    260270            'capabilities'          => array(),
    261271            'rewrite'               => true,
     
    346356        $args['name'] = $this->name;
    347357
     358        // Default meta box sanitization callback depends on the value of 'meta_box_cb'.
     359        if ( null === $args['meta_box_sanitize_cb'] ) {
     360            switch ( $args['meta_box_cb'] ) {
     361                case 'post_categories_meta_box' :
     362                    $args['meta_box_sanitize_cb'] = 'taxonomy_meta_box_sanitize_cb_checkboxes';
     363                break;
     364
     365                case 'post_tags_meta_box' :
     366                default :
     367                    $args['meta_box_sanitize_cb'] = 'taxonomy_meta_box_sanitize_cb_input';
     368                break;
     369            }
     370        }
     371
    348372        foreach ( $args as $property_name => $property_value ) {
    349373            $this->$property_name = $property_value;
Note: See TracChangeset for help on using the changeset viewer.