Changeset 1031470
- Timestamp:
- 11/24/2014 02:28:09 AM (11 years ago)
- Location:
- reading-time-wp/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
rt-reading-time.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
reading-time-wp/trunk/readme.txt
r1026099 r1031470 54 54 == Changelog == 55 55 56 = 1.0.1 = 57 * Converting the plugin to a class based structure 58 56 59 = 1.0.0 = 57 60 * Initial release … … 61 64 = 1.0 = 62 65 Initial release 66 67 = 1.0.1 = 68 This update converts the plugin into a class based structure for better expandability in the future. -
reading-time-wp/trunk/rt-reading-time.php
r1026094 r1031470 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. 06 * Version: 1.0.1 7 7 * Author: Jason Yingling 8 8 * Author URI: http://jasonyingling.me … … 26 26 */ 27 27 28 29 // Add label option using add_option if it does not already exist 30 $defaultSettings = array( 31 'label' => 'Reading Time: ', 32 'postfix' => 'minutes', 33 'wpm' => 300, 34 'before_content' => 'true', 35 ); 36 37 add_option('rt_reading_time_options', $defaultSettings); 38 39 $rtReadingOptions = get_option('rt_reading_time_options'); 40 41 // Functions to create Reading Time admin pages 42 function rt_reading_time_admin() { 43 include('rt-reading-time-admin.php'); 28 class readingTimeWP { 29 30 // Add label option using add_option if it does not already exist 31 32 public function __construct() { 33 $defaultSettings = array( 34 'label' => 'Reading Time: ', 35 'postfix' => 'minutes', 36 'wpm' => 300, 37 'before_content' => 'true', 38 ); 39 40 $rtReadingOptions = get_option('rt_reading_time_options'); 41 42 add_shortcode( 'rt_reading_time', array($this, 'rt_reading_time') ); 43 add_option('rt_reading_time_options', $defaultSettings); 44 add_action('admin_menu', array($this, 'rt_reading_time_admin_actions')); 45 46 if ($rtReadingOptions['before_content'] === 'true') { 47 48 add_filter('the_content', array($this, 'rt_add_reading_time_before_content')); 49 50 } 51 } 52 53 public function rt_reading_time($atts, $content = null) { 54 55 extract (shortcode_atts(array( 56 'label' => '', 57 'postfix' => '', 58 ), $atts)); 59 60 $rtReadingOptions = get_option('rt_reading_time_options'); 61 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']); 67 68 return " 69 <span class='span-reading-time'>$label $readingTime $postfix</span> 70 "; 71 } 72 73 // Functions to create Reading Time admin pages 74 public function rt_reading_time_admin() { 75 include('rt-reading-time-admin.php'); 76 } 77 78 public function rt_reading_time_admin_actions() { 79 add_options_page("Reading Time WP Settings", "Reading Time WP", "manage_options", "rt-reading-time-settings", array($this, "rt_reading_time_admin")); 80 } 81 82 // Calculate reading time by running it through the_content 83 public function rt_add_reading_time_before_content($content) { 84 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 92 $label = $rtReadingOptions['label']; 93 $postfix = $rtReadingOptions['postfix']; 94 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>'; 96 $content .= $originalContent; 97 return $content; 98 } 99 44 100 } 45 101 46 function rt_reading_time_admin_actions() { 47 add_options_page("Reading Time WP Settings", "Reading Time WP", "manage_options", "rt-reading-time-settings", "rt_reading_time_admin"); 48 } 49 50 add_action('admin_menu', 'rt_reading_time_admin_actions'); 51 52 // Calculate reading time by running it through the_content 53 function rt_add_reading_time_before_content($content) { 54 55 $rtReadingOptions = get_option('rt_reading_time_options'); 56 57 $originalContent = $content; 58 $strippedContent = strip_shortcodes($originalContent); 59 $wordCount = str_word_count($strippedContent); 60 $readingTime = ceil($wordCount / $rtReadingOptions['wpm']); 61 62 $label = $rtReadingOptions['label']; 63 $postfix = $rtReadingOptions['postfix']; 64 65 $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>'; 66 $content .= $originalContent; 67 return $content; 68 } 69 70 if ($rtReadingOptions['before_content'] === 'true') { 71 72 add_filter('the_content', 'rt_add_reading_time_before_content'); 73 74 } 75 76 // Shortcode for inserting reading time 77 function rt_reading_time($atts, $content = null) { 78 79 extract (shortcode_atts(array( 80 'label' => '', 81 'postfix' => '', 82 ), $atts)); 83 84 $rtReadingOptions = get_option('rt_reading_time_options'); 85 86 $rtPostID = get_the_ID(); 87 $rtContent = get_the_content($rtPostID); 88 $strippedContent = strip_shortcodes($rtContent); 89 $wordCount = str_word_count($strippedContent); 90 $readingTime = ceil($wordCount / $rtReadingOptions['wpm']); 91 92 return " 93 <span class='span-reading-time'>$label $readingTime $postfix</span> 94 "; 95 } 96 97 add_shortcode( 'rt_reading_time', 'rt_reading_time' ); 102 $readingTimeWP = new readingTimeWP(); 98 103 99 104 ?>
Note: See TracChangeset
for help on using the changeset viewer.