WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#5811 closed defect (bug) (fixed)

wp-admin/edit-comments.php unnecessarily checks twice for user permissions

Reported by: hansengel Owned by: hansengel
Priority: normal Milestone: 2.9
Component: Administration Version: 2.5
Severity: minor Keywords: needs-patch
Cc:

Description

It's easier to just show you the current code (as of [6772]):

    <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
	echo "<a href='comment.php?action=editcomment&amp;c=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a>"; } ?></td>
    <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
		$url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
		echo "<a href='$url' class='delete:the-comment-list:comment-$comment->comment_ID delete'>" . __('Delete') . "</a> ";
		} ?></td>

I don't see any point in repeatedly checking if the user has sufficient permissions on the same page. Let's simplify it a bit and check for user permissions once.

Attachments (1)

5811.r6772.diff (1.2 KB) - added by hansengel 5 years ago.
Removes second unnecessary check for sufficient user permissions in wp-admin/edit-comments.php

Download all attachments as: .zip

Change History (5)

hansengel5 years ago

Removes second unnecessary check for sufficient user permissions in wp-admin/edit-comments.php

comment:1 ryan5 years ago

That puts the td tags inside the conditional. I think they need to always be there even when the user doesn't have the proper caps. In that case they would be empty.

comment:2 hansengel5 years ago

  • Status changed from new to assigned

Just checked it out—without my patch when the user doesn't have enough permissions, there are two empty columns at the end of each row. With the patch, they're not shown and the View link extends over where the other two columns would be. So it's actually better to use it this way, IMHO.

comment:3 Denis-de-Bernardy4 years ago

  • Keywords needs-patch added; has-patch tested removed

comment:4 westi4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

Closing as FIXED as this code no longer exits in wp-admin/edit-comments.php and _wp_comment_row only checks the cap once.

Note: See TracTickets for help on using tickets.