<!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>[15596] trunk: Introduce 'edit_comment' meta cap.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15596">15596</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-09-07 23:35:28 +0000 (Tue, 07 Sep 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce 'edit_comment' meta cap. Fixes <a href="http://trac.wordpress.org/ticket/14520">#14520</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincommentphp">trunk/wp-admin/comment.php</a></li>
<li><a href="#trunkwpadmineditcommentsphp">trunk/wp-admin/edit-comments.php</a></li>
<li><a href="#trunkwpadminincludesdashboardphp">trunk/wp-admin/includes/dashboard.php</a></li>
<li><a href="#trunkwpadminincludesdefaultlisttablesphp">trunk/wp-admin/includes/default-list-tables.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
<li><a href="#trunkwpincludeslinktemplatephp">trunk/wp-includes/link-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincommentphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/comment.php (15595 => 15596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/comment.php 2010-09-07 17:52:43 UTC (rev 15595)
+++ trunk/wp-admin/comment.php 2010-09-07 23:35:28 UTC (rev 15596)
</span><span class="lines">@@ -60,8 +60,8 @@
</span><span class="cx"> if ( !$comment = get_comment( $comment_id ) )
</span><span class="cx"> comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'javascript:history.go(-1)') );
</span><span class="cx">
</span><del>- if ( !current_user_can('edit_post', $comment->comment_post_ID) )
- comment_footer_die( __('You are not allowed to edit comments on this post.') );
</del><ins>+ if ( !current_user_can( 'edit_comment', $comment_id ) )
+ comment_footer_die( __('You are not allowed to edit this comment.') );
</ins><span class="cx">
</span><span class="cx"> if ( 'trash' == $comment->comment_approved )
</span><span class="cx"> comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
</span><span class="lines">@@ -84,7 +84,7 @@
</span><span class="cx"> die();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
</del><ins>+ if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
</ins><span class="cx"> wp_redirect( admin_url('edit-comments.php?error=2') );
</span><span class="cx"> die();
</span><span class="cx"> }
</span><span class="lines">@@ -184,7 +184,6 @@
</span><span class="cx">
</span><span class="cx"> <?php wp_nonce_field( $nonce_action ); ?>
</span><span class="cx"> <input type='hidden' name='action' value='<?php echo esc_attr($formaction); ?>' />
</span><del>-<input type='hidden' name='p' value='<?php echo esc_attr($comment->comment_post_ID); ?>' />
</del><span class="cx"> <input type='hidden' name='c' value='<?php echo esc_attr($comment->comment_ID); ?>' />
</span><span class="cx"> <input type='hidden' name='noredir' value='1' />
</span><span class="cx"> </form>
</span><span class="lines">@@ -212,7 +211,7 @@
</span><span class="cx">
</span><span class="cx"> if ( !$comment = get_comment($comment_id) )
</span><span class="cx"> comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit-comments.php') );
</span><del>- if ( !current_user_can('edit_post', $comment->comment_post_ID ) )
</del><ins>+ if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
</ins><span class="cx"> comment_footer_die( __('You are not allowed to edit comments on this post.') );
</span><span class="cx">
</span><span class="cx"> if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
</span></span></pre></div>
<a id="trunkwpadmineditcommentsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-comments.php (15595 => 15596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-comments.php 2010-09-07 17:52:43 UTC (rev 15595)
+++ trunk/wp-admin/edit-comments.php 2010-09-07 23:35:28 UTC (rev 15596)
</span><span class="lines">@@ -34,9 +34,7 @@
</span><span class="cx"> $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
</span><span class="cx">
</span><span class="cx"> foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
</span><del>- $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id ) );
-
- if ( !current_user_can( 'edit_post', $_post_id ) )
</del><ins>+ if ( !current_user_can( 'edit_comment', $comment_id ) )
</ins><span class="cx"> continue;
</span><span class="cx">
</span><span class="cx"> switch ( $doaction ) {
</span></span></pre></div>
<a id="trunkwpadminincludesdashboardphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/dashboard.php (15595 => 15596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/dashboard.php 2010-09-07 17:52:43 UTC (rev 15595)
+++ trunk/wp-admin/includes/dashboard.php 2010-09-07 23:35:28 UTC (rev 15596)
</span><span class="lines">@@ -586,7 +586,7 @@
</span><span class="cx"> $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
</span><span class="cx">
</span><span class="cx"> $actions_string = '';
</span><del>- if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
</del><ins>+ if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
</ins><span class="cx"> // preorder it: Approve | Reply | Edit | Spam | Trash
</span><span class="cx"> $actions = array(
</span><span class="cx"> 'approve' => '', 'unapprove' => '',
</span></span></pre></div>
<a id="trunkwpadminincludesdefaultlisttablesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/default-list-tables.php (15595 => 15596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/default-list-tables.php 2010-09-07 17:52:43 UTC (rev 15595)
+++ trunk/wp-admin/includes/default-list-tables.php 2010-09-07 23:35:28 UTC (rev 15596)
</span><span class="lines">@@ -2254,8 +2254,7 @@
</span><span class="cx"> $comment = get_comment( $comment_id );
</span><span class="cx"> $post = get_post( $comment->comment_post_ID );
</span><span class="cx"> $the_comment_status = wp_get_comment_status( $comment->comment_ID );
</span><del>- $post_type_object = get_post_type_object( $post->post_type );
- $user_can = current_user_can( $post_type_object->cap->edit_post, $post->ID );
</del><ins>+ $user_can = current_user_can( 'edit_comment', $comment_id );
</ins><span class="cx">
</span><span class="cx"> $comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
</span><span class="cx"> $author_url = get_comment_author_url();
</span><span class="lines">@@ -2275,7 +2274,7 @@
</span><span class="cx"> $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
</span><span class="cx"> $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
</span><span class="cx">
</span><del>- $url = "comment.php?post_ID=$post->ID&c=$comment->comment_ID";
</del><ins>+ $url = "comment.php?c=$comment->comment_ID";
</ins><span class="cx">
</span><span class="cx"> $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
</span><span class="cx"> $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (15595 => 15596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php 2010-09-07 17:52:43 UTC (rev 15595)
+++ trunk/wp-includes/capabilities.php 2010-09-07 23:35:28 UTC (rev 15596)
</span><span class="lines">@@ -896,6 +896,7 @@
</span><span class="cx"> $author_data = get_userdata( $user_id );
</span><span class="cx"> //echo "post ID: {$args[0]}<br />";
</span><span class="cx"> $post = get_post( $args[0] );
</span><ins>+
</ins><span class="cx"> $post_type = get_post_type_object( $post->post_type );
</span><span class="cx"> if ( $post_type && 'post' != $post_type->capability_type ) {
</span><span class="cx"> $args = array_merge( array( $post_type->cap->edit_post, $user_id ), $args );
</span><span class="lines">@@ -988,6 +989,13 @@
</span><span class="cx"> else
</span><span class="cx"> $caps[] = 'read_private_pages';
</span><span class="cx"> break;
</span><ins>+ case 'edit_comment':
+ $comment = get_comment( $args[0] );
+ $post = get_post( $comment->comment_post_ID );
+ $post_type_object = get_post_type_object( $post->post_type );
+
+ $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
+ break;
</ins><span class="cx"> case 'unfiltered_upload':
</span><span class="cx"> if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) )
</span><span class="cx"> $caps[] = $cap;
</span></span></pre></div>
<a id="trunkwpincludeslinktemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/link-template.php (15595 => 15596)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/link-template.php 2010-09-07 17:52:43 UTC (rev 15595)
+++ trunk/wp-includes/link-template.php 2010-09-07 23:35:28 UTC (rev 15596)
</span><span class="lines">@@ -875,15 +875,9 @@
</span><span class="cx"> */
</span><span class="cx"> function get_edit_comment_link( $comment_id = 0 ) {
</span><span class="cx"> $comment = &get_comment( $comment_id );
</span><del>- $post = &get_post( $comment->comment_post_ID );
</del><span class="cx">
</span><del>- if ( $post->post_type == 'page' ) {
- if ( !current_user_can( 'edit_page', $post->ID ) )
- return;
- } else {
- if ( !current_user_can( 'edit_post', $post->ID ) )
- return;
- }
</del><ins>+ if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
+ return;
</ins><span class="cx">
</span><span class="cx"> $location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
</span><span class="cx"> return apply_filters( 'get_edit_comment_link', $location );
</span><span class="lines">@@ -900,15 +894,10 @@
</span><span class="cx"> * @return string|null HTML content, if $echo is set to false.
</span><span class="cx"> */
</span><span class="cx"> function edit_comment_link( $link = null, $before = '', $after = '' ) {
</span><del>- global $comment, $post;
</del><ins>+ global $comment;
</ins><span class="cx">
</span><del>- if ( $post->post_type == 'page' ) {
- if ( !current_user_can( 'edit_page', $post->ID ) )
- return;
- } else {
- if ( !current_user_can( 'edit_post', $post->ID ) )
- return;
- }
</del><ins>+ if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
+ return;
</ins><span class="cx">
</span><span class="cx"> if ( null === $link )
</span><span class="cx"> $link = __('Edit This');
</span></span></pre>
</div>
</div>
</body>
</html>