| 683 | * WordPress Post Status class. |
| 684 | * |
| 685 | * @since 3.6.0 |
| 686 | * |
| 687 | */ |
| 688 | final class WP_Post_Status { |
| 689 | |
| 690 | /** |
| 691 | * |
| 692 | * @var string |
| 693 | */ |
| 694 | public $name = ''; |
| 695 | |
| 696 | /** |
| 697 | * |
| 698 | * @var string |
| 699 | */ |
| 700 | public $label = false; |
| 701 | |
| 702 | /** |
| 703 | * |
| 704 | * @var array |
| 705 | */ |
| 706 | public $label_count = false; |
| 707 | |
| 708 | /** |
| 709 | * |
| 710 | * @var labels |
| 711 | */ |
| 712 | public $labels = null; |
| 713 | |
| 714 | /** |
| 715 | * |
| 716 | * @var bool |
| 717 | */ |
| 718 | public $exclude_from_search = null; |
| 719 | |
| 720 | /** |
| 721 | * |
| 722 | * @var bool |
| 723 | */ |
| 724 | public $_builtin = false; |
| 725 | |
| 726 | /** |
| 727 | * |
| 728 | * @var bool |
| 729 | */ |
| 730 | public $public = null; |
| 731 | |
| 732 | /** |
| 733 | * |
| 734 | * @var bool |
| 735 | */ |
| 736 | public $internal = null; |
| 737 | |
| 738 | /** |
| 739 | * |
| 740 | * @var bool |
| 741 | */ |
| 742 | public $protected = null; |
| 743 | |
| 744 | /** |
| 745 | * |
| 746 | * @var bool |
| 747 | */ |
| 748 | public $private = null; |
| 749 | |
| 750 | /** |
| 751 | * |
| 752 | * @var bool |
| 753 | */ |
| 754 | public $publicly_queryable = null; |
| 755 | |
| 756 | /** |
| 757 | * |
| 758 | * @var bool |
| 759 | */ |
| 760 | public $show_in_admin_status_list = null; |
| 761 | |
| 762 | /** |
| 763 | * |
| 764 | * @var bool |
| 765 | */ |
| 766 | public $show_in_admin_all_list = null; |
| 767 | |
| 768 | /** |
| 769 | * |
| 770 | * @var bool |
| 771 | */ |
| 772 | public $show_in_admin_status_dropdown = false; |
| 773 | |
| 774 | /** |
| 775 | * |
| 776 | * @var int |
| 777 | */ |
| 778 | public $priority = 10; |
| 779 | |
| 780 | /** |
| 781 | * |
| 782 | * @var object |
| 783 | */ |
| 784 | public $capabilities = null; |
| 785 | |
| 786 | public function __construct( $post_status, $args = array() ) { |
| 787 | |
| 788 | $args = (object) $args; |
| 789 | foreach ( get_object_vars( $args ) as $key => $value ) |
| 790 | $this->$key = $value; |
| 791 | |
| 792 | $this->name = sanitize_key( $post_status ); |
| 793 | |
| 794 | if ( null === $this->public && null === $this->internal && null === $this->protected && null === $this->private ) |
| 795 | $this->internal = true; |
| 796 | |
| 797 | if ( null === $this->public ) |
| 798 | $this->public = false; |
| 799 | |
| 800 | if ( null === $this->private ) |
| 801 | $this->private = false; |
| 802 | |
| 803 | if ( null === $this->protected ) |
| 804 | $this->protected = false; |
| 805 | |
| 806 | if ( null === $this->internal ) |
| 807 | $this->internal = false; |
| 808 | |
| 809 | if ( null === $this->publicly_queryable ) |
| 810 | $this->publicly_queryable = $this->public; |
| 811 | |
| 812 | if ( null === $this->exclude_from_search ) |
| 813 | $this->exclude_from_search = $this->internal; |
| 814 | |
| 815 | if ( null === $this->show_in_admin_all_list ) |
| 816 | $this->show_in_admin_all_list = !$this->internal; |
| 817 | |
| 818 | if ( null === $this->show_in_admin_status_list ) |
| 819 | $this->show_in_admin_status_list = !$this->internal; |
| 820 | |
| 821 | if ( false === $this->label ) |
| 822 | $this->label = $post_status; |
| 823 | |
| 824 | if ( false === $this->label_count ) |
| 825 | $this->label_count = array( $this->label, $this->label ); |
| 826 | |
| 827 | if ( null === $this->capabilities ) |
| 828 | $this->capabilities = array( 'transition_post' => 'edit_post' ); |
| 829 | |
| 830 | $this->capabilities = (object) $this->capabilities; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | /** |
928 | | // Args prefixed with an underscore are reserved for internal use. |
929 | | $defaults = array( |
930 | | 'label' => false, |
931 | | 'label_count' => false, |
932 | | 'exclude_from_search' => null, |
933 | | '_builtin' => false, |
934 | | 'public' => null, |
935 | | 'internal' => null, |
936 | | 'protected' => null, |
937 | | 'private' => null, |
938 | | 'publicly_queryable' => null, |
939 | | 'show_in_admin_status_list' => null, |
940 | | 'show_in_admin_all_list' => null, |
941 | | ); |
942 | | $args = wp_parse_args($args, $defaults); |
943 | | $args = (object) $args; |
| 1087 | $args = new WP_Post_Status( $post_status, $args ); |
| 1088 | $wp_post_statuses[ $post_status ] = $args; |
948 | | if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) |
949 | | $args->internal = true; |
950 | | |
951 | | if ( null === $args->public ) |
952 | | $args->public = false; |
953 | | |
954 | | if ( null === $args->private ) |
955 | | $args->private = false; |
956 | | |
957 | | if ( null === $args->protected ) |
958 | | $args->protected = false; |
959 | | |
960 | | if ( null === $args->internal ) |
961 | | $args->internal = false; |
962 | | |
963 | | if ( null === $args->publicly_queryable ) |
964 | | $args->publicly_queryable = $args->public; |
965 | | |
966 | | if ( null === $args->exclude_from_search ) |
967 | | $args->exclude_from_search = $args->internal; |
968 | | |
969 | | if ( null === $args->show_in_admin_all_list ) |
970 | | $args->show_in_admin_all_list = !$args->internal; |
971 | | |
972 | | if ( null === $args->show_in_admin_status_list ) |
973 | | $args->show_in_admin_status_list = !$args->internal; |
974 | | |
975 | | if ( false === $args->label ) |
976 | | $args->label = $post_status; |
977 | | |
978 | | if ( false === $args->label_count ) |
979 | | $args->label_count = array( $args->label, $args->label ); |
980 | | |
981 | | $wp_post_statuses[$post_status] = $args; |
982 | | |
1005 | | return $wp_post_statuses[$post_status]; |
| 1117 | if ( $object_type ) { |
| 1118 | $post_type = get_post_type_object( $object_type ); |
| 1119 | if ( $post_type && ! empty( $post_type->statuses[ $post_status ] ) ) |
| 1120 | $status_object = $post_type->statuses[ $post_status ]; |
| 1121 | } |
| 1122 | |
| 1123 | if ( ! empty( $wp_post_statuses[ $post_status ] ) ) |
| 1124 | $status = $wp_post_statuses[ $post_status ]; |
| 1125 | |
| 1126 | // Search across all post types |
| 1127 | foreach ( get_post_types( array(), 'objects' ) as $post_type ) { |
| 1128 | if ( ! empty( $post_type->statuses[ $post_status ] ) ) { |
| 1129 | $status_object = $post_type->statuses[ $post_status ]; |
| 1130 | break; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | return $status_object; |
1029 | | return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); |
| 1158 | $statuses = $wp_post_statuses; |
| 1159 | |
| 1160 | if ( ! empty( $args['object_type'] ) ) { |
| 1161 | $post_type = get_post_type_object( $args['object_type'] ); |
| 1162 | if ( $post_type ) |
| 1163 | $statuses = $post_type->statuses; |
| 1164 | |
| 1165 | unset( $args['object_type'] ); |
| 1166 | } |
| 1167 | |
| 1168 | return wp_filter_object_list( $statuses, $args, $operator, $field ); |
| 1489 | if ( null === $args->statuses ) |
| 1490 | $args->statuses = array(); |
| 1491 | |
| 1492 | foreach ( $args->statuses as $post_status => $post_status_args ) |
| 1493 | $args->statuses[ $post_status ] = new WP_Post_Status( $post_status, $post_status_args ); |
| 1494 | |
| 1495 | // Legacy post statuses |
| 1496 | if ( ! empty( $wp_post_statuses ) ) |
| 1497 | foreach ( $wp_post_statuses as $key => $post_status ) |
| 1498 | if ( empty( $args->statuses[ $key ] ) ) |
| 1499 | $args->statuses[ $key ] = $post_status; |
| 1500 | |