#37: comments_per_page

The comments_per_page filter allows you to define the number of comments to list per page in the comments list table.

It is evaluated in:

comments_per_page accepts 2 arguments:

  1. int $comments_per_page The number of comments to list per page.
  2. string $comment_status The comment status name. Default is ‘all’.

Example:

I don’t know about you, but when I go to clean out spam comments, it’s irritating to have that extra step of upping the comments per page — the default is 20 — just so I can bulk-delete them faster. The following example raises the comments-per-page amount only when you’re in the ‘Spam’ filtered view.

<?php
/**
* Increase comments-per-page limit when viewing spam comments
*
* @see WP_Comments_List_Table::get_per_page(), WP_Screen::render_per_page_options()
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The current comment status view. Default is 'all'.
*
* @return int The filtered number of comments to list per page.
*/
function wpdocs_delete_more_spam_comments( $comments_per_page, $comment_status ) {
if ( 'spam' == $comment_status )
$comments_per_page = 50;
return $comments_per_page;
}
add_filter( 'comments_per_page', 'wpdocs_delete_more_spam_comments', 10, 2 );

View the code example on Gist.

#36: heartbeat_send

The heartbeat_send allows you to modify the Heartbeat response sent when no $_POST data is passed. It is the logged-in, privileged sibling of heartbeat_nopriv_send.

It was added in 3.6.

It is evaluated in wp_ajax_heartbeat() in the wp-admin/includes/ajax-actions.php file.

Like heartbeat_nopriv_send, heartbeat_send accepts 2 arguments:

  1. array|object $response The response object or array.
  2. string $screen_id The screen id.

Example:

There is no example for this filter yet. Have an idea for one? Submit an example.

#35: heartbeat_received

The heartbeat_received ilter allows you to modify the Heartbeat response data in logged-in AJAX situations. It is the logged-in version of heartbeat_nopriv_received.

It was added in 3.6.

It is evaluated in wp_ajax_heartbeat() in the wp-admin/includes/ajax-actions.php file.

Like heartbeat_nopriv_received, heartbeat_received accepts 3 arguments:

  1. array|object $response The nopriv Heartbeat response.
  2. array $data An array of data passed via $_POST.
  3. string $screen_id The screen id.

Example:

Since we already have a working example for heartbeat_nopriv_received, we’ll reuse that here.

The following example is based on a Heartbeat example Gist written by Jason Coleman and kindly suggested by jsternberg in the comments.

It modifies the $response value to return a ‘marco polo’ scenario showing the server “responding” to the AJAX call. Thanks to for the suggestion!

<?php
/**
* Example 'Marco, Polo' Heartbeat data received filter.
*
* Based on an original Gist by Jason Coleman (https://gist.github.com/strangerstudios/5888123)
*
* @see wp_ajax_heartbeat()
*
* @param array|object $response The response object.
* @param array $data An array of $_POST data.
* @param string $screen_id The screen id.
*
* @return mixed The filtered response.
*/
function wpdocs_heartbeat_received( $response, $data, $screen_id ) {
if ( $data['client'] == 'marco' )
$response['server'] = 'polo';
return $response;
}
add_filter( 'heartbeat_received', 'wpdocs_heartbeat_received', 10, 3 );

View the code example on Gist.