Plugin Directory

Changeset 1035581


Ignore:
Timestamp:
11/30/2014 07:21:30 PM (11 years ago)
Author:
yingles
Message:

Fixes issue with not calculating the correct reading time when using more tags

Location:
reading-time-wp/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • reading-time-wp/trunk/readme.txt

    r1031470 r1035581  
    55Requires at least: 3.0.1
    66Tested up to: 4.0
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5454== Changelog ==
    5555
     56= 1.0.2 =
     57* Fixing bug with more tags in the_content
     58
    5659= 1.0.1 =
    5760* Converting the plugin to a class based structure
     
    6770= 1.0.1 =
    6871This update converts the plugin into a class based structure for better expandability in the future.
     72
     73= 1.0.2 =
     74Fixes issue with miscalculated reading time when using <!--more--> tags
  • reading-time-wp/trunk/rt-reading-time.php

    r1031470 r1035581  
    44 * Plugin URI: http://jasonyingling.me/reading-time-wp/
    55 * Description: Add an estimated reading time to your posts.
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Author: Jason Yingling
    88 * Author URI: http://jasonyingling.me
     
    2929   
    3030    // Add label option using add_option if it does not already exist
     31    public $readingTime;
    3132   
    3233    public function __construct() {
     
    5152    }
    5253   
     54    public function rt_calculate_reading_time($rtPostID, $rtOptions) {
     55       
     56        $rtContent = get_post_field('post_content', $rtPostID);
     57        $strippedContent = strip_shortcodes($rtContent);
     58        $wordCount = str_word_count($strippedContent);
     59        $this->readingTime = ceil($wordCount / $rtOptions['wpm']);
     60       
     61        return $this->readingTime;
     62       
     63    }
     64   
    5365    public function rt_reading_time($atts, $content = null) {
    5466   
     
    6072        $rtReadingOptions = get_option('rt_reading_time_options');
    6173       
    62         $rtPostID = get_the_ID();
    63         $rtContent = get_the_content($rtPostID);
    64         $strippedContent = strip_shortcodes($rtContent);
    65         $wordCount = str_word_count($strippedContent);
    66         $readingTime = ceil($wordCount / $rtReadingOptions['wpm']);
     74        $rtPost = get_the_ID();
     75       
     76        $this->rt_calculate_reading_time($rtPost, $rtReadingOptions);
    6777       
    6878        return "
    69         <span class='span-reading-time'>$label $readingTime $postfix</span>
     79        <span class='span-reading-time'>$label $this->readingTime $postfix</span>
    7080        ";
    7181    }
     
    8292    // Calculate reading time by running it through the_content
    8393    public function rt_add_reading_time_before_content($content) {
     94        $rtReadingOptions = get_option('rt_reading_time_options');
     95
     96        $originalContent = $content;
     97        $rtPost = get_the_ID();
    8498       
    85         $rtReadingOptions = get_option('rt_reading_time_options');
    86        
    87         $originalContent = $content;
    88         $strippedContent = strip_shortcodes($originalContent);
    89         $wordCount = str_word_count($strippedContent);
    90         $readingTime = ceil($wordCount / $rtReadingOptions['wpm']);
    91        
     99        $this->rt_calculate_reading_time($rtPost, $rtReadingOptions);
     100               
    92101        $label = $rtReadingOptions['label'];
    93102        $postfix = $rtReadingOptions['postfix'];
    94103       
    95         $content = '<div class="rt-reading-time">'.'<span class="rt-label">'.$label.'</span>'.'<span class="rt-time">'.$readingTime.'</span>'.'<span class="rt-label"> '.$postfix.'</span>'.'</div>';
     104        $content = '<div class="rt-reading-time">'.'<span class="rt-label">'.$label.'</span>'.'<span class="rt-time">'.$this->readingTime.'</span>'.'<span class="rt-label"> '.$postfix.'</span>'.'</div>';
    96105        $content .= $originalContent;
    97106        return $content;
Note: See TracChangeset for help on using the changeset viewer.