sandywp / plugins / wp-stats

WP-Stats

2.6 out of 5 stars. 2.6 7 reviews

Display your WordPress blog statistics. Ranging from general total statistics, some of my plugins statistics and top 10 statistics.

Launch a sandbox with this plugin → No signup.
Ready in seconds.

v3.0.1 2,000+ installs WP 6.8+ PHP 8.2+

your-sandbox.sandywp.com/wp-admin
WP-Stats running inside a SandyWP sandbox

What you get inside

4 screens
  • Stats -> Statistics: the site, then a section for every plugin that contributes one

  • The Settings tab, which chooses what the report and the widget carry

  • The stats page a visitor sees, from the shortcode

  • The widget, in a sidebar

About this plugin

WP-Stats builds a statistics page for your blog out of what is already in your database: how many posts, pages, comments, tags, categories and links there are, which posts drew the most comments, who has commented most often, and who writes for you. Put the [page_stats] shortcode on a page and that page becomes your statistics page. There is a sidebar widget for the totals, and the same statistics appear in wp-admin under WP-Stats.

Other plugins of mine can add their own blocks to that page. WP-Stats does not need to know anything about them in advance and never reads their settings.

Features

  • A full statistics page from one shortcode
  • Totals for posts, pages, comments, commenters, tags, categories, links and authors
  • Top X most commented posts and pages, most recent posts and most recent comments
  • A per-commenter view listing every comment somebody has left, with paging
  • A sidebar widget for the totals
  • Every block can be switched off individually

Donations

I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.

Usage

Create The Stats Page

  1. Go to WP-Admin -> Pages -> Add New
  2. Type any title you like in the page’s title area
  3. If you ARE using nice permalinks, WordPress will generate the permalink to the page after you type the title. You will see an ‘Edit’ link just beside the permalink.
  4. Click ‘Edit’, type in stats in the text field and click ‘Save’.
  5. Type [page_stats] in the page’s content area
  6. Click ‘Publish’
  7. If you ARE NOT using nice permalinks, go to WP-Admin -> WP-Stats, open the Settings tab and fill in ‘Stats URL’ with the URL of the page you just created.

The Block

Blog Statistics is in the editor’s inserter, under Widgets. Add it to a page and that page is your statistics page — there is nothing to configure on the block itself, because what the page shows comes from the settings and from whichever companion plugins are installed, not from the post.

It renders on the server, so the preview in the editor is the real page rather than an approximation, and the numbers are counted afresh on every view rather than frozen into the post when you save it.

The shortcode still works and is not going anywhere. [page_stats] behaves exactly as it always has, and a page already containing it needs no change. The block calls the same code the shortcode calls, so the two render identically — including the blocks other plugins contribute — and you can use whichever suits the page.

The Widget

  1. Go to WP-Admin -> Appearance -> Widgets
  2. The widget name is Stats.

For Plugin Authors

A plugin adds a block to the statistics page by answering one filter. Return an entry keyed by your own slug with underscores:

add_filter( 'wp_stats_sections', function ( $sections ) {
    $options = get_option( 'my_plugin_options', array() );

    if ( empty( $options['stats_display'] ) ) {
        return $sections;   // the site owner switched this block off
    }

    $sections['my_plugin'] = array(
        'title'    => __( 'My Plugin', 'my-plugin' ),
        'priority' => 10,
        'render'   => 'my_plugin_render_stats',
    );

    return $sections;
} );

function my_plugin_render_stats() {
    echo '<ul><li>42 things.</li></ul>';
}
title is a translated heading and is required. `render` is a callable that echoes the block body, takes no arguments, and is required. `priority` sorts the blocks and defaults to 10; ties are broken by the array key.

Decide out of your own settings whether to contribute at all, and return $sections untouched if the answer is no rather than adding an entry with an empty body. WP-Stats never reads another plugin’s option row and never checks whether your classes exist — if your plugin is not installed, nothing answers the filter and no block appears.

WP-Stats then fires wp_stats_section_my_plugin with your entry. Its own listener on that action is what prints the heading and calls render, so a theme can take one plugin’s block over without disturbing the others:

add_action( 'wp_stats_section_my_plugin', function ( $section ) {
    remove_action( 'wp_stats_section_my_plugin', array( 'WP_Stats_Page', 'render_section' ) );
    echo '<p>drawn by the theme instead</p>';
}, 5 );

An entry that is malformed — not an array, no title, a render that is not callable — is skipped. It will not take the page down, and it will not tell you either, so check your block appears.

Questions

Which options does the plugin store?

Two rows. wp_stats_options holds the stats page URL, the “top X” limit and the display toggles; wp_stats_version records the version last run so an upgrade knows what it is upgrading from. Deleting the plugin from the Plugins screen removes both.

I have a plugin that reads `get_option( ‘stats_display’ )`. Will it break?

Yes. That row is deleted during the upgrade, and 3.0.0 no longer answers for it. Seven plugins used to share it, which meant none of them could change how it was stored without breaking the other six. Keep your own copy of the setting in your own option row and answer wp_stats_sections — see “For Plugin Authors” above.

The Plugins Stats heading has disappeared

It only appears now when a plugin has actually contributed a block. Before 3.0.0 it was printed whether or not there was anything under it.

Why do my author counts look different?

“Authors” now means the users who can publish posts, which is what the block always claimed to count. It used to be derived from the legacy user_level meta, and it excluded anyone with a password reset in progress.

My own code renders the stats page and it comes out unstyled

The stylesheet loads only where WP-Stats can see the page coming: a [page_stats]
shortcode or the block in the post being viewed, or the widget in a sidebar. It is
enqueued from the head and nowhere else, so a theme calling WP_Stats_Page::render()
itself, or markup fetched over admin-ajax.php into a page carrying none of the three,
gets no stylesheet — and the paging strip in the per-commenter view is what that
stylesheet is for.

Say so from the page that will hold it:

add_filter( 'wp_stats_needs_styles', '__return_true' );

2.6

7 reviews

  • 5 ★ 2
  • 4 ★ 1
  • 3 ★ 0
  • 2 ★ 0
  • 1 ★ 4

Ratings come from WordPress.org. SandyWP does not collect its own reviews.

sandywp / also on the shelf

Try another plugin

  • WP Server Health Stats

    4.8 · 9K+ installs

    Monitor your WP site the right way with most important stats like Database, PHP details, PHP Memory, RAM Usage, CPU load, Server…

  • Homepage Helden Contact Info

    5.0 · 200+ installs

    Contact information for Homepage Helden GmbH clients - displayed directly on your Wordpress dashboard for quick support

  • bbp profile information

    4.3 · 100+ installs

    For bbPress - adds fields to the bbp user profile and displays any combination of these under the authors avatar in topics and…

Spin up a real WordPress site in seconds.

Test plugins, build a demo, hand a client a link — then squash it and start again. No local setup, no Docker.