<!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>[12650] trunk: Assume current user of user ID is not passed.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12650">12650</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-01-07 19:45:57 +0000 (Thu, 07 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Assume current user of user ID is not passed. Props filosofo. fixes <a href="http://trac.wordpress.org/ticket/11808">#11808</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="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.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 (12649 => 12650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-form-advanced.php        2010-01-07 19:41:52 UTC (rev 12649)
+++ trunk/wp-admin/edit-form-advanced.php        2010-01-07 19:45:57 UTC (rev 12650)
</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 ) &amp;&amp; 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-&gt;post_status || 'private' == $post-&gt;post_status )
</del><ins>+if ( ('publish' == $post-&gt;post_status || 'private' == $post-&gt;post_status) &amp;&amp; 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-&gt;post_status &amp;&amp; !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 (12649 => 12650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-page-form.php        2010-01-07 19:41:52 UTC (rev 12649)
+++ trunk/wp-admin/edit-page-form.php        2010-01-07 19:45:57 UTC (rev 12650)
</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' ) &amp;&amp; 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-&gt;id, true, 'page' ); // TODO: ROLE SYSTEM
</span><span class="cx"> if ( $post-&gt;post_author &amp;&amp; !in_array($post-&gt;post_author, $authors) )
</span><span class="cx">         $authors[] = $post-&gt;post_author;
</span><span class="cx"> if ( $authors &amp;&amp; count( $authors ) &gt; 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 &lt; $post_ID &amp;&amp; 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"> ?&gt;
</span><span class="lines">@@ -128,7 +134,7 @@
</span><span class="cx"> &lt;div id=&quot;side-info-column&quot; class=&quot;inner-sidebar&quot;&gt;
</span><span class="cx"> &lt;?php
</span><span class="cx"> do_action('submitpage_box');
</span><del>-$side_meta_boxes = do_meta_boxes('page', 'side', $post); ?&gt;
</del><ins>+$side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?&gt;
</ins><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;div id=&quot;post-body&quot;&gt;
</span><span class="lines">@@ -178,9 +184,9 @@
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?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"> ?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;/div&gt;
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (12649 => 12650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2010-01-07 19:41:52 UTC (rev 12649)
+++ trunk/wp-includes/capabilities.php        2010-01-07 19:45:57 UTC (rev 12650)
</span><span class="lines">@@ -1085,17 +1085,14 @@
</span><span class="cx">  * @return bool True if the user is a site admin.
</span><span class="cx">  */
</span><span class="cx"> function is_super_admin( $user_id = false ) {
</span><del>-        global $current_user;
</del><ins>+        if ( ! $user_id ) {
+                $current_user = wp_get_current_user();
+                $user_id = ! empty($current_user) ? $current_user-&gt;id : 0;
+        }
</ins><span class="cx"> 
</span><del>-        if ( !$current_user &amp;&amp; !$user_id )
</del><ins>+        if ( ! $user_id )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( !$user_id )
-                $user_id = $current_user-&gt;id;
-
-        if ( !$user_id )
-                return false;
-
</del><span class="cx">         $user = new WP_User($user_id);
</span><span class="cx"> 
</span><span class="cx">         if ( is_multisite() ) {
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (12649 => 12650)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-01-07 19:41:52 UTC (rev 12649)
+++ trunk/wp-includes/post.php        2010-01-07 19:45:57 UTC (rev 12650)
</span><span class="lines">@@ -19,6 +19,8 @@
</span><span class="cx">         register_post_type( 'page', array('label' =&gt; __('Pages'),'exclude_from_search' =&gt; false, '_builtin' =&gt; true, '_edit_link' =&gt; 'page.php?post=%d', 'capability_type' =&gt; 'page', 'hierarchical' =&gt; true) );
</span><span class="cx">         register_post_type( 'attachment', array('label' =&gt; __('Media'), 'exclude_from_search' =&gt; false, '_builtin' =&gt; true, '_edit_link' =&gt; 'media.php?attachment_id=%d', 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false) );
</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><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() &lt;= 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>