wp_dashboard_recent_comments

函式
wp_dashboard_recent_comments ( $total_items = 5 )
引數
  • (int) $total_items Optional. Number of comments to query. Default 5.
    Required:
    Default: 5
返回值
  • (bool) False if no comments were found. True otherwise.
定義位置
相關方法
_wp_dashboard_recent_comments_rowwp_dashboard_recent_comments_controlwp_dashboard_recent_postswp_dashboard_recent_draftswp_dashboard_rss_control
引入
3.8.0
棄用
-

wp_dashboard_recent_comments:此鉤子用於將內容新增到WordPress中的“最近的評論”儀表盤小工具。開發人員可以使用此鉤子向“最近的評論”小工具新增自定義內容,例如與網站上最近的評論相關的附加資訊或操作。

顯示評論部分。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_dashboard_recent_comments( $total_items = 5 ) {
// Select all comment types and filter out spam later for better query performance.
$comments = array();
$comments_query = array(
'number' => $total_items * 5,
'offset' => 0,
);
if ( ! current_user_can( 'edit_posts' ) ) {
$comments_query['status'] = 'approve';
}
while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
if ( ! is_array( $possible ) ) {
break;
}
foreach ( $possible as $comment ) {
if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
continue;
}
$comments[] = $comment;
if ( count( $comments ) === $total_items ) {
break 2;
}
}
$comments_query['offset'] += $comments_query['number'];
$comments_query['number'] = $total_items * 10;
}
if ( $comments ) {
echo '<div id="latest-comments" class="activity-block table-view-list">';
echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
foreach ( $comments as $comment ) {
_wp_dashboard_recent_comments_row( $comment );
}
echo '</ul>';
if ( current_user_can( 'edit_posts' ) ) {
echo '<h3 class="screen-reader-text">' . __( 'View more comments' ) . '</h3>';
_get_list_table( 'WP_Comments_List_Table' )->views();
}
wp_comment_reply( -1, false, 'dashboard', false );
wp_comment_trashnotice();
echo '</div>';
} else {
return false;
}
return true;
}
function wp_dashboard_recent_comments( $total_items = 5 ) { // Select all comment types and filter out spam later for better query performance. $comments = array(); $comments_query = array( 'number' => $total_items * 5, 'offset' => 0, ); if ( ! current_user_can( 'edit_posts' ) ) { $comments_query['status'] = 'approve'; } while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) { if ( ! is_array( $possible ) ) { break; } foreach ( $possible as $comment ) { if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) { continue; } $comments[] = $comment; if ( count( $comments ) === $total_items ) { break 2; } } $comments_query['offset'] += $comments_query['number']; $comments_query['number'] = $total_items * 10; } if ( $comments ) { echo '<div id="latest-comments" class="activity-block table-view-list">'; echo '<h3>' . __( 'Recent Comments' ) . '</h3>'; echo '<ul id="the-comment-list" data-wp-lists="list:comment">'; foreach ( $comments as $comment ) { _wp_dashboard_recent_comments_row( $comment ); } echo '</ul>'; if ( current_user_can( 'edit_posts' ) ) { echo '<h3 class="screen-reader-text">' . __( 'View more comments' ) . '</h3>'; _get_list_table( 'WP_Comments_List_Table' )->views(); } wp_comment_reply( -1, false, 'dashboard', false ); wp_comment_trashnotice(); echo '</div>'; } else { return false; } return true; }
function wp_dashboard_recent_comments( $total_items = 5 ) {
	// Select all comment types and filter out spam later for better query performance.
	$comments = array();

	$comments_query = array(
		'number' => $total_items * 5,
		'offset' => 0,
	);

	if ( ! current_user_can( 'edit_posts' ) ) {
		$comments_query['status'] = 'approve';
	}

	while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
		if ( ! is_array( $possible ) ) {
			break;
		}

		foreach ( $possible as $comment ) {
			if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
				continue;
			}

			$comments[] = $comment;

			if ( count( $comments ) === $total_items ) {
				break 2;
			}
		}

		$comments_query['offset'] += $comments_query['number'];
		$comments_query['number']  = $total_items * 10;
	}

	if ( $comments ) {
		echo '<div id="latest-comments" class="activity-block table-view-list">';
		echo '<h3>' . __( 'Recent Comments' ) . '</h3>';

		echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
		foreach ( $comments as $comment ) {
			_wp_dashboard_recent_comments_row( $comment );
		}
		echo '</ul>';

		if ( current_user_can( 'edit_posts' ) ) {
			echo '<h3 class="screen-reader-text">' . __( 'View more comments' ) . '</h3>';
			_get_list_table( 'WP_Comments_List_Table' )->views();
		}

		wp_comment_reply( -1, false, 'dashboard', false );
		wp_comment_trashnotice();

		echo '</div>';
	} else {
		return false;
	}
	return true;
}

常見問題

FAQs
檢視更多 >