Ticket #49644: 49644.patch
File 49644.patch, 5.1 KB (added by , 5 years ago) |
---|
-
www/wp-includes/class-wp-post-type.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
360 360 * Default empty array. 361 361 */ 362 362 public function __construct( $post_type, $args = array() ) { 363 // Sanitize post type name 364 $post_type = sanitize_key( $post_type ); 365 366 if ( empty( $post_type ) || strlen( $post_type ) > 20 ) { 367 _doing_it_wrong( __METHOD__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' ); 368 return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) ); 369 } 370 363 371 $this->name = $post_type; 364 372 365 373 $this->set_props( $args ); … … 728 736 729 737 return $this->rest_controller; 730 738 } 739 740 public function unregister() { 741 global $wp_post_types; 742 743 // Do not allow unregistering internal post types. 744 if ( $this->_builtin ) { 745 return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); 746 } 747 748 if ( $removed = post_type_exists( $this->name ) ) { 749 $this->remove_supports(); 750 $this->remove_rewrite_rules(); 751 $this->unregister_meta_boxes(); 752 $this->remove_hooks(); 753 $this->unregister_taxonomies(); 754 unset( $wp_post_types[ $this->name ] ); 755 } 756 757 /** 758 * Fires after a post type was unregistered. 759 * 760 * @since 4.5.0 761 * 762 * @param string $post_type Post type key. 763 * @param bool $removed True if the post type 'existed' and was removed, false otherwise 764 */ 765 do_action( 'unregistered_post_type', $this->name, $removed ); 766 767 return true; 768 769 } 770 771 public function register() { 772 global $wp_post_types; 773 774 if ( ! is_array( $wp_post_types ) ) { 775 $wp_post_types = array(); 776 } 777 778 $this->add_supports(); 779 $this->add_rewrite_rules(); 780 $this->register_meta_boxes(); 781 782 $wp_post_types[ $this->name ] = $this; 783 784 $this->add_hooks(); 785 $this->register_taxonomies(); 786 787 /** 788 * Fires after a post type is registered. 789 * 790 * @since 3.3.0 791 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. 792 * 793 * @param string $post_type Post type. 794 * @param WP_Post_Type $post_type_object Arguments used to register the post type. 795 */ 796 do_action( 'registered_post_type', $this->name, $this ); 797 798 return $this; 799 } 800 731 801 } -
www/wp-includes/post.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
1403 1403 * @return WP_Post_Type|WP_Error The registered post type object, or an error object. 1404 1404 */ 1405 1405 function register_post_type( $post_type, $args = array() ) { 1406 global $wp_post_types;1407 1408 if ( ! is_array( $wp_post_types ) ) {1409 $wp_post_types = array();1410 }1411 1412 // Sanitize post type name1413 $post_type = sanitize_key( $post_type );1414 1415 if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {1416 _doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' );1417 return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) );1418 }1419 1420 1406 $post_type_object = new WP_Post_Type( $post_type, $args ); 1421 $post_type_object->add_supports(); 1422 $post_type_object->add_rewrite_rules(); 1423 $post_type_object->register_meta_boxes(); 1424 1425 $wp_post_types[ $post_type ] = $post_type_object; 1426 1427 $post_type_object->add_hooks(); 1428 $post_type_object->register_taxonomies(); 1429 1430 /** 1431 * Fires after a post type is registered. 1432 * 1433 * @since 3.3.0 1434 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. 1435 * 1436 * @param string $post_type Post type. 1437 * @param WP_Post_Type $post_type_object Arguments used to register the post type. 1438 */ 1439 do_action( 'registered_post_type', $post_type, $post_type_object ); 1440 1441 return $post_type_object; 1407 return $post_type_object->register(); 1442 1408 } 1443 1409 1444 1410 /** … … 1460 1426 return new WP_Error( 'invalid_post_type', __( 'Invalid post type.' ) ); 1461 1427 } 1462 1428 1463 $post_type_object = get_post_type_object( $post_type ); 1464 1465 // Do not allow unregistering internal post types. 1466 if ( $post_type_object->_builtin ) { 1467 return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); 1468 } 1469 1470 $post_type_object->remove_supports(); 1471 $post_type_object->remove_rewrite_rules(); 1472 $post_type_object->unregister_meta_boxes(); 1473 $post_type_object->remove_hooks(); 1474 $post_type_object->unregister_taxonomies(); 1475 1476 unset( $wp_post_types[ $post_type ] ); 1477 1478 /** 1479 * Fires after a post type was unregistered. 1480 * 1481 * @since 4.5.0 1482 * 1483 * @param string $post_type Post type key. 1484 */ 1485 do_action( 'unregistered_post_type', $post_type ); 1486 1487 return true; 1429 return get_post_type_object( $post_type )->unregister(); 1488 1430 } 1489 1431 1490 1432 /**