Plugin Directory

Changeset 1303349

Timestamp:
12/08/2015 10:53:39 PM (9 years ago)
Author:
nickmomrik
Message:

Coding stardards cleanup and bump to 1.2.

Location:
post-word-count
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • post-word-count/trunk/post-word-count.php

    r155541 r1303349  
    44Plugin URI: http://wordpress.org/extend/plugins/post-word-count/
    55Description: Outputs the total number of words in all posts or the number of words in a single post.
    6 Version: 1.1
     6Version: 1.
    77Author: Nick Momrik
    88Author URI: http://nickmomrik.com/
    99*/
    1010
    11 function mdv_post_word_count($single = false) {
     11function mdv_post_word_count() {
    1212    global $wpdb, $id;
    13     $now = gmdate("Y-m-d H:i:s",time());
     13    $now = gmdate();
    1414
    15     if ($single) $query = "SELECT post_content FROM $wpdb->posts WHERE ID = '$id'";
    16     else $query = "SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now'";
     15    if ( $single ) {
     16        $query = $wpdb->prepare( "SELECT post_content FROM $wpdb->posts WHERE ID = %d", $id );
     17    } else {
     18        $query = $wpdb->prepare( "SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < %s", $now );
     19    }
    1720   
    18     $words = $wpdb->get_results($query);
    19     if ($words) {
    20         foreach ($words as $word) {
    21             $post = strip_tags($word->post_content);
    22             $post = explode(' ', $post);
    23             $count = count($post);
     21    $words = $wpdb->get_results( $query );
     22    if ( $words ) {
     23        $oldcount = 0;
     24        foreach ( $words as $word ) {
     25            $post = strip_tags( $word->post_content );
     26            $post = explode( ' ', $post );
     27            $count = count( $post );
    2428            $totalcount = $count + $oldcount;
    2529            $oldcount = $totalcount;
    2630        }
    2731    } else {
    28         $totalcount=0;
     32        $totalcount0;
    2933    }
    30     echo number_format($totalcount);
     34
     35    echo number_format( $totalcount );
    3136}
    32 ?>
  • post-word-count/trunk/readme.txt

    r1303343 r1303349  
    22Contributors: nickmomrik
    33Tags: posts, count, words
    4 Stable tag: 1.1
     4Stable tag: 1.2
     5Tested up to: 4.4
    56
    67Counts the total number of words in all posts or the number of words in a single post.
     
    1415The default is to count the total number of words in all posts. If you would like the number of words displayed for a particular post or page, use the following inside "the loop"
    1516
    16 `<?php mdv_post_word_count(true); ?>`
     17`<?php mdv_post_word_count(); ?>`
Note: See TracChangeset for help on using the changeset viewer.