Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments

The new Site Activity dashboard widget defaults to showing 5 comments. I’d like to show 10.

I can see the code in core /wp-admin/includes/dashboard.php where it calls the function wp_dashboard_site_activity, and uses wp_dashboard_recent_comments ( $total_items = 5 ). But I don’t know the syntax to hook into this function to update it.

I know how to create a custom functionality plugin & edit functions.php, I’m just unsure of the syntax and/or hook to use.

Any help is greatly appreciated. Thanks.

1
1

Seems like there is no filter for this (yet), but you can unregister the default activity widget and register (within your functions, or even better within your plugin as recommended by Dave Warfel) a similar activity widget with your custom settings:

// unregister the default activity widget
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
function remove_dashboard_widgets() {

    global $wp_meta_boxes;
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);

}

// register your custom activity widget
add_action('wp_dashboard_setup', 'add_custom_dashboard_activity' );
function add_custom_dashboard_activity() {
    wp_add_dashboard_widget('custom_dashboard_activity', 'Activity', 'custom_wp_dashboard_site_activity');
}

function custom_wp_dashboard_site_activity() {

    echo '<div id="activity-widget">';

    $future_posts = wp_dashboard_recent_posts( array(
        'display' => 2,
        'max'     => 5,
        'status'  => 'future',
        'order'   => 'ASC',
        'title'   => __( 'Publishing Soon' ),
        'id'      => 'future-posts',
    ) );

    $recent_posts = wp_dashboard_recent_posts( array(
        'display' => 2,
        'max'     => 5,
        'status'  => 'publish',
        'order'   => 'DESC',
        'title'   => __( 'Recently Published' ),
        'id'      => 'published-posts',
    ) );

    $recent_comments = wp_dashboard_recent_comments( 10 );

    if ( !$future_posts && !$recent_posts && !$recent_comments ) {
        echo '<div class="no-activity">';
        echo '<p class="smiley"></p>';
        echo '<p>' . __( 'No activity yet!' ) . '</p>';
        echo '</div>';
    }

    echo '</div>';

}

Leave a Comment