返回介绍

_wp_dashboard_recent_comments_row()

发布于 2017-09-11 13:40:43 字数 10585 浏览 1043 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_wp_dashboard_recent_comments_row( WP_Comment $comment,  bool $show_date = true )

Outputs a row for the Recent Comments widget.


description


参数

$comment

(WP_Comment) (Required) The current comment.

$show_date

(bool) (Optional) Whether to display the date.

Default value: true


源代码

File: wp-admin/includes/dashboard.php

function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
	$GLOBALS['comment'] = clone $comment;

	if ( $comment->comment_post_ID > 0 ) {

		$comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
		$comment_post_url = get_the_permalink( $comment->comment_post_ID );
		$comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
	} else {
		$comment_post_link = '';
	}

	$actions_string = '';
	if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
		// Pre-order it: Approve | Reply | Edit | Spam | Trash.
		$actions = array(
			'approve' => '', 'unapprove' => '',
			'reply' => '',
			'edit' => '',
			'spam' => '',
			'trash' => '', 'delete' => '',
			'view' => '',
		);

		$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
		$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );

		$approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
		$unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
		$spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
		$trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
		$delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );

		$actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
		$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
		$actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>';
		$actions['reply'] = '<a onclick="window.commentReply && commentReply.open(\'' . $comment->comment_ID . '\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" aria-label="' . esc_attr__( 'Reply to this comment' ) . '" href="#">' . __( 'Reply' ) . '</a>';
		$actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';

		if ( ! EMPTY_TRASH_DAYS ) {
			$actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>';
		} else {
			$actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
		}

		$actions['view'] = '<a class="comment-link" href="' . esc_url( get_comment_link( $comment ) ) . '" aria-label="' . esc_attr__( 'View this comment' ) . '">' . __( 'View' ) . '</a>';

		/**
		 * Filters the action links displayed for each comment in the 'Recent Comments'
		 * dashboard widget.
		 *
		 * @since 2.6.0
		 *
		 * @param array      $actions An array of comment actions. Default actions include:
		 *                            'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
		 *                            'Delete', and 'Trash'.
		 * @param WP_Comment $comment The comment object.
		 */
		$actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );

		$i = 0;
		foreach ( $actions as $action => $link ) {
			++$i;
			( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';

			// Reply and quickedit need a hide-if-no-js span
			if ( 'reply' == $action || 'quickedit' == $action ) {
				$action .= ' hide-if-no-js';
			}

			if ( 'view' === $action && '1' !== $comment->comment_approved ) {
				$action .= ' hidden';
			}
			$actions_string .= "<span class='$action'>$sep$link</span>";
		}
	}
?>

		<li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>

			<?php echo get_avatar( $comment, 50, 'mystery' ); ?>

			<?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>

			<div class="dashboard-comment-wrap has-row-actions">
			<p class="comment-meta">
			<?php
				// Comments might not have a post they relate to, e.g. programmatically created ones.
				if ( $comment_post_link ) {
					printf(
/* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */
__( 'From %1$s on %2$s %3$s' ),
'<code class="comment-author">' . get_comment_author_link( $comment ) . '</code>',
$comment_post_link,
'<span class="approve">' . __( '[Pending]' ) . '</span>'
					);
				} else {
					printf(
/* translators: 1: comment author, 2: notification if the comment is pending */
__( 'From %1$s %2$s' ),
'<code class="comment-author">' . get_comment_author_link( $comment ) . '</code>',
'<span class="approve">' . __( '[Pending]' ) . '</span>'
					);
				}
			?>
			</p>

			<?php
			else :
				switch ( $comment->comment_type ) {
					case 'pingback' :
$type = __( 'Pingback' );
break;
					case 'trackback' :
$type = __( 'Trackback' );
break;
					default :
$type = ucwords( $comment->comment_type );
				}
				$type = esc_html( $type );
			?>
			<div class="dashboard-comment-wrap has-row-actions">
			<p class="comment-meta">
			<?php
				// Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
				if ( $comment_post_link ) {
					printf(
/* translators: 1: type of comment, 2: post link, 3: notification if the comment is pending */
_x( '%1$s on %2$s %3$s', 'dashboard' ),
"<strong>$type</strong>",
$comment_post_link,
'<span class="approve">' . __( '[Pending]' ) . '</span>'
					);
				} else {
					printf(
/* translators: 1: type of comment, 2: notification if the comment is pending */
_x( '%1$s %2$s', 'dashboard' ),
"<strong>$type</strong>",
'<span class="approve">' . __( '[Pending]' ) . '</span>'
					);
				}
			?>
			</p>
			<p class="comment-author"><?php comment_author_link( $comment ); ?></p>

			<?php endif; // comment_type ?>
			<blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote>
			<?php if ( $actions_string ) : ?>
			<p class="row-actions"><?php echo $actions_string; ?></p>
			<?php endif; ?>
			</div>
		</li>
<?php
	$GLOBALS['comment'] = null;
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-admin/includes/dashboard.php: comment_row_actions
  • wp-admin/includes/template.php: _draft_or_post_title()
  • wp-includes/capabilities.php: current_user_can()
  • wp-includes/l10n.php: esc_attr__()
  • wp-includes/l10n.php: __()
  • wp-includes/l10n.php: _x()
  • wp-includes/formatting.php: esc_html()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/pluggable.php: get_avatar()
  • wp-includes/pluggable.php: wp_create_nonce()
  • wp-includes/link-template.php: get_the_permalink()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/comment-template.php: get_comment_link()
  • wp-includes/comment-template.php: comment_class()
  • wp-includes/comment-template.php: comment_excerpt()
  • wp-includes/comment-template.php: get_comment_author_link()
  • wp-includes/comment-template.php: comment_author_link()
  • wp-includes/comment.php: wp_get_comment_status()
  • Show 13 more uses Hide more uses

Used By

  • wp-admin/includes/dashboard.php: wp_dashboard_recent_comments()
  • wp-admin/includes/ajax-actions.php: wp_ajax_replyto_comment()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文