register_post_type(). see #9674
git-svn-id: http://svn.automattic.com/wordpress/trunk@12719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b323e4b9e6
commit
c6737c2f02
|
@ -137,7 +137,7 @@ if ( !current_user_can('edit_others_posts') ) {
|
|||
$_GET['author'] = $current_user->ID;
|
||||
}
|
||||
|
||||
list($post_stati, $avail_post_stati) = wp_edit_posts_query();
|
||||
$avail_post_stati = wp_edit_posts_query();
|
||||
|
||||
require_once('admin-header.php');
|
||||
|
||||
|
@ -220,19 +220,21 @@ $total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
|
|||
$class = empty($class) && empty($_GET['post_status']) ? ' class="current"' : '';
|
||||
$status_links[] = "<li><a href='edit.php{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
|
||||
|
||||
foreach ( $post_stati as $status => $label ) {
|
||||
foreach ( get_post_stati(array(), 'objects') as $status ) {
|
||||
$class = '';
|
||||
|
||||
if ( !in_array( $status, $avail_post_stati ) )
|
||||
$status_name = $status->name;
|
||||
|
||||
if ( !in_array( $status_name, $avail_post_stati ) )
|
||||
continue;
|
||||
|
||||
if ( empty( $num_posts->$status ) )
|
||||
if ( empty( $num_posts->$status_name ) )
|
||||
continue;
|
||||
|
||||
if ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
|
||||
if ( isset($_GET['post_status']) && $status_name == $_GET['post_status'] )
|
||||
$class = ' class="current"';
|
||||
|
||||
$status_links[] = "<li><a href='edit.php?post_status=$status&post_type=$post_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
|
||||
$status_links[] = "<li><a href='edit.php?post_status=$status_name&post_type=$post_type'$class>" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
|
||||
}
|
||||
echo implode( " |</li>\n", $status_links ) . '</li>';
|
||||
unset( $status_links );
|
||||
|
|
|
@ -817,16 +817,7 @@ function wp_edit_posts_query( $q = false ) {
|
|||
$q = $_GET;
|
||||
$q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
|
||||
$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
|
||||
$post_stati = array( // array( adj, noun )
|
||||
'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
|
||||
'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
|
||||
'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
|
||||
'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
|
||||
'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
|
||||
'trash' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')),
|
||||
);
|
||||
|
||||
$post_stati = apply_filters('post_stati', $post_stati);
|
||||
$post_stati = get_post_stati();
|
||||
|
||||
if ( isset($q['post_type']) && in_array( $q['post_type'], get_post_types( array('_show' => true) ) ) )
|
||||
$post_type = $q['post_type'];
|
||||
|
@ -835,7 +826,7 @@ function wp_edit_posts_query( $q = false ) {
|
|||
|
||||
$avail_post_stati = get_available_post_statuses($post_type);
|
||||
|
||||
if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_stati) ) ) {
|
||||
if ( isset($q['post_status']) && in_array( $q['post_status'], $post_stati ) ) {
|
||||
$post_status = $q['post_status'];
|
||||
$perm = 'readable';
|
||||
}
|
||||
|
@ -862,7 +853,7 @@ function wp_edit_posts_query( $q = false ) {
|
|||
|
||||
wp( compact('post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page') );
|
||||
|
||||
return array($post_stati, $avail_post_stati);
|
||||
return $avail_post_stati;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,12 @@ function create_initial_post_types() {
|
|||
register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) );
|
||||
add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') );
|
||||
add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') );
|
||||
|
||||
register_post_status( 'publish', array('label' => _x('Published', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')) );
|
||||
register_post_status( 'future', array('label' => _x('Scheduled', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')) );
|
||||
register_post_status( 'draft', array('label' => _x('Draft', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')) );
|
||||
register_post_status( 'private', array('label' => _x('Private', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')) );
|
||||
register_post_status( 'trash', array('label' => _x('Trash', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')) );
|
||||
}
|
||||
add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
|
||||
|
||||
|
@ -418,6 +424,118 @@ function get_page_statuses( ) {
|
|||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a post type. Do not use before init.
|
||||
*
|
||||
* A simple function for creating or modifying a post status based on the
|
||||
* parameters given. The function will accept an array (second optional
|
||||
* parameter), along with a string for the post status name.
|
||||
*
|
||||
*
|
||||
* Optional $args contents:
|
||||
*
|
||||
* label - A descriptive name for the post status marked for translation. Defaults to $post_status.
|
||||
* public - Whether posts of this status should be shown in the admin UI. Defaults to true.
|
||||
* exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to true.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post
|
||||
* @since 3.0
|
||||
* @uses $wp_post_statuses Inserts new post status object into the list
|
||||
*
|
||||
* @param string $post_status Name of the post status.
|
||||
* @param array|string $args See above description.
|
||||
*/
|
||||
function register_post_status($post_status, $args = array()) {
|
||||
global $wp_post_statuses;
|
||||
|
||||
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' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false);
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
$args = (object) $args;
|
||||
|
||||
$post_status = sanitize_user($post_status, true);
|
||||
$args->name = $post_status;
|
||||
|
||||
if ( false === $args->label )
|
||||
$args->label = $post_status;
|
||||
|
||||
if ( false === $args->label_count )
|
||||
$args->label_count = $args->label;
|
||||
|
||||
if ( !$args->_builtin && $args->public )
|
||||
$args->_show = true;
|
||||
|
||||
$wp_post_statuses[$post_status] = $args;
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a post status object by name
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post
|
||||
* @since 3.0
|
||||
* @uses $wp_post_statuses
|
||||
* @see register_post_status
|
||||
* @see get_post_statuses
|
||||
*
|
||||
* @param string $post_type The name of a registered post status
|
||||
* @return object A post status object
|
||||
*/
|
||||
function get_post_status_object( $post_status ) {
|
||||
global $wp_post_statuses;
|
||||
|
||||
if ( empty($wp_post_statuses[$post_status]) )
|
||||
return null;
|
||||
|
||||
return $wp_post_statuses[$post_status];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all registered post status objects.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post
|
||||
* @since 3.0
|
||||
* @uses $wp_post_statuses
|
||||
* @see register_post_status
|
||||
* @see get_post_status_object
|
||||
*
|
||||
* @param array|string $args An array of key => value arguments to match against the post statuses.
|
||||
* Only post statuses having attributes that match all arguments are returned.
|
||||
* @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default.
|
||||
* @return array A list of post type names or objects
|
||||
*/
|
||||
function get_post_stati( $args = array(), $output = 'names' ) {
|
||||
global $wp_post_statuses;
|
||||
|
||||
$do_names = false;
|
||||
if ( 'names' == $output )
|
||||
$do_names = true;
|
||||
|
||||
$post_statuses = array();
|
||||
foreach ( (array) $wp_post_statuses as $post_status ) {
|
||||
if ( empty($args) ) {
|
||||
if ( $do_names )
|
||||
$post_statuses[] = $post_status->name;
|
||||
else
|
||||
$post_statuses[] = $post_status;
|
||||
} elseif ( array_intersect_assoc((array) $post_status, $args) ) {
|
||||
if ( $do_names )
|
||||
$post_statuses[] = $post_status->name;
|
||||
else
|
||||
$post_statuses[] = $post_status;
|
||||
}
|
||||
}
|
||||
|
||||
return $post_statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the post type of the current post or of a given post.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue