Ticket #31154: 31154.patch
File 31154.patch, 2.4 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
1342 1342 $post_type = sanitize_key( $post_type ); 1343 1343 $args->name = $post_type; 1344 1344 1345 $reserved_post_types = array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' ); 1346 if ( in_array( $post_type, $reserved_post_types ) && !$args->_builtin ) { 1347 _doing_it_wrong( __FUNCTION__, __( 'Reserved post types cannot be registered as non-built-in ones.' ), '4.2' ); 1348 return new WP_Error( 'reserved_post_type_non_built_in', __( 'Reserved post types cannot be registered as non-built-in ones.' ) ); 1349 } 1350 1351 $disallowed_post_types = array( 'action', 'order', 'theme' ); 1352 if ( in_array( $post_type, $disallowed_post_types ) ) { 1353 _doing_it_wrong( __FUNCTION__, __( 'Disallowed post types cannot be registered.' ), '4.2' ); 1354 return new WP_Error( 'post_type_disallowed', __( 'Disallowed post type cannot be registered.' ) ); 1355 } 1356 1345 1357 if ( strlen( $post_type ) > 20 ) { 1346 1358 _doing_it_wrong( __FUNCTION__, __( 'Post types cannot exceed 20 characters in length' ), '4.0' ); 1347 1359 return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) ); -
tests/phpunit/tests/post/types.php
81 81 update_option( 'permalink_structure', $old_permastruct ); 82 82 _unregister_post_type( 'foo' ); 83 83 } 84 85 /** 86 * @ticket 31154 87 * 88 * @expectedIncorrectUsage register_post_type 89 */ 90 function test_register_post_type_reserved() { 91 $result = register_post_type( 'post' ); 92 $this->assertInstanceOf( 'WP_Error', $result ); 93 94 $result = register_post_type( 'post', array( '_builtin' => true ) ); 95 $this->assertTrue( post_type_exists( 'post' ) ); 96 $this->assertInstanceOf( 'stdClass', $result ); 97 } 98 99 /** 100 * @ticket 31154 101 * 102 * @expectedIncorrectUsage register_post_type 103 */ 104 function test_register_post_type_disallowed() { 105 $result = register_post_type( 'action' ); 106 $this->assertInstanceOf( 'WP_Error', $result ); 107 108 $result = register_post_type( 'action', array( '_builtin' => true ) ); 109 $this->assertInstanceOf( 'WP_Error', $result ); 110 } 84 111 }