. Thanks to Allan Ellegaard for testing and input. */ /* # Word Counts -------------------------------------------------------------- */ load_plugin_textdomain( 'word-stats', '/wp-content/plugins/word-stats/languages/', 'word-stats/languages/' ); // Delete deprecated options if ( get_option( 'ws-counts-cache' ) ) { delete_option( 'ws-counts-cache' ); } // Classes are used to avoid function name collisions // Word Counts class class word_stats_counts { // Count words from all post types and cache the output function cache_word_counts() { $total_count = 0; $cache = ''; $author_count = array(); // Get the post types $args=array( 'public' => true, ); $post_types = get_post_types( $args ); foreach( $post_types as $post_type ) { if ( $post_type != 'attachment' && $post_type != 'nav_menu_item' && $post_type != 'revision' ) { $total_count = 0; $posts = get_posts( array( 'numberposts' => -1, 'post_type' => array( $post_type ) )); foreach( $posts as $post ) { $word_count = str_word_count( strip_tags( get_post_field( 'post_content', $post->ID ) ) ); $total_count += $word_count; // Multidimensional array, stores monthly words per author $author_count[ $post->post_author ][ substr( $post->post_date, 0, 7 ) ] += $word_count; } $num = number_format_i18n( $total_count ); // This adds the word count for each post type to the stats portion of the Right Now box $text = __( 'Words', 'word-stats' ) . ' (' . $post_type . ')'; $cache = $cache . "::opentag::{$num}::separator::{$text}::closetag::"; $total_num += $total_count; } } $text = __( 'Total words', 'word-stats' ); $total_num = number_format_i18n( $total_num ); $cache = $cache . "::totalopentag::{$total_num}::separator::{$text}::closetag::"; update_option( 'ws-total-counts-cache', $cache ); update_option( 'ws-monthly-counts-cache', $author_count ); return $cache; } // Output the cached word counts with the proper HTML tags function get_word_counts( $mode ) { if ( !get_option( 'ws-total-counts-cache' ) ) { $cached = word_stats_counts::cache_word_counts(); } else { $cached = get_option( 'ws-total-counts-cache' ); } if ( $mode == 'table' ) { $cached = str_replace( '::opentag::', '
| ', $author_data->nickname, ' | '; foreach ( $author as $month=>$count ) { echo '|
| ', $month, ' | ', number_format_i18n( $count ), ' |