Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PHP – WordPress – Blog Info

Posted on February 16, 2016 By David Kittell

This is a simple piece of code to provide basic information about your blog.

The first lines of the code will restrict the PHP access to the command line interface (CLI) so not just anyone could/should be able to see the details.

Additional Mime Types can be seen at: http://codex.wordpress.org/Function_Reference/get_allowed_mime_types

php wp-info.php
# php wp-info.php

WordPress Site Name: Test Blog
WordPress Site URL: http://www.testblog.com
WordPress Current Template: twentysixteen
WordPress Admin Email: david@testblog.com

Total Blog Posts: 483
     Auto-Draft Posts: 2
     Draft Posts: 3
     Inherit Posts: 0
     Private Posts: 66
     Publish Posts: 412

Total Blog Pages: 6
     Auto-Draft Pages: 0
     Draft Pages: 1
     Inherit Pages: 0
     Private Pages: 0
     Publish Pages: 5

Total Blog Uploads: 117
     Image Uploads: 113
     Audio Uploads: 0
     Archive Uploads: 2

Total Users: 2
     Administrator Users: 1
     Editor Users: 0
     Author Users: 0
     Contributor Users: 0
     Subscriber Users: 1
<?PHP
	// Restrict access to this file - start
	if (php_sapi_name() != 'cli')
		{
			exit;
		}
	// Restrict access to this file - stop

	require_once('wp-blog-header.php') ;

	echo "\nWordPress Site Name: " . get_option( 'blogname', false);
	echo "\nWordPress Site URL: " . get_option( 'siteurl', false);
	echo "\nWordPress Current Template: " . get_option( 'template', false);
	echo "\nWordPress Admin Email: " . get_option( 'admin_email', false)."\n";

	// WP Database Queries - Start
	require_once('wp-includes/wp-db.php') ;
	
	$post_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post'" );
	echo "\nTotal Blog Posts: {$post_count}";	

	$post_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'auto-draft'" );
	echo "\n     Auto-Draft Posts: {$post_count}";

	$post_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft'" );
	echo "\n     Draft Posts: {$post_count}";

	$post_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'inherit'" );
	echo "\n     Inherit Posts: {$post_count}";

	$post_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'private'" );
	echo "\n     Private Posts: {$post_count}";

	$post_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'" );
	echo "\n     Publish Posts: {$post_count}";

	$page_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page'" );
	echo "\n\nTotal Blog Pages: {$page_count}";	

	$page_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'auto-draft'" );
	echo "\n     Auto-Draft Pages: {$page_count}";

	$page_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'draft'" );
	echo "\n     Draft Pages: {$page_count}";

	$page_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'inherit'" );
	echo "\n     Inherit Pages: {$page_count}";

	$page_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'private'" );
	echo "\n     Private Pages: {$page_count}";

	$page_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'" );
	echo "\n     Publish Pages: {$page_count}";


	$attachment_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'" );
	echo "\n\nTotal Blog Uploads: {$attachment_count}";
	$attachment_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type like '%image%'" );
	echo "\n     Image Uploads: {$attachment_count}";
	$attachment_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type like '%audio%'" );
	echo "\n     Audio Uploads: {$attachment_count}";
	$attachment_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND (post_mime_type = 'application/zip' OR post_mime_type = 'application/x-tar' OR post_mime_type = 'application/x-gzip' OR post_mime_type = 'application/rar' OR post_mime_type = 'application/x-7z-compressed')" );
	echo "\n     Archive Uploads: {$attachment_count}";


	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
	echo "\n\nTotal Users: {$user_count}";

	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users wpu , $wpdb->usermeta wpum WHERE wpum.user_id = wpu.ID AND meta_value like '%administrator%' AND wpum.meta_key = 'wp_capabilities'" );
	echo "\n     Administrator Users: {$user_count}";

	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users wpu , $wpdb->usermeta wpum WHERE wpum.user_id = wpu.ID AND meta_value like '%editor%' AND wpum.meta_key = 'wp_capabilities'" );
	echo "\n     Editor Users: {$user_count}";

	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users wpu , $wpdb->usermeta wpum WHERE wpum.user_id = wpu.ID AND meta_value like '%author%' AND wpum.meta_key = 'wp_capabilities'" );
	echo "\n     Author Users: {$user_count}";

	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users wpu , $wpdb->usermeta wpum WHERE wpum.user_id = wpu.ID AND meta_value like '%contributor%' AND wpum.meta_key = 'wp_capabilities'" );
	echo "\n     Contributor Users: {$user_count}";

	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users wpu , $wpdb->usermeta wpum WHERE wpum.user_id = wpu.ID AND meta_value like '%subscriber%' AND wpum.meta_key = 'wp_capabilities'" );
	echo "\n     Subscriber Users: {$user_count}\n";
	// WP Database Queries - Stop
?>
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PHP WordPress

Post navigation

Previous post
Next post

Related Posts

Android Contacts – Clear Name If It Matches Company Name

Posted on February 21, 2014October 26, 2015

UPDATE data SET data1 = NULL ,data2 = NULL ,data3 = NULL WHERE mimetype_id IN ( SELECT _id FROM mimetypes WHERE mimetype LIKE "%name%" ) AND raw_contact_id IN ( SELECT raw_contact_id FROM data dt1 INNER JOIN mimetypes ON mimetype_id = mimetypes._id WHERE mimetype LIKE "%name%" AND length(data1) > 0 AND…

Read More

Ektron Menu Item List

Posted on July 30, 2015October 26, 2015

List out all items in an Ektron menu SELECT mt.[mnu_id] AS ‘Menu ID’ ,mnu_name AS ‘Menu Name’ ,[item_title] AS ‘Menu Item Title’ ,[item_link] ,CASE [item_target] WHEN 1 THEN ‘Popup’ WHEN 2 THEN ‘Self’ WHEN 3 THEN ‘Parent’ WHEN 4 THEN ‘Top’ END AS ‘Item Target’ , –[item_target], [item_id] AS ‘Content…

Read More

Mac OSX Terminal – Get Artist and Song From iTunes PlayList Export

Posted on December 28, 2016March 6, 2017

There are more elegant ways to do this but I got bored and thought I’d do something that is only done with base Mac OSX tools #!/bin/sh # Read_iTunes_PlayList.sh # # Get only the artist list – remove duplicates # Read_iTunes_PlayList.sh 1 iTunesPlayListFileName ~/Desktop # # Get Artist and Song…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes