Return a WP_Error
if an empty name is provided when registering a post type.
Fixes #31134 Props tyxla, MikeHansenMe git-svn-id: https://develop.svn.wordpress.org/trunk@31450 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
22fc19e06d
commit
f4d6d4e66b
@ -1342,9 +1342,9 @@ function register_post_type( $post_type, $args = array() ) {
|
||||
$post_type = sanitize_key( $post_type );
|
||||
$args->name = $post_type;
|
||||
|
||||
if ( strlen( $post_type ) > 20 ) {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'Post types cannot exceed 20 characters in length' ), '4.0' );
|
||||
return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) );
|
||||
if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2' );
|
||||
return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) );
|
||||
}
|
||||
|
||||
// If not set, default to the setting for public.
|
||||
|
@ -19,6 +19,26 @@ class Tests_Post_Types extends WP_UnitTestCase {
|
||||
_unregister_post_type( 'foo' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31134
|
||||
*
|
||||
* @expectedIncorrectUsage register_post_type
|
||||
*/
|
||||
function test_register_post_type_length_long() {
|
||||
// post type too long
|
||||
$this->assertInstanceOf( 'WP_Error', register_post_type( 'abcdefghijklmnopqrstuvwxyz0123456789' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31134
|
||||
*
|
||||
* @expectedIncorrectUsage register_post_type
|
||||
*/
|
||||
function test_register_post_type_length_short() {
|
||||
// post type too short
|
||||
$this->assertInstanceOf( 'WP_Error', register_post_type( '' ) );
|
||||
}
|
||||
|
||||
function test_register_taxonomy_for_object_type() {
|
||||
global $wp_taxonomies;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user