Ticket #49644: 49644-1.patch
File 49644-1.patch, 8.5 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
345 345 */ 346 346 public $rest_controller; 347 347 348 /** 349 * Set to a WP_Error when an inspected error occurs within the class. 350 * 351 * Currently this is only used by __construct() and unregister(). 352 * 353 * @since 5.4.0 354 * @var WP_Error|null $last_error 355 */ 356 public $last_error = null; 357 348 358 /** 349 359 * Constructor. 350 360 * … … 360 370 * Default empty array. 361 371 */ 362 372 public function __construct( $post_type, $args = array() ) { 373 // Sanitize post type name 374 $post_type = sanitize_key( $post_type ); 375 376 if ( empty( $post_type ) || strlen( $post_type ) > 20 ) { 377 _doing_it_wrong( __METHOD__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' ); 378 $this->last_error = new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) ); 379 } 380 363 381 $this->name = $post_type; 364 382 365 383 $this->set_props( $args ); … … 375 393 public function set_props( $args ) { 376 394 $args = wp_parse_args( $args ); 377 395 396 $this->last_error = null; 397 378 398 /** 379 399 * Filters the arguments for registering a post type. 380 400 * … … 514 534 515 535 $this->labels = get_post_type_labels( $this ); 516 536 $this->label = $this->labels->name; 537 517 538 } 518 539 519 540 /** … … 522 543 * @since 4.6.0 523 544 */ 524 545 public function add_supports() { 546 $this->last_error = null; 525 547 if ( ! empty( $this->supports ) ) { 526 548 foreach ( $this->supports as $feature => $args ) { 527 549 if ( is_array( $args ) ) { … … 548 570 public function add_rewrite_rules() { 549 571 global $wp_rewrite, $wp; 550 572 573 $this->last_error = null; 574 551 575 if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) { 552 576 $wp->add_query_var( $this->query_var ); 553 577 } … … 593 617 if ( $this->register_meta_box_cb ) { 594 618 add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 ); 595 619 } 620 $this->last_error = null; 596 621 } 597 622 598 623 /** … … 602 627 */ 603 628 public function add_hooks() { 604 629 add_action( 'future_' . $this->name, '_future_post_hook', 5, 2 ); 630 $this->last_error = null; 605 631 } 606 632 607 633 /** … … 613 639 foreach ( $this->taxonomies as $taxonomy ) { 614 640 register_taxonomy_for_object_type( $taxonomy, $this->name ); 615 641 } 642 $this->last_error = null; 616 643 } 617 644 618 645 /** … … 626 653 global $_wp_post_type_features; 627 654 628 655 unset( $_wp_post_type_features[ $this->name ] ); 656 657 $this->last_error = null; 629 658 } 630 659 631 660 /** … … 640 669 public function remove_rewrite_rules() { 641 670 global $wp, $wp_rewrite, $post_type_meta_caps; 642 671 672 $this->last_error = null; 673 643 674 // Remove query var. 644 675 if ( false !== $this->query_var ) { 645 676 $wp->remove_query_var( $this->query_var ); … … 668 699 * @since 4.6.0 669 700 */ 670 701 public function unregister_meta_boxes() { 702 $this->last_error = null; 671 703 if ( $this->register_meta_box_cb ) { 672 704 remove_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10 ); 673 705 } … … 679 711 * @since 4.6.0 680 712 */ 681 713 public function unregister_taxonomies() { 714 $this->last_error = null; 682 715 foreach ( get_object_taxonomies( $this->name ) as $taxonomy ) { 683 716 unregister_taxonomy_for_object_type( $taxonomy, $this->name ); 684 717 } … … 690 723 * @since 4.6.0 691 724 */ 692 725 public function remove_hooks() { 726 $this->last_error = null; 693 727 remove_action( 'future_' . $this->name, '_future_post_hook', 5 ); 694 728 } 695 729 … … 704 738 * is set not to show in rest. 705 739 */ 706 740 public function get_rest_controller() { 741 742 $this->last_error = null; 743 707 744 if ( ! $this->show_in_rest ) { 708 745 return null; 709 746 } … … 727 764 } 728 765 729 766 return $this->rest_controller; 767 730 768 } 769 770 /** 771 * Registers this post type. 772 * 773 * @since 5.4.0 774 */ 775 public function register() { 776 global $wp_post_types; 777 778 $this->last_error = null; 779 780 if ( ! is_array( $wp_post_types ) ) { 781 $wp_post_types = array(); 782 } 783 784 $this->add_supports(); 785 $this->add_rewrite_rules(); 786 $this->register_meta_boxes(); 787 788 $wp_post_types[ $this->name ] = $this; 789 790 $this->add_hooks(); 791 $this->register_taxonomies(); 792 793 /** 794 * Fires after a post type is registered. 795 * 796 * @since 3.3.0 797 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. 798 * 799 * @param string $post_type Post type. 800 * @param WP_Post_Type $post_type_object Arguments used to register the post type. 801 */ 802 do_action( 'registered_post_type', $this->name, $this ); 803 } 804 805 /** 806 * Unregisters this post type. 807 * 808 * @since 5.4.0 809 * 810 * @return bool Returns true if unregistered, false if a _builtin post type. 811 */ 812 public function unregister() { 813 global $wp_post_types; 814 815 // Do not allow unregistering internal post types. 816 if ( $this->_builtin ) { 817 $this->last_error = new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); 818 return false; 819 } 820 821 $this->last_error = null; 822 823 if ( $removed = post_type_exists( $this->name ) ) { 824 $this->remove_supports(); 825 $this->remove_rewrite_rules(); 826 $this->unregister_meta_boxes(); 827 $this->remove_hooks(); 828 $this->unregister_taxonomies(); 829 unset( $wp_post_types[ $this->name ] ); 830 } 831 832 /** 833 * Fires after a post type was unregistered. 834 * 835 * @since 4.5.0 836 * 837 * @param string $post_type Post type key. 838 * @param WP_Post_Type $post_type_object Arguments used to register the post type. 839 * @param bool $removed True if the post type 'existed' and was removed, false otherwise 840 */ 841 do_action( 'unregistered_post_type', $this->name, $this, $removed ); 842 843 return true; 844 845 } 846 731 847 } -
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 /**