<!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>[12682] trunk: Post type caps.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12682">12682</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-01-10 01:23:14 +0000 (Sun, 10 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Post type caps. see <a href="http://trac.wordpress.org/ticket/9674">#9674</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditformadvancedphp">trunk/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunkwpadmineditpageformphp">trunk/wp-admin/edit-page-form.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditformadvancedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-form-advanced.php (12681 => 12682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-form-advanced.php        2010-01-09 19:19:55 UTC (rev 12681)
+++ trunk/wp-admin/edit-form-advanced.php        2010-01-10 01:23:14 UTC (rev 12682)
</span><span class="lines">@@ -99,15 +99,19 @@
</span><span class="cx">
</span><span class="cx"> if ( is_object_in_taxonomy($post_type, 'category') )
</span><span class="cx">         add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
</span><del>-if ( current_theme_supports( 'post-thumbnails', $post_type ) )
</del><ins>+if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports($post_type, 'post-thumbnails') )
</ins><span class="cx">         add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
</span><del>-add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
-add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
-add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
</del><ins>+if ( post_type_supports($post_type, 'excerpts') )
+        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
+if ( post_type_supports($post_type, 'trackbacks') )
+        add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
+if ( post_type_supports($post_type, 'custom-fields') )
+        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
</ins><span class="cx"> do_action('dbx_post_advanced');
</span><del>-add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
</del><ins>+if ( post_type_supports($post_type, 'comments') )
+        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
</ins><span class="cx">
</span><del>-if ( 'publish' == $post->post_status || 'private' == $post->post_status )
</del><ins>+if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
</ins><span class="cx">         add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
</span><span class="cx">
</span><span class="cx"> if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) )
</span></span></pre></div>
<a id="trunkwpadmineditpageformphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-page-form.php (12681 => 12682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-page-form.php        2010-01-09 19:19:55 UTC (rev 12681)
+++ trunk/wp-admin/edit-page-form.php        2010-01-10 01:23:14 UTC (rev 12682)
</span><span class="lines">@@ -75,26 +75,32 @@
</span><span class="cx">
</span><span class="cx"> require_once('includes/meta-boxes.php');
</span><span class="cx">
</span><ins>+$post_type = 'page';
+
</ins><span class="cx"> add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 'page', 'side', 'core');
</span><del>-add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', 'page', 'side', 'core');
-add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'page', 'normal', 'core');
-add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', 'page', 'normal', 'core');
-add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', 'page', 'normal', 'core');
-if ( current_theme_supports( 'post-thumbnails', 'page' ) )
-        add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', 'page', 'side', 'low');
</del><span class="cx">
</span><ins>+if ( post_type_supports($post_type, 'page-attributes') )
+        add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');
+if ( post_type_supports($post_type, 'custom-fields') )
+        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
+if ( post_type_supports($post_type, 'comments') )
+        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
+add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
+if ( current_theme_supports( 'post-thumbnails', 'page' ) && post_type_supports($post_type, 'post-thumbnails') )
+        add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
+
</ins><span class="cx"> $authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM
</span><span class="cx"> if ( $post->post_author && !in_array($post->post_author, $authors) )
</span><span class="cx">         $authors[] = $post->post_author;
</span><span class="cx"> if ( $authors && count( $authors ) > 1 )
</span><del>-        add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', 'page', 'normal', 'core');
</del><ins>+        add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
</ins><span class="cx">
</span><span class="cx"> if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
</span><del>-        add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', 'page', 'normal', 'core');
</del><ins>+        add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
</ins><span class="cx">
</span><del>-do_action('do_meta_boxes', 'page', 'normal', $post);
-do_action('do_meta_boxes', 'page', 'advanced', $post);
-do_action('do_meta_boxes', 'page', 'side', $post);
</del><ins>+do_action('do_meta_boxes', $post_type, 'normal', $post);
+do_action('do_meta_boxes', $post_type, 'advanced', $post);
+do_action('do_meta_boxes', $post_type, 'side', $post);
</ins><span class="cx">
</span><span class="cx"> require_once('admin-header.php');
</span><span class="cx"> ?>
</span><span class="lines">@@ -128,7 +134,7 @@
</span><span class="cx"> <div id="side-info-column" class="inner-sidebar">
</span><span class="cx"> <?php
</span><span class="cx"> do_action('submitpage_box');
</span><del>-$side_meta_boxes = do_meta_boxes('page', 'side', $post); ?>
</del><ins>+$side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?>
</ins><span class="cx"> </div>
</span><span class="cx">
</span><span class="cx"> <div id="post-body">
</span><span class="lines">@@ -178,9 +184,9 @@
</span><span class="cx"> </div>
</span><span class="cx">
</span><span class="cx"> <?php
</span><del>-do_meta_boxes('page', 'normal', $post);
</del><ins>+do_meta_boxes($post_type, 'normal', $post);
</ins><span class="cx"> do_action('edit_page_form');
</span><del>-do_meta_boxes('page', 'advanced', $post);
</del><ins>+do_meta_boxes($post_type, 'advanced', $post);
</ins><span class="cx"> ?>
</span><span class="cx">
</span><span class="cx"> </div>
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (12681 => 12682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-01-09 19:19:55 UTC (rev 12681)
+++ trunk/wp-includes/post.php        2010-01-10 01:23:14 UTC (rev 12682)
</span><span class="lines">@@ -19,6 +19,8 @@
</span><span class="cx">         register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'page.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) );
</span><span class="cx">         register_post_type( 'attachment', array('label' => __('Media'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'media.php?attachment_id=%d', 'capability_type' => 'post', 'hierarchical' => false) );
</span><span class="cx">         register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) );
</span><ins>+        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') );
</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">@@ -562,6 +564,50 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Register support of certain features for a post type.
+ *
+ * @since 3.0
+ * @param string $post_type The post type for which to add the feature
+ * @param string|array $feature the feature being added, can be an array of feature strings or a single string
+ */
+function add_post_type_support( $post_type, $feature ) {
+        global $_wp_post_type_features;
+
+        $features = (array) $feature;
+        foreach ($features as $feature) {
+                if ( func_num_args() == 2 )
+                        $_wp_post_type_features[$post_type][$feature] = true;
+                else
+                        $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
+        }
+}
+
+/**
+ * Checks a post type's support for a given feature
+ *
+ * @since 3.0
+ * @param string $post_type The post type being checked
+ * @param string $feature the feature being checked
+ * @return boolean
+ */
+
+function post_type_supports( $post_type, $feature ) {
+        global $_wp_post_type_features;
+
+        if ( !isset( $_wp_post_type_features[$post_type][$feature] ) )
+                return false;
+
+        // If no args passed then no extra checks need be performed
+        if ( func_num_args() <= 2 )
+                return true;
+
+        // @todo Allow pluggable arg checking
+        //$args = array_slice( func_get_args(), 2 );
+
+        return true;
+}
+
+/**
</ins><span class="cx"> * Updates the post type for the post ID.
</span><span class="cx"> *
</span><span class="cx"> * The page or post cache will be cleaned for the post ID.
</span></span></pre>
</div>
</div>
</body>
</html>