WordPress.org

Make WordPress Core

Ticket #36514: 36514-2.diff

File 36514-2.diff, 3.2 KB (added by stephenharris, 3 years ago)
  • src/wp-admin/includes/post.php

    diff --git src/wp-admin/includes/post.php src/wp-admin/includes/post.php
    index 757a160..d3f7d0f 100644
    function edit_post( $post_data = null ) { 
    326326        // Convert taxonomy input to term IDs, to avoid ambiguity.
    327327        if ( isset( $post_data['tax_input'] ) ) {
    328328                foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) {
    329                         // Hierarchical taxonomy data is already sent as term IDs, so no conversion is necessary.
    330                         if ( is_taxonomy_hierarchical( $taxonomy ) ) {
     329                        // If 'tax_input' already contains term IDs, there's no conversion to perform.
     330                        $tax_object = get_taxonomy( $taxonomy );
     331                        if ( $tax_object && $tax_object->meta_box_expect_ids ) {
     332                                $post_data['tax_input'][ $taxonomy ] = array_map( 'intval', $terms );
    331333                                continue;
    332334                        }
    333335
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index a51658f..edffa34 100644
    function is_taxonomy_hierarchical($taxonomy) { 
    276276 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
    277277 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
    278278 * @since 4.5.0 Introduced `publicly_queryable` argument.
     279 * @since 4.6.0 Introduced `meta_box_expect_ids` argument.
    279280 *
    280281 * @global array $wp_taxonomies Registered taxonomies.
    281282 * @global WP    $wp            WP instance.
    function is_taxonomy_hierarchical($taxonomy) { 
    318319 *                                                post_categories_meta_box() is used for hierarchical taxonomies, and
    319320 *                                                post_tags_meta_box() is used for non-hierarchical. If false, no meta
    320321 *                                                box is shown.
     322 *     @type bool          $meta_box_expect_ids   Whether the save routine should expect term IDs to be set as the
     323 *                                                'tax_input' field from the meta box form. If false, 'tax_input' will
     324 *                                                be converted to term IDs (via get_term_by() lookups) in edit_post().
     325 *                                                Defaults to true if `$meta_box_cb` is 'post_categories_meta_box'.
    321326 *     @type array         $capabilities {
    322327 *         Array of capabilities for this taxonomy.
    323328 *
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    380385                'show_in_quick_edit'    => null,
    381386                'show_admin_column'     => false,
    382387                'meta_box_cb'           => null,
     388                'meta_box_expect_ids'   => null,
    383389                'capabilities'          => array(),
    384390                'rewrite'               => true,
    385391                'query_var'             => $taxonomy,
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    473479                        $args['meta_box_cb'] = 'post_tags_meta_box';
    474480        }
    475481
     482        // Assume that the meta box tax_input field will provide term IDs if using the Categories meta box.
     483        if ( null === $args['meta_box_expect_ids'] ) {
     484                $args['meta_box_expect_ids'] = 'post_categories_meta_box' === $args['meta_box_cb'];
     485        }
     486
    476487        $wp_taxonomies[ $taxonomy ] = (object) $args;
    477488
    478489        // register callback handling for metabox