Ticket #12706: 12706.3.diff

File 12706.3.diff, 9.6 KB (added by kovshenin, 4 months ago)
  • wp-includes/post.php

     
    111111                'public'      => true, 
    112112                '_builtin'    => true, /* internal use only. */ 
    113113                'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ), 
     114                'priority'    => 20, 
     115                'show_in_admin_status_dropdown' => true, 
     116                'capabilities' => array( 'transition_post' => 'publish_post' ), 
    114117        ) ); 
    115118 
    116119        register_post_status( 'future', array( 
     
    125128                'protected'   => true, 
    126129                '_builtin'    => true, /* internal use only. */ 
    127130                'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), 
     131                'priority'    => 5, 
     132                'show_in_admin_status_dropdown' => true, 
    128133        ) ); 
    129134 
    130135        register_post_status( 'pending', array( 
     
    132137                'protected'   => true, 
    133138                '_builtin'    => true, /* internal use only. */ 
    134139                'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), 
     140                'priority'    => 15, 
     141                'show_in_admin_status_dropdown' => true, 
    135142        ) ); 
    136143 
    137144        register_post_status( 'private', array( 
     
    673680} 
    674681 
    675682/** 
     683 * WordPress Post Status class. 
     684 * 
     685 * @since 3.6.0 
     686 * 
     687 */ 
     688final 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/** 
    676835 * Retrieve ancestors of a post. 
    677836 * 
    678837 * @since 2.5.0 
     
    9201079 * @param array|string $args See above description. 
    9211080 */ 
    9221081function register_post_status($post_status, $args = array()) { 
    923         global $wp_post_statuses; 
     1082        global $wp_post_statuses, $wp_post_types; 
    9241083 
    9251084        if (!is_array($wp_post_statuses)) 
    9261085                $wp_post_statuses = array(); 
    9271086 
    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; 
    9441089 
    945         $post_status = sanitize_key($post_status); 
    946         $args->name = $post_status; 
     1090        // Add status to already registered post types 
     1091        if ( ! empty( $wp_post_types ) ) 
     1092                foreach ( $wp_post_types as $key => $post_type ) 
     1093                        if ( ! array_key_exists( $post_status, $post_type->statuses ) ) 
     1094                                $wp_post_types[ $key ]->statuses[ $post_status ] = $args; 
    9471095 
    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  
    9831096        return $args; 
    9841097} 
    9851098 
     
    9961109 * @param string $post_status The name of a registered post status 
    9971110 * @return object A post status object 
    9981111 */ 
    999 function get_post_status_object( $post_status ) { 
     1112function get_post_status_object( $post_status, $object_type = null ) { 
    10001113        global $wp_post_statuses; 
    10011114 
    1002         if ( empty($wp_post_statuses[$post_status]) ) 
    1003                 return null; 
     1115        $status_object = null; 
    10041116 
    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; 
    10061135} 
    10071136 
    10081137/** 
     
    10261155 
    10271156        $field = ('names' == $output) ? 'name' : false; 
    10281157 
    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 ); 
    10301169} 
    10311170 
    10321171/** 
     1172 * Sort an array of posts statuses by priority. 
     1173 */ 
     1174function _sort_post_statuses( $a, $b ) { 
     1175        if ( $a->priority == $b->priority ) 
     1176                return 0; 
     1177 
     1178        return ( $a->priority < $b->priority ) ? -1 : 1; 
     1179} 
     1180 
     1181/** 
    10331182 * Whether the post type is hierarchical. 
    10341183 * 
    10351184 * A false return value might also mean that the post type does not exist. 
     
    12111360 * @return object|WP_Error the registered post type object, or an error object 
    12121361 */ 
    12131362function register_post_type( $post_type, $args = array() ) { 
    1214         global $wp_post_types, $wp_rewrite, $wp; 
     1363        global $wp_post_types, $wp_rewrite, $wp, $wp_post_statuses; 
    12151364 
    12161365        if ( !is_array($wp_post_types) ) 
    12171366                $wp_post_types = array(); 
     
    12271376                'can_export' => true, 
    12281377                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 
    12291378                'delete_with_user' => null, 
     1379                'statuses' => null, 
    12301380        ); 
    12311381        $args = wp_parse_args($args, $defaults); 
    12321382        $args = (object) $args; 
     
    13361486        if ( $args->register_meta_box_cb ) 
    13371487                add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); 
    13381488 
     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 
    13391501        $args->labels = get_post_type_labels( $args ); 
    13401502        $args->label = $args->labels->name; 
    13411503 
  • wp-includes/capabilities.php

     
    11551155 
    11561156                $caps[] = $post_type->cap->publish_posts; 
    11571157                break; 
     1158        case 'transition_post': 
     1159                $post = get_post( $args[0] ); 
     1160                $post_status = get_post_status_object( $args[1], $post->post_type ); 
     1161                $caps = map_meta_cap( $post_status->capabilities->transition_post, $user_id, $post->ID, $args[1] ); 
     1162                break; 
    11581163        case 'edit_post_meta': 
    11591164        case 'delete_post_meta': 
    11601165        case 'add_post_meta':