WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 4 months ago

#46265 closed defect (bug) (duplicate)

Newly registered taxonomy adds new entries upon save

Reported by: zethodderskov Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0.3
Component: Taxonomy Keywords:
Focuses: Cc:

Description

https://cdn-std.dprcdn.net/files/acc_636823/eAR3qg

The gif above should be self-explanatory. It adds new topics (with the name of an ID or something) upon saving a post. It's a custom registerede taxonomy.

I deactivated all plugins and put these lines of code in functions.php of Twentynineteen, - and the bug is still reproducable:

/**
 * Disable regular editor
 */
function life_init_remove_support(){
	remove_post_type_support( 'page', 'editor');
	remove_post_type_support( 'post', 'editor');
}
add_action('init', 'foobar_init_remove_support', 100 );


// Register Custom Taxonomy
function foobar_learning_packages_taxonomy() {

	$topic_labels = array(
		'name'                       => _x( 'Topics', 'Taxonomy General Name', 'foobar_lang' ),
		'singular_name'              => _x( 'Topic', 'Taxonomy Singular Name', 'foobar_lang' ),
		'menu_name'                  => __( 'Topics', 'foobar_lang' ),
		'all_items'                  => __( 'All topics', 'foobar_lang' ),
		'parent_item'                => __( 'Parent topic', 'foobar_lang' ),
		'parent_item_colon'          => __( 'Parent topic:', 'foobar_lang' ),
		'new_item_name'              => __( 'New topic name', 'foobar_lang' ),
		'add_new_item'               => __( 'Add new topic', 'foobar_lang' ),
		'edit_item'                  => __( 'Edit topic', 'foobar_lang' ),
		'update_item'                => __( 'Update topic', 'foobar_lang' ),
		'view_item'                  => __( 'View topic', 'foobar_lang' ),
		'separate_items_with_commas' => __( 'Separate topics with commas', 'foobar_lang' ),
		'add_or_remove_items'        => __( 'Add or remove topics', 'foobar_lang' ),
		'choose_from_most_used'      => __( 'Choose from the most used', 'foobar_lang' ),
		'popular_items'              => __( 'Popular topics', 'foobar_lang' ),
		'search_items'               => __( 'Search topics', 'foobar_lang' ),
		'not_found'                  => __( 'Not found', 'foobar_lang' ),
		'no_terms'                   => __( 'No topics', 'foobar_lang' ),
		'items_list'                 => __( 'Topics list', 'foobar_lang' ),
		'items_list_navigation'      => __( 'Topics list navigation', 'foobar_lang' ),
	);
	$topic_rewrite = array(
		'slug'                       => 'topic',
		'with_front'                 => true,
		'hierarchical'               => false,
	);
	$topic_args = array(
		'labels'                     => $topic_labels,
		'hierarchical'               => false,
		'meta_box_cb'                => 'post_categories_meta_box',
		'public'                     => true,
		'show_ui'                    => true,
		'show_admin_column'          => true,
		'show_in_nav_menus'          => true,
		'show_tagcloud'              => false,
		'rewrite'                    => $topic_rewrite,
		'show_in_rest'               => true,
	);
	register_taxonomy( 'topic', array( 'post' ), $topic_args );


}
add_action( 'init', 'foobar_new_taxonomy', 0 );

Change History (2)

#1 @zethodderskov
4 months ago

Bah! I can see that I messed up the function-names, trying to rename them to something generic. Here are the code snippet again, with correct function-names (which is the only thing changed, compared to the original ticket-description):

function foobar_init_remove_support(){
  remove_post_type_support( 'page', 'editor');
  remove_post_type_support( 'post', 'editor');
}
add_action('init', 'foobar_init_remove_support', 100 );


// Register Custom Taxonomy
function foobar_new_taxonomy() {

  $topic_labels = array(
    'name'                       => _x( 'Topics', 'Taxonomy General Name', 'foobar_lang' ),
    'singular_name'              => _x( 'Topic', 'Taxonomy Singular Name', 'foobar_lang' ),
    'menu_name'                  => __( 'Topics', 'foobar_lang' ),
    'all_items'                  => __( 'All topics', 'foobar_lang' ),
    'parent_item'                => __( 'Parent topic', 'foobar_lang' ),
    'parent_item_colon'          => __( 'Parent topic:', 'foobar_lang' ),
    'new_item_name'              => __( 'New topic name', 'foobar_lang' ),
    'add_new_item'               => __( 'Add new topic', 'foobar_lang' ),
    'edit_item'                  => __( 'Edit topic', 'foobar_lang' ),
    'update_item'                => __( 'Update topic', 'foobar_lang' ),
    'view_item'                  => __( 'View topic', 'foobar_lang' ),
    'separate_items_with_commas' => __( 'Separate topics with commas', 'foobar_lang' ),
    'add_or_remove_items'        => __( 'Add or remove topics', 'foobar_lang' ),
    'choose_from_most_used'      => __( 'Choose from the most used', 'foobar_lang' ),
    'popular_items'              => __( 'Popular topics', 'foobar_lang' ),
    'search_items'               => __( 'Search topics', 'foobar_lang' ),
    'not_found'                  => __( 'Not found', 'foobar_lang' ),
    'no_terms'                   => __( 'No topics', 'foobar_lang' ),
    'items_list'                 => __( 'Topics list', 'foobar_lang' ),
    'items_list_navigation'      => __( 'Topics list navigation', 'foobar_lang' ),
  );
  $topic_rewrite = array(
    'slug'                       => 'topic',
    'with_front'                 => true,
    'hierarchical'               => false,
  );
  $topic_args = array(
    'labels'                     => $topic_labels,
    'hierarchical'               => false,
    'meta_box_cb'                => 'post_categories_meta_box',
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => false,
    'rewrite'                    => $topic_rewrite,
    'show_in_rest'               => true,
  );
  register_taxonomy( 'topic', array( 'post' ), $topic_args );


}
add_action( 'init', 'foobar_new_taxonomy', 0 );
Last edited 4 months ago by zethodderskov (previous) (diff)

#2 @dlh
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Hi @zethodderskov, and welcome to Trac!

The behavior you describe was a result of using the post_categories_meta_box callback with a non-hierarchical taxonomy, which was already being tracked in #36514 and #28033.

However, please take a look at the changes added to WordPress 5.1 in [42211] and the accompanying dev note to confirm that those address the issue.

Note: See TracTickets for help on using tickets.