WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/21/17 03:14:52 (2 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/tests/phpunit/tests/taxonomy.php

    r41174 r42211  
    792792        $this->assertSame( 'foo', $taxonomy->name ); 
    793793    } 
     794 
     795    /** 
     796     * @ticket 36514 
     797     */ 
     798    public function test_edit_post_hierarchical_taxonomy() { 
     799 
     800        $taxonomy_name = 'foo'; 
     801        $term_name     = 'bar'; 
     802 
     803        register_taxonomy( $taxonomy_name, array( 'post' ), array( 
     804            'hierarchical' => false, 
     805            'meta_box_cb'  => 'post_categories_meta_box', 
     806        ) ); 
     807        $post = self::factory()->post->create_and_get( array( 
     808            'post_type' => 'post', 
     809        ) ); 
     810 
     811        $term_id  = self::factory()->term->create_object( array( 
     812            'name'     => $term_name, 
     813            'taxonomy' => $taxonomy_name, 
     814        ) ); 
     815 
     816        wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); 
     817        $updated_post_id = edit_post( array( 
     818            'post_ID'   => $post->ID, 
     819            'post_type' => 'post', 
     820            'tax_input' => array( 
     821                $taxonomy_name => array( 
     822                    (string) $term_id // Cast term_id as string to match whats sent in WP Admin. 
     823                ), 
     824            ), 
     825        ) ); 
     826 
     827        $terms_obj = get_the_terms( $updated_post_id, $taxonomy_name ); 
     828        $problematic_term = current( wp_list_pluck( $terms_obj, 'name' ) ); 
     829 
     830        $this->assertEquals( $problematic_term, $term_name ); 
     831    } 
    794832} 
Note: See TracChangeset for help on using the changeset viewer.