Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php (revision 23301)
+++ wp-includes/post.php (working copy)
@@ -111,6 +111,9 @@
'public' => true,
'_builtin' => true, /* internal use only. */
'label_count' => _n_noop( 'Published (%s)', 'Published (%s)' ),
+ 'priority' => 20,
+ 'show_in_admin_status_dropdown' => true,
+ 'capabilities' => array( 'transition_post' => 'publish_post' ),
) );
register_post_status( 'future', array(
@@ -125,6 +128,8 @@
'protected' => true,
'_builtin' => true, /* internal use only. */
'label_count' => _n_noop( 'Draft (%s)', 'Drafts (%s)' ),
+ 'priority' => 5,
+ 'show_in_admin_status_dropdown' => true,
) );
register_post_status( 'pending', array(
@@ -132,6 +137,8 @@
'protected' => true,
'_builtin' => true, /* internal use only. */
'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)' ),
+ 'priority' => 15,
+ 'show_in_admin_status_dropdown' => true,
) );
register_post_status( 'private', array(
@@ -673,6 +680,158 @@
}
/**
+ * WordPress Post Status class.
+ *
+ * @since 3.6.0
+ *
+ */
+final class WP_Post_Status {
+
+ /**
+ *
+ * @var string
+ */
+ public $name = '';
+
+ /**
+ *
+ * @var string
+ */
+ public $label = false;
+
+ /**
+ *
+ * @var array
+ */
+ public $label_count = false;
+
+ /**
+ *
+ * @var labels
+ */
+ public $labels = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $exclude_from_search = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $_builtin = false;
+
+ /**
+ *
+ * @var bool
+ */
+ public $public = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $internal = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $protected = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $private = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $publicly_queryable = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $show_in_admin_status_list = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $show_in_admin_all_list = null;
+
+ /**
+ *
+ * @var bool
+ */
+ public $show_in_admin_status_dropdown = false;
+
+ /**
+ *
+ * @var int
+ */
+ public $priority = 10;
+
+ /**
+ *
+ * @var object
+ */
+ public $capabilities = null;
+
+ public function __construct( $post_status, $args = array() ) {
+
+ $args = (object) $args;
+ foreach ( get_object_vars( $args ) as $key => $value )
+ $this->$key = $value;
+
+ $this->name = sanitize_key( $post_status );
+
+ if ( null === $this->public && null === $this->internal && null === $this->protected && null === $this->private )
+ $this->internal = true;
+
+ if ( null === $this->public )
+ $this->public = false;
+
+ if ( null === $this->private )
+ $this->private = false;
+
+ if ( null === $this->protected )
+ $this->protected = false;
+
+ if ( null === $this->internal )
+ $this->internal = false;
+
+ if ( null === $this->publicly_queryable )
+ $this->publicly_queryable = $this->public;
+
+ if ( null === $this->exclude_from_search )
+ $this->exclude_from_search = $this->internal;
+
+ if ( null === $this->show_in_admin_all_list )
+ $this->show_in_admin_all_list = !$this->internal;
+
+ if ( null === $this->show_in_admin_status_list )
+ $this->show_in_admin_status_list = !$this->internal;
+
+ if ( false === $this->label )
+ $this->label = $post_status;
+
+ if ( false === $this->label_count )
+ $this->label_count = array( $this->label, $this->label );
+
+ if ( null === $this->capabilities )
+ $this->capabilities = array( 'transition_post' => 'edit_post' );
+
+ $this->capabilities = (object) $this->capabilities;
+ }
+}
+
+/**
* Retrieve ancestors of a post.
*
* @since 2.5.0
@@ -920,66 +1079,20 @@
* @param array|string $args See above description.
*/
function register_post_status($post_status, $args = array()) {
- global $wp_post_statuses;
+ global $wp_post_statuses, $wp_post_types;
if (!is_array($wp_post_statuses))
$wp_post_statuses = array();
- // Args prefixed with an underscore are reserved for internal use.
- $defaults = array(
- 'label' => false,
- 'label_count' => false,
- 'exclude_from_search' => null,
- '_builtin' => false,
- 'public' => null,
- 'internal' => null,
- 'protected' => null,
- 'private' => null,
- 'publicly_queryable' => null,
- 'show_in_admin_status_list' => null,
- 'show_in_admin_all_list' => null,
- );
- $args = wp_parse_args($args, $defaults);
- $args = (object) $args;
+ $args = new WP_Post_Status( $post_status, $args );
+ $wp_post_statuses[ $post_status ] = $args;
- $post_status = sanitize_key($post_status);
- $args->name = $post_status;
+ // Add status to already registered post types
+ if ( ! empty( $wp_post_types ) )
+ foreach ( $wp_post_types as $key => $post_type )
+ if ( ! array_key_exists( $post_status, $post_type->statuses ) )
+ $wp_post_types[ $key ]->statuses[ $post_status ] = $args;
- if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )
- $args->internal = true;
-
- if ( null === $args->public )
- $args->public = false;
-
- if ( null === $args->private )
- $args->private = false;
-
- if ( null === $args->protected )
- $args->protected = false;
-
- if ( null === $args->internal )
- $args->internal = false;
-
- if ( null === $args->publicly_queryable )
- $args->publicly_queryable = $args->public;
-
- if ( null === $args->exclude_from_search )
- $args->exclude_from_search = $args->internal;
-
- if ( null === $args->show_in_admin_all_list )
- $args->show_in_admin_all_list = !$args->internal;
-
- if ( null === $args->show_in_admin_status_list )
- $args->show_in_admin_status_list = !$args->internal;
-
- if ( false === $args->label )
- $args->label = $post_status;
-
- if ( false === $args->label_count )
- $args->label_count = array( $args->label, $args->label );
-
- $wp_post_statuses[$post_status] = $args;
-
return $args;
}
@@ -996,13 +1109,29 @@
* @param string $post_status The name of a registered post status
* @return object A post status object
*/
-function get_post_status_object( $post_status ) {
+function get_post_status_object( $post_status, $object_type = null ) {
global $wp_post_statuses;
- if ( empty($wp_post_statuses[$post_status]) )
- return null;
+ $status_object = null;
- return $wp_post_statuses[$post_status];
+ if ( $object_type ) {
+ $post_type = get_post_type_object( $object_type );
+ if ( $post_type && ! empty( $post_type->statuses[ $post_status ] ) )
+ $status_object = $post_type->statuses[ $post_status ];
+ }
+
+ if ( ! empty( $wp_post_statuses[ $post_status ] ) )
+ $status = $wp_post_statuses[ $post_status ];
+
+ // Search across all post types
+ foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
+ if ( ! empty( $post_type->statuses[ $post_status ] ) ) {
+ $status_object = $post_type->statuses[ $post_status ];
+ break;
+ }
+ }
+
+ return $status_object;
}
/**
@@ -1026,10 +1155,30 @@
$field = ('names' == $output) ? 'name' : false;
- return wp_filter_object_list($wp_post_statuses, $args, $operator, $field);
+ $statuses = $wp_post_statuses;
+
+ if ( ! empty( $args['object_type'] ) ) {
+ $post_type = get_post_type_object( $args['object_type'] );
+ if ( $post_type )
+ $statuses = $post_type->statuses;
+
+ unset( $args['object_type'] );
+ }
+
+ return wp_filter_object_list( $statuses, $args, $operator, $field );
}
/**
+ * Sort an array of posts statuses by priority.
+ */
+function _sort_post_statuses( $a, $b ) {
+ if ( $a->priority == $b->priority )
+ return 0;
+
+ return ( $a->priority < $b->priority ) ? -1 : 1;
+}
+
+/**
* Whether the post type is hierarchical.
*
* A false return value might also mean that the post type does not exist.
@@ -1211,7 +1360,7 @@
* @return object|WP_Error the registered post type object, or an error object
*/
function register_post_type( $post_type, $args = array() ) {
- global $wp_post_types, $wp_rewrite, $wp;
+ global $wp_post_types, $wp_rewrite, $wp, $wp_post_statuses;
if ( !is_array($wp_post_types) )
$wp_post_types = array();
@@ -1227,6 +1376,7 @@
'can_export' => true,
'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
'delete_with_user' => null,
+ 'statuses' => null,
);
$args = wp_parse_args($args, $defaults);
$args = (object) $args;
@@ -1336,6 +1486,18 @@
if ( $args->register_meta_box_cb )
add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
+ if ( null === $args->statuses )
+ $args->statuses = array();
+
+ foreach ( $args->statuses as $post_status => $post_status_args )
+ $args->statuses[ $post_status ] = new WP_Post_Status( $post_status, $post_status_args );
+
+ // Legacy post statuses
+ if ( ! empty( $wp_post_statuses ) )
+ foreach ( $wp_post_statuses as $key => $post_status )
+ if ( empty( $args->statuses[ $key ] ) )
+ $args->statuses[ $key ] = $post_status;
+
$args->labels = get_post_type_labels( $args );
$args->label = $args->labels->name;
Index: wp-includes/capabilities.php
===================================================================
--- wp-includes/capabilities.php (revision 23301)
+++ wp-includes/capabilities.php (working copy)
@@ -1155,6 +1155,11 @@
$caps[] = $post_type->cap->publish_posts;
break;
+ case 'transition_post':
+ $post = get_post( $args[0] );
+ $post_status = get_post_status_object( $args[1], $post->post_type );
+ $caps = map_meta_cap( $post_status->capabilities->transition_post, $user_id, $post->ID, $args[1] );
+ break;
case 'edit_post_meta':
case 'delete_post_meta':
case 'add_post_meta':