<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12719] trunk: register_post_type().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12719">12719</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-01-13 18:49:56 +0000 (Wed, 13 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>register_post_type(). see <a href="http://trac.wordpress.org/ticket/9674">#9674</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditphp">trunk/wp-admin/edit.php</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#trunkwpadmin">trunk/wp-admin/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmin"></a>
<div class="propset"><h4>Property changes: trunk/wp-admin</h4>
<pre class="diff"><span>
<span class="cx">Name: svn:ignore
</span><span class="cx">   - .categories.php.swp
</span></span></pre></div>
<a id="trunkwpadmineditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit.php (12718 => 12719)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit.php        2010-01-13 17:03:14 UTC (rev 12718)
+++ trunk/wp-admin/edit.php        2010-01-13 18:49:56 UTC (rev 12719)
</span><span class="lines">@@ -137,7 +137,7 @@
</span><span class="cx">                 $_GET['author'] = $current_user-&gt;ID;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-list($post_stati, $avail_post_stati) = wp_edit_posts_query();
</del><ins>+$avail_post_stati = wp_edit_posts_query();
</ins><span class="cx"> 
</span><span class="cx"> require_once('admin-header.php');
</span><span class="cx"> 
</span><span class="lines">@@ -220,19 +220,21 @@
</span><span class="cx"> $class = empty($class) &amp;&amp; empty($_GET['post_status']) ? ' class=&quot;current&quot;' : '';
</span><span class="cx"> $status_links[] = &quot;&lt;li&gt;&lt;a href='edit.php{$allposts}'$class&gt;&quot; . sprintf( _nx( 'All &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'All &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '&lt;/a&gt;';
</span><span class="cx"> 
</span><del>-foreach ( $post_stati as $status =&gt; $label ) {
</del><ins>+foreach ( get_post_stati(array(), 'objects') as $status ) {
</ins><span class="cx">         $class = '';
</span><span class="cx"> 
</span><del>-        if ( !in_array( $status, $avail_post_stati ) )
</del><ins>+        $status_name = $status-&gt;name;
+
+        if ( !in_array( $status_name, $avail_post_stati ) )
</ins><span class="cx">                 continue;
</span><span class="cx"> 
</span><del>-        if ( empty( $num_posts-&gt;$status ) )
</del><ins>+        if ( empty( $num_posts-&gt;$status_name ) )
</ins><span class="cx">                 continue;
</span><span class="cx"> 
</span><del>-        if ( isset($_GET['post_status']) &amp;&amp; $status == $_GET['post_status'] )
</del><ins>+        if ( isset($_GET['post_status']) &amp;&amp; $status_name == $_GET['post_status'] )
</ins><span class="cx">                 $class = ' class=&quot;current&quot;';
</span><span class="cx"> 
</span><del>-        $status_links[] = &quot;&lt;li&gt;&lt;a href='edit.php?post_status=$status&amp;amp;post_type=$post_type'$class&gt;&quot; . sprintf( _n( $label[2][0], $label[2][1], $num_posts-&gt;$status ), number_format_i18n( $num_posts-&gt;$status ) ) . '&lt;/a&gt;';
</del><ins>+        $status_links[] = &quot;&lt;li&gt;&lt;a href='edit.php?post_status=$status_name&amp;amp;post_type=$post_type'$class&gt;&quot; . sprintf( _n( $status-&gt;label_count[0], $status-&gt;label_count[1], $num_posts-&gt;$status_name ), number_format_i18n( $num_posts-&gt;$status_name ) ) . '&lt;/a&gt;';
</ins><span class="cx"> }
</span><span class="cx"> echo implode( &quot; |&lt;/li&gt;\n&quot;, $status_links ) . '&lt;/li&gt;';
</span><span class="cx"> unset( $status_links );
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (12718 => 12719)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2010-01-13 17:03:14 UTC (rev 12718)
+++ trunk/wp-admin/includes/post.php        2010-01-13 18:49:56 UTC (rev 12719)
</span><span class="lines">@@ -817,17 +817,8 @@
</span><span class="cx">                 $q = $_GET;
</span><span class="cx">         $q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
</span><span class="cx">         $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
</span><del>-        $post_stati  = array(        //        array( adj, noun )
-                                'publish' =&gt; array(_x('Published', 'post'), __('Published posts'), _n_noop('Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')),
-                                'future' =&gt; array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')),
-                                'pending' =&gt; array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Pending Review &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')),
-                                'draft' =&gt; array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Drafts &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')),
-                                'private' =&gt; array(_x('Private', 'post'), __('Private posts'), _n_noop('Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')),
-                                'trash' =&gt; array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')),
-                        );
</del><ins>+        $post_stati  = get_post_stati();
</ins><span class="cx"> 
</span><del>-        $post_stati = apply_filters('post_stati', $post_stati);
-
</del><span class="cx">         if ( isset($q['post_type']) &amp;&amp; in_array( $q['post_type'], get_post_types( array('_show' =&gt; true) ) ) )
</span><span class="cx">                 $post_type = $q['post_type'];
</span><span class="cx">         else
</span><span class="lines">@@ -835,7 +826,7 @@
</span><span class="cx"> 
</span><span class="cx">         $avail_post_stati = get_available_post_statuses($post_type);
</span><span class="cx"> 
</span><del>-        if ( isset($q['post_status']) &amp;&amp; in_array( $q['post_status'], array_keys($post_stati) ) ) {
</del><ins>+        if ( isset($q['post_status']) &amp;&amp; in_array( $q['post_status'], $post_stati ) ) {
</ins><span class="cx">                 $post_status = $q['post_status'];
</span><span class="cx">                 $perm = 'readable';
</span><span class="cx">         }
</span><span class="lines">@@ -862,7 +853,7 @@
</span><span class="cx"> 
</span><span class="cx">         wp( compact('post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page') );
</span><span class="cx"> 
</span><del>-        return array($post_stati, $avail_post_stati);
</del><ins>+        return $avail_post_stati;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (12718 => 12719)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-01-13 17:03:14 UTC (rev 12718)
+++ trunk/wp-includes/post.php        2010-01-13 18:49:56 UTC (rev 12719)
</span><span class="lines">@@ -21,6 +21,12 @@
</span><span class="cx">         register_post_type( 'revision', array('label' =&gt; __('Revisions'),'exclude_from_search' =&gt; true, '_builtin' =&gt; true, '_edit_link' =&gt; 'revision.php?revision=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false) );
</span><span class="cx">         add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') );
</span><span class="cx">         add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') );
</span><ins>+
+        register_post_status( 'publish', array('label' =&gt; _x('Published', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Published &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
+        register_post_status( 'future', array('label' =&gt; _x('Scheduled', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Scheduled &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
+        register_post_status( 'draft', array('label' =&gt; _x('Draft', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Draft &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Drafts &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
+        register_post_status( 'private', array('label' =&gt; _x('Private', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Private &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
+        register_post_status( 'trash', array('label' =&gt; _x('Trash', 'post'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, 'label_count' =&gt; _n_noop('Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;')) );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
</span><span class="cx"> 
</span><span class="lines">@@ -419,6 +425,118 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * 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' =&gt; false, 'label_count' =&gt; false, 'exclude_from_search' =&gt; true, '_builtin' =&gt; false, '_edit_link' =&gt; 'post.php?post=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'public' =&gt; false, '_show' =&gt; false);
+        $args = wp_parse_args($args, $defaults);
+        $args = (object) $args;
+
+        $post_status = sanitize_user($post_status, true);
+        $args-&gt;name = $post_status;
+
+        if ( false === $args-&gt;label )
+                $args-&gt;label = $post_status;
+
+        if ( false === $args-&gt;label_count )
+                $args-&gt;label_count = $args-&gt;label;
+
+        if ( !$args-&gt;_builtin &amp;&amp; $args-&gt;public )
+                $args-&gt;_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 =&gt; 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-&gt;name;
+                        else
+                                $post_statuses[] = $post_status;
+                } elseif ( array_intersect_assoc((array) $post_status, $args) ) {
+                        if ( $do_names )
+                                $post_statuses[] = $post_status-&gt;name;
+                        else
+                                $post_statuses[] = $post_status;
+                }
+        }
+
+        return $post_statuses;
+}
+
+/**
</ins><span class="cx">  * Retrieve the post type of the current post or of a given post.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.1.0
</span></span></pre>
</div>
</div>

</body>
</html>