Taxonomy: In register_taxonomy(), return the registered taxonomy object on success, for consistency with register_post_type().

Props krynes, SergeyBiryukov.
Fixes #48558.

git-svn-id: https://develop.svn.wordpress.org/trunk@47186 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-02-05 06:24:16 +00:00
parent 6c00abab9e
commit e4d8eac50f
3 changed files with 17 additions and 1 deletions

View File

@ -408,7 +408,7 @@ function is_taxonomy_hierarchical( $taxonomy ) {
* @type bool $_builtin This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
* Default false.
* }
* @return void|WP_Error Void on success, WP_Error object on failure.
* @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
*/
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
global $wp_taxonomies;
@ -441,6 +441,8 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
* @param array $args Array of taxonomy registration arguments.
*/
do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );
return $taxonomy_object;
}
/**

View File

@ -39,6 +39,13 @@ class Tests_Post_Types extends WP_UnitTestCase {
_unregister_post_type( 'foo' );
}
/**
* @ticket 48558
*/
function test_register_post_type_return_value() {
$this->assertInstanceOf( 'WP_Post_Type', register_post_type( 'foo' ) );
}
/**
* @ticket 31134
*

View File

@ -169,6 +169,13 @@ class Tests_Taxonomy extends WP_UnitTestCase {
unset( $GLOBALS['wp_taxonomies'][ $tax ] );
}
/**
* @ticket 48558
*/
function test_register_taxonomy_return_value() {
$this->assertInstanceOf( 'WP_Taxonomy', register_taxonomy( 'foo', 'post' ) );
}
/**
* @ticket 21593
*