wp/wp-admin/edit-comments.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    23 
    23 
    24 if ( $doaction ) {
    24 if ( $doaction ) {
    25 	check_admin_referer( 'bulk-comments' );
    25 	check_admin_referer( 'bulk-comments' );
    26 
    26 
    27 	if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
    27 	if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
       
    28 		/**
       
    29 		 * @global wpdb $wpdb WordPress database abstraction object.
       
    30 		 */
       
    31 		global $wpdb;
       
    32 
    28 		$comment_status = wp_unslash( $_REQUEST['comment_status'] );
    33 		$comment_status = wp_unslash( $_REQUEST['comment_status'] );
    29 		$delete_time    = wp_unslash( $_REQUEST['pagegen_timestamp'] );
    34 		$delete_time    = wp_unslash( $_REQUEST['pagegen_timestamp'] );
    30 		$comment_ids    = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) );
    35 		$comment_ids    = $wpdb->get_col(
       
    36 			$wpdb->prepare(
       
    37 				"SELECT comment_ID FROM $wpdb->comments
       
    38 				WHERE comment_approved = %s AND %s > comment_date_gmt",
       
    39 				$comment_status,
       
    40 				$delete_time
       
    41 			)
       
    42 		);
    31 		$doaction       = 'delete';
    43 		$doaction       = 'delete';
    32 	} elseif ( isset( $_REQUEST['delete_comments'] ) ) {
    44 	} elseif ( isset( $_REQUEST['delete_comments'] ) ) {
    33 		$comment_ids = $_REQUEST['delete_comments'];
    45 		$comment_ids = $_REQUEST['delete_comments'];
    34 		$doaction    = $_REQUEST['action'];
    46 		$doaction    = $_REQUEST['action'];
    35 	} elseif ( isset( $_REQUEST['ids'] ) ) {
    47 	} elseif ( isset( $_REQUEST['ids'] ) ) {
    45 	$unspammed  = 0;
    57 	$unspammed  = 0;
    46 	$trashed    = 0;
    58 	$trashed    = 0;
    47 	$untrashed  = 0;
    59 	$untrashed  = 0;
    48 	$deleted    = 0;
    60 	$deleted    = 0;
    49 
    61 
    50 	$redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
    62 	$redirect_to = remove_query_arg(
       
    63 		array(
       
    64 			'trashed',
       
    65 			'untrashed',
       
    66 			'deleted',
       
    67 			'spammed',
       
    68 			'unspammed',
       
    69 			'approved',
       
    70 			'unapproved',
       
    71 			'ids',
       
    72 		),
       
    73 		wp_get_referer()
       
    74 	);
    51 	$redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
    75 	$redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
    52 
    76 
    53 	wp_defer_comment_counting( true );
    77 	wp_defer_comment_counting( true );
    54 
    78 
    55 	foreach ( $comment_ids as $comment_id ) { // Check the permissions on each.
    79 	foreach ( $comment_ids as $comment_id ) { // Check the permissions on each.
    58 		}
    82 		}
    59 
    83 
    60 		switch ( $doaction ) {
    84 		switch ( $doaction ) {
    61 			case 'approve':
    85 			case 'approve':
    62 				wp_set_comment_status( $comment_id, 'approve' );
    86 				wp_set_comment_status( $comment_id, 'approve' );
    63 				$approved++;
    87 				++$approved;
    64 				break;
    88 				break;
    65 			case 'unapprove':
    89 			case 'unapprove':
    66 				wp_set_comment_status( $comment_id, 'hold' );
    90 				wp_set_comment_status( $comment_id, 'hold' );
    67 				$unapproved++;
    91 				++$unapproved;
    68 				break;
    92 				break;
    69 			case 'spam':
    93 			case 'spam':
    70 				wp_spam_comment( $comment_id );
    94 				wp_spam_comment( $comment_id );
    71 				$spammed++;
    95 				++$spammed;
    72 				break;
    96 				break;
    73 			case 'unspam':
    97 			case 'unspam':
    74 				wp_unspam_comment( $comment_id );
    98 				wp_unspam_comment( $comment_id );
    75 				$unspammed++;
    99 				++$unspammed;
    76 				break;
   100 				break;
    77 			case 'trash':
   101 			case 'trash':
    78 				wp_trash_comment( $comment_id );
   102 				wp_trash_comment( $comment_id );
    79 				$trashed++;
   103 				++$trashed;
    80 				break;
   104 				break;
    81 			case 'untrash':
   105 			case 'untrash':
    82 				wp_untrash_comment( $comment_id );
   106 				wp_untrash_comment( $comment_id );
    83 				$untrashed++;
   107 				++$untrashed;
    84 				break;
   108 				break;
    85 			case 'delete':
   109 			case 'delete':
    86 				wp_delete_comment( $comment_id );
   110 				wp_delete_comment( $comment_id );
    87 				$deleted++;
   111 				++$deleted;
    88 				break;
   112 				break;
    89 		}
   113 		}
    90 	}
   114 	}
    91 
   115 
    92 	if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {
   116 	if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {
   132 
   156 
   133 $wp_list_table->prepare_items();
   157 $wp_list_table->prepare_items();
   134 
   158 
   135 wp_enqueue_script( 'admin-comments' );
   159 wp_enqueue_script( 'admin-comments' );
   136 enqueue_comment_hotkeys_js();
   160 enqueue_comment_hotkeys_js();
       
   161 
       
   162 /**
       
   163  * @global int $post_id
       
   164  */
       
   165 global $post_id;
   137 
   166 
   138 if ( $post_id ) {
   167 if ( $post_id ) {
   139 	$comments_count      = wp_count_comments( $post_id );
   168 	$comments_count      = wp_count_comments( $post_id );
   140 	$draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
   169 	$draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
   141 
   170 
   185 	array(
   214 	array(
   186 		'id'      => 'moderating-comments',
   215 		'id'      => 'moderating-comments',
   187 		'title'   => __( 'Moderating Comments' ),
   216 		'title'   => __( 'Moderating Comments' ),
   188 		'content' =>
   217 		'content' =>
   189 					'<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
   218 					'<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
   190 					'<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and blog URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
   219 					'<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and site URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
   191 					'<p>' . __( 'In the <strong>Comment</strong> column, hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
   220 					'<p>' . __( 'In the <strong>Comment</strong> column, hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
   192 					'<p>' . __( 'In the <strong>In response to</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows the number of approved comments that post has received. If there are pending comments, a red notification circle with the number of pending comments is displayed. Clicking the notification circle will filter the comments screen to show only pending comments on that post.' ) . '</p>' .
   221 					'<p>' . __( 'In the <strong>In response to</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows the number of approved comments that post has received. If there are pending comments, a red notification circle with the number of pending comments is displayed. Clicking the notification circle will filter the comments screen to show only pending comments on that post.' ) . '</p>' .
   193 					'<p>' . __( 'In the <strong>Submitted on</strong> column, the date and time the comment was left on your site appears. Clicking on the date/time link will take you to that comment on your live site.' ) . '</p>' .
   222 					'<p>' . __( 'In the <strong>Submitted on</strong> column, the date and time the comment was left on your site appears. Clicking on the date/time link will take you to that comment on your live site.' ) . '</p>' .
   194 					'<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>',
   223 					'<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>',
   195 	)
   224 	)
   196 );
   225 );
   197 
   226 
   198 get_current_screen()->set_help_sidebar(
   227 get_current_screen()->set_help_sidebar(
   199 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   228 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   200 	'<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' .
   229 	'<p>' . __( '<a href="https://wordpress.org/documentation/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' .
   201 	'<p>' . __( '<a href="https://wordpress.org/support/article/comment-spam/">Documentation on Comment Spam</a>' ) . '</p>' .
   230 	'<p>' . __( '<a href="https://wordpress.org/documentation/article/understand-comment-spam/">Documentation on Comment Spam</a>' ) . '</p>' .
   202 	'<p>' . __( '<a href="https://wordpress.org/support/article/keyboard-shortcuts/">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
   231 	'<p>' . __( '<a href="https://wordpress.org/documentation/article/keyboard-shortcuts-classic-editor/#keyboard-shortcuts-for-comments">Documentation on Keyboard Shortcuts</a>' ) . '</p>' .
   203 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   232 	'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
   204 );
   233 );
   205 
   234 
   206 get_current_screen()->set_screen_reader_content(
   235 get_current_screen()->set_screen_reader_content(
   207 	array(
   236 	array(
   208 		'heading_views'      => __( 'Filter comments list' ),
   237 		'heading_views'      => __( 'Filter comments list' ),
   270 		case 2:
   299 		case 2:
   271 			$error_msg = __( 'Sorry, you are not allowed to edit comments on this post.' );
   300 			$error_msg = __( 'Sorry, you are not allowed to edit comments on this post.' );
   272 			break;
   301 			break;
   273 	}
   302 	}
   274 	if ( $error_msg ) {
   303 	if ( $error_msg ) {
   275 		echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
   304 		wp_admin_notice(
   276 	}
   305 			$error_msg,
   277 }
   306 			array(
   278 
   307 				'id'                 => 'moderated',
   279 if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) || isset( $_REQUEST['spammed'] ) || isset( $_REQUEST['unspammed'] ) || isset( $_REQUEST['same'] ) ) {
   308 				'additional_classes' => array( 'error' ),
       
   309 			)
       
   310 		);
       
   311 	}
       
   312 }
       
   313 
       
   314 if ( isset( $_REQUEST['approved'] )
       
   315 	|| isset( $_REQUEST['deleted'] )
       
   316 	|| isset( $_REQUEST['trashed'] )
       
   317 	|| isset( $_REQUEST['untrashed'] )
       
   318 	|| isset( $_REQUEST['spammed'] )
       
   319 	|| isset( $_REQUEST['unspammed'] )
       
   320 	|| isset( $_REQUEST['same'] )
       
   321 ) {
   280 	$approved  = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
   322 	$approved  = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
   281 	$deleted   = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
   323 	$deleted   = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
   282 	$trashed   = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
   324 	$trashed   = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
   283 	$untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
   325 	$untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
   284 	$spammed   = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
   326 	$spammed   = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
   285 	$unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
   327 	$unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
   286 	$same      = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
   328 	$same      = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
   287 
   329 
   288 	if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
   330 	if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
   289 		if ( $approved > 0 ) {
   331 		if ( $approved > 0 ) {
   290 			/* translators: %s: Number of comments. */
   332 			$messages[] = sprintf(
   291 			$messages[] = sprintf( _n( '%s comment approved.', '%s comments approved.', $approved ), $approved );
   333 				/* translators: %s: Number of comments. */
       
   334 				_n( '%s comment approved.', '%s comments approved.', $approved ),
       
   335 				$approved
       
   336 			);
   292 		}
   337 		}
   293 
   338 
   294 		if ( $spammed > 0 ) {
   339 		if ( $spammed > 0 ) {
   295 			$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
   340 			$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
   296 			/* translators: %s: Number of comments. */
   341 
   297 			$messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />';
   342 			$messages[] = sprintf(
       
   343 				/* translators: %s: Number of comments. */
       
   344 				_n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ),
       
   345 				$spammed
       
   346 			) . sprintf(
       
   347 				' <a href="%1$s">%2$s</a><br />',
       
   348 				esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ),
       
   349 				__( 'Undo' )
       
   350 			);
   298 		}
   351 		}
   299 
   352 
   300 		if ( $unspammed > 0 ) {
   353 		if ( $unspammed > 0 ) {
   301 			/* translators: %s: Number of comments. */
   354 			$messages[] = sprintf(
   302 			$messages[] = sprintf( _n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ), $unspammed );
   355 				/* translators: %s: Number of comments. */
       
   356 				_n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ),
       
   357 				$unspammed
       
   358 			);
   303 		}
   359 		}
   304 
   360 
   305 		if ( $trashed > 0 ) {
   361 		if ( $trashed > 0 ) {
   306 			$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
   362 			$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
   307 			/* translators: %s: Number of comments. */
   363 
   308 			$messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />';
   364 			$messages[] = sprintf(
       
   365 				/* translators: %s: Number of comments. */
       
   366 				_n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ),
       
   367 				$trashed
       
   368 			) . sprintf(
       
   369 				' <a href="%1$s">%2$s</a><br />',
       
   370 				esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ),
       
   371 				__( 'Undo' )
       
   372 			);
   309 		}
   373 		}
   310 
   374 
   311 		if ( $untrashed > 0 ) {
   375 		if ( $untrashed > 0 ) {
   312 			/* translators: %s: Number of comments. */
   376 			$messages[] = sprintf(
   313 			$messages[] = sprintf( _n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ), $untrashed );
   377 				/* translators: %s: Number of comments. */
       
   378 				_n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ),
       
   379 				$untrashed
       
   380 			);
   314 		}
   381 		}
   315 
   382 
   316 		if ( $deleted > 0 ) {
   383 		if ( $deleted > 0 ) {
   317 			/* translators: %s: Number of comments. */
   384 			$messages[] = sprintf(
   318 			$messages[] = sprintf( _n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ), $deleted );
   385 				/* translators: %s: Number of comments. */
       
   386 				_n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ),
       
   387 				$deleted
       
   388 			);
   319 		}
   389 		}
   320 
   390 
   321 		if ( $same > 0 ) {
   391 		if ( $same > 0 ) {
   322 			$comment = get_comment( $same );
   392 			$comment = get_comment( $same );
   323 			if ( $comment ) {
   393 			if ( $comment ) {
   324 				switch ( $comment->comment_approved ) {
   394 				switch ( $comment->comment_approved ) {
   325 					case '1':
   395 					case '1':
   326 						$messages[] = __( 'This comment is already approved.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
   396 						$messages[] = __( 'This comment is already approved.' ) . sprintf(
       
   397 							' <a href="%1$s">%2$s</a>',
       
   398 							esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ),
       
   399 							__( 'Edit comment' )
       
   400 						);
   327 						break;
   401 						break;
   328 					case 'trash':
   402 					case 'trash':
   329 						$messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
   403 						$messages[] = __( 'This comment is already in the Trash.' ) . sprintf(
       
   404 							' <a href="%1$s">%2$s</a>',
       
   405 							esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ),
       
   406 							__( 'View Trash' )
       
   407 						);
   330 						break;
   408 						break;
   331 					case 'spam':
   409 					case 'spam':
   332 						$messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
   410 						$messages[] = __( 'This comment is already marked as spam.' ) . sprintf(
       
   411 							' <a href="%1$s">%2$s</a>',
       
   412 							esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ),
       
   413 							__( 'Edit comment' )
       
   414 						);
   333 						break;
   415 						break;
   334 				}
   416 				}
   335 			}
   417 			}
   336 		}
   418 		}
   337 
   419 
   338 		echo '<div id="moderated" class="updated notice is-dismissible"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
   420 		wp_admin_notice(
       
   421 			implode( "<br />\n", $messages ),
       
   422 			array(
       
   423 				'id'                 => 'moderated',
       
   424 				'additional_classes' => array( 'updated' ),
       
   425 				'dismissible'        => true,
       
   426 			)
       
   427 		);
   339 	}
   428 	}
   340 }
   429 }
   341 ?>
   430 ?>
   342 
   431 
   343 <?php $wp_list_table->views(); ?>
   432 <?php $wp_list_table->views(); ?>