Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active August 4, 2016 19:39
Show Gist options
  • Save lukecav/4b0ee289986e51bb312bc5b8c0766052 to your computer and use it in GitHub Desktop.
Save lukecav/4b0ee289986e51bb312bc5b8c0766052 to your computer and use it in GitHub Desktop.
WP-CLI - Digest command
/**
* Display Digest of Info.
*
* @param null $args Unused.
* @param array $assoc_args Unused.
*/
public function digest( $args, $assoc_args ) {
global $wpdb;
global $wp_version;
$details = array();
$details['WP VERSION'] = $wp_version;
$details['PHP VERSION'] = phpversion();
$details['MYSQL VERSION'] = $wpdb->get_var( 'SHOW VARIABLES LIKE "version";', 1 );
$details['ACTIVE THEME'] = get_option( 'stylesheet' );
$details['ACTIVE PLUGINS'] = count( get_option( 'active_plugins' ) );
$details['TOTAL PLUGINS'] = count( get_plugins() );
$details['TOTAL THEMES'] = count( wp_get_themes() );
$details['TOTAL POSTS'] = count( get_posts( array( 'post_type' => 'post' ) ) );
$details['TOTAL PAGES'] = count( get_posts( array( 'post_type' => 'page' ) ) );
$details['TOTAL MEDIA'] = count( get_posts( array( 'post_type' => 'attachment' ) ) );
$comments_count = wp_count_comments();
$details['TOTAL COMMENTS'] = $comments_count->total_comments;
$details['COMMENTS APPROVED'] = $comments_count->approved;
$details['COMMENTS MODERATION'] = $comments_count->moderated;
$details['COMMENTS SPAM'] = $comments_count->spam;
$details['COMMENTS TRASHED'] = $comments_count->trash;
$options = wp_load_alloptions();
$all_transients = 0;
$all_options = 0;
foreach ( $options as $name => $value ) {
if ( false !== strpos( $name, 'transient' ) ) {
$all_transients++;
} else {
$all_options++;
}
}
$details['ALL OPTIONS'] = $all_options;
$details['ALL TRANSIENTS'] = $all_transients;
$output = ' +' . str_pad( '', 21, '-' ) . '+' . str_pad( '', 32, '-' ) . "+ \n";
$output .= ' |' . str_pad( 'NAME ', 21, ' ', STR_PAD_LEFT ) . '|' . str_pad( 'VALUE ', 32, ' ', STR_PAD_LEFT ) . "| \n";
$output .= ' +' . str_pad( '', 21, '-' ) . '+' . str_pad( '', 32, '-' ) . "+ \n";
foreach ( $details as $name => $value ) {
$output .= ' |' . str_pad( $name, 20, ' ', STR_PAD_LEFT ) . ' | ' . str_pad( $value, 30, ' ', STR_PAD_LEFT ) . " | \n";
}
$output .= ' +' . str_pad( '', 21, '-' ) . '+' . str_pad( '', 32, '-' ) . "+ \n";
echo $output;
}
}
WP_CLI::add_command( 'new', 'WP_NEW_Commands' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment