Changeset 1035581
- Timestamp:
- 11/30/2014 07:21:30 PM (11 years ago)
- Location:
- reading-time-wp/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
rt-reading-time.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
reading-time-wp/trunk/readme.txt
r1031470 r1035581 5 5 Requires at least: 3.0.1 6 6 Tested up to: 4.0 7 Stable tag: 1.0. 07 Stable tag: 1.0.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 54 54 == Changelog == 55 55 56 = 1.0.2 = 57 * Fixing bug with more tags in the_content 58 56 59 = 1.0.1 = 57 60 * Converting the plugin to a class based structure … … 67 70 = 1.0.1 = 68 71 This update converts the plugin into a class based structure for better expandability in the future. 72 73 = 1.0.2 = 74 Fixes issue with miscalculated reading time when using <!--more--> tags -
reading-time-wp/trunk/rt-reading-time.php
r1031470 r1035581 4 4 * Plugin URI: http://jasonyingling.me/reading-time-wp/ 5 5 * Description: Add an estimated reading time to your posts. 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 * Author: Jason Yingling 8 8 * Author URI: http://jasonyingling.me … … 29 29 30 30 // Add label option using add_option if it does not already exist 31 public $readingTime; 31 32 32 33 public function __construct() { … … 51 52 } 52 53 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 53 65 public function rt_reading_time($atts, $content = null) { 54 66 … … 60 72 $rtReadingOptions = get_option('rt_reading_time_options'); 61 73 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); 67 77 68 78 return " 69 <span class='span-reading-time'>$label $ readingTime $postfix</span>79 <span class='span-reading-time'>$label $this->readingTime $postfix</span> 70 80 "; 71 81 } … … 82 92 // Calculate reading time by running it through the_content 83 93 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(); 84 98 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 92 101 $label = $rtReadingOptions['label']; 93 102 $postfix = $rtReadingOptions['postfix']; 94 103 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>'; 96 105 $content .= $originalContent; 97 106 return $content;
Note: See TracChangeset
for help on using the changeset viewer.