Changeset 958672
- Timestamp:
- 08/01/2014 01:51:32 PM (12 years ago)
- Location:
- excerpt-tools
- Files:
-
- 2 edited
- 10 copied
-
tags/0.4 (copied) (copied from excerpt-tools/trunk)
-
tags/0.4/excerpt-tools.php (copied) (copied from excerpt-tools/trunk/excerpt-tools.php) (1 diff)
-
tags/0.4/readme.txt (copied) (copied from excerpt-tools/trunk/readme.txt)
-
tags/0.4/screenshot-1.png (copied) (copied from excerpt-tools/trunk/screenshot-1.png)
-
tags/0.4/screenshot-2.png (copied) (copied from excerpt-tools/trunk/screenshot-2.png)
-
tags/0.5 (copied) (copied from excerpt-tools/trunk)
-
tags/0.5/excerpt-tools.php (copied) (copied from excerpt-tools/trunk/excerpt-tools.php) (5 diffs)
-
tags/0.5/readme.txt (copied) (copied from excerpt-tools/trunk/readme.txt) (2 diffs)
-
tags/0.5/screenshot-1.png (copied) (copied from excerpt-tools/trunk/screenshot-1.png)
-
tags/0.5/screenshot-2.png (copied) (copied from excerpt-tools/trunk/screenshot-2.png)
-
trunk/excerpt-tools.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
excerpt-tools/tags/0.4/excerpt-tools.php
r926472 r958672 2 2 /* 3 3 Plugin Name: Excerpt Tools 4 Plugin URI: http://www.bang-on.net/ 4 5 Description: Customize your excerpts. Allows you to limit the length of excerpts with a jQuery character counter, display a custom title and description for the excerpt box and show the excerpt box on pages. 5 6 Author: Marcus Downing and Zack Kakia 7 Author URI: http://www.bang-on.net/ 6 8 Version: 0.4 7 9 */ -
excerpt-tools/tags/0.5/excerpt-tools.php
r926472 r958672 1 1 <?php 2 3 namespace Bang\excerpt_tools; 2 4 /* 3 5 Plugin Name: Excerpt Tools 6 Plugin URI: http://www.bang-on.net/ 4 7 Description: Customize your excerpts. Allows you to limit the length of excerpts with a jQuery character counter, display a custom title and description for the excerpt box and show the excerpt box on pages. 5 8 Author: Marcus Downing and Zack Kakia 6 Version: 0.4 9 Author URI: http://www.bang-on.net/ 10 Version: 0.5 7 11 */ 8 12 9 13 $jscounter = plugins_url( 'js/jquery.charcounter.js', __FILE__ ); 10 14 11 add_action('admin_init', 'e_tools_box_init');15 add_action('admin_init', __NAMESPACE__.'\box_init'); 12 16 13 17 // Checks options to see if custom excerpts are turned on. if so, adds them 14 function e_tools_box_init() {18 function box_init() { 15 19 $options = get_option('e_tools'); 16 20 do_action('log', 'Excerpt tools: init', $options); … … 21 25 22 26 foreach (get_post_types(array(), 'objects') as $post_type) { 23 if ( $options['enable_'.$post_type->name] == 1) {27 if (isset($options['enable_'.$post_type->name]) && $options['enable_'.$post_type->name] == 1) { 24 28 do_action('log', 'Excerpt tools: Add meta box', $post_type->name, $title); 25 29 remove_meta_box('postexcerpt', $post_type->name, 'core'); 26 add_meta_box('e_tools_excerpt', $title, 'e_tools_meta_box', $post_type->name, 'normal', 'high');30 add_meta_box('e_tools_excerpt', $title, __NAMESPACE__.'\meta_box', $post_type->name, 'normal', 'high'); 27 31 } 28 32 } 29 33 } 30 34 31 add_action('admin_init', 'e_tools_init'); 32 add_action('admin_menu', 'e_tools_add_page'); 35 add_action('init', __NAMESPACE__.'\init'); 36 add_action('admin_init', __NAMESPACE__.'\admin_init'); 37 add_action('admin_menu', __NAMESPACE__.'\add_page'); 33 38 34 39 // Init plugin options to white list our options 35 function e_tools_init() {40 function admin_init() { 36 41 register_setting('e_tools_options', 'e_tools'); 37 42 } 38 43 39 44 // Add menu page 40 function e_tools_add_page() { 41 add_options_page('Excerpt Options', 'Excerpt Tools', 'manage_options', 'e_tools_handler', 'e_tools_page'); 45 function add_page() { 46 add_options_page('Excerpt Options', 'Excerpt Tools', 'manage_options', 'e_tools_handler', __NAMESPACE__.'\settings_page'); 47 } 48 49 // Check if we need to adjust all excerpts 50 function init() { 51 $options = get_option('e_tools'); 52 if ($options['enforce_length']) { 53 add_filter('wp_trim_excerpt', __NAMESPACE__.'\filter_trim_excerpt', 11, 2); 54 add_filter('option_relevanssi_excerpt_length', __NAMESPACE__.'\option_relevanssi_excerpt_length', 99); 55 } 56 } 57 58 function filter_trim_excerpt($excerpt, $raw) { 59 do_action('log', 'wp_trim_excerpt', '@filter', 'wp_trim_excerpt'); 60 61 $options = get_option('e_tools'); 62 $len = intval($options['excerpt_length']); 63 64 if (mb_strlen($excerpt) > $len) { 65 $short = mb_substr($excerpt, 0, $len + 1); 66 $pos = mb_strrpos($short, ' '); 67 do_action('log', 'trim excerpt: excerpt length = %s; desired length = %s; found space at %s: "%s%', mb_strlen($excerpt), $len, $pos, $short); 68 if ($pos !== false && $pos > 0) 69 $excerpt = mb_substr($short, 0, $pos); 70 else 71 $excerpt = $short; 72 } 73 74 return $excerpt; 75 } 76 77 function option_relevanssi_excerpt_length($length) { 78 $options = get_option('e_tools'); 79 $len = intval($options['excerpt_length']); 80 if ($length > $len) $length = $len; 81 return $length; 42 82 } 43 83 44 84 // Draw the menu page itself 45 function e_tools_page() {85 function settings_page() { 46 86 global $jscounter; 47 87 $options = get_option('e_tools'); … … 85 125 $i++; 86 126 echo "<td><label for='e_tools_enable_$key'>"; 87 echo "<input type='checkbox' name='e_tools[enable_$key]' id='e_tools_enable_$key' value='1' "; checked( '1', $options["enable_$key"]); echo ">";127 echo "<input type='checkbox' name='e_tools[enable_$key]' id='e_tools_enable_$key' value='1' "; checked(isset($options["enable_$key"]) && intval($options["enable_$key"])); echo ">"; 88 128 if (isset($post_type_icons[$key])) 89 129 echo " <i class='dashicons ${post_type_icons[$key]}'></i> "; … … 98 138 $length = $len; 99 139 } 140 141 $enforce_length = isset($options['enforce_length']) && (boolean) $options['enforce_length']; 100 142 ?> 101 143 102 144 <tr valign="top"> 103 145 <th scope="row"><?php _e('Excerpt Length', 'excerpt-tools'); ?></th> 104 <td><input type="text" name="e_tools[excerpt_length]" id='excerpt_length' value="<?php echo $length; ?>" placeholder='150' style='text-align: right; width: 4em;' /> characters</td> 146 <td><input type="text" name="e_tools[excerpt_length]" id='excerpt_length' value="<?php echo $length; ?>" placeholder='150' style='text-align: right; width: 4em;' /> characters 147 <p><label for='enforce_length'><input type='checkbox' name='e_tools[enforce_length]' id='enforce_length' <?php checked($enforce_length); ?>> 148 <?php _e('Enforce this length limit on all excerpts', 'excerpt-tools'); ?></p></td> 105 149 </tr> 106 150 … … 133 177 134 178 135 function e_tools_meta_box($post) {179 function meta_box($post) { 136 180 wp_enqueue_script('jquery'); 137 181 $options = get_option('e_tools'); -
excerpt-tools/tags/0.5/readme.txt
r926472 r958672 20 20 3. Configure your options under the "Excerpt Tools" item in the Settings menu. 21 21 22 === Requirements === 23 24 Note that from version 0.5, this plugin requires PHP version 5.3 or above. 25 22 26 ==Screenshots== 23 27 … … 26 30 27 31 == Changelog == 32 33 = 0.5 = 34 * Moved to a new namespace (requires PHP 5.3) 35 * Added option to enforce excerpt length 36 * Set excerpt length with Relevanssi as well 28 37 29 38 = 0.4 = -
excerpt-tools/trunk/excerpt-tools.php
r926472 r958672 1 1 <?php 2 3 namespace Bang\excerpt_tools; 2 4 /* 3 5 Plugin Name: Excerpt Tools 6 Plugin URI: http://www.bang-on.net/ 4 7 Description: Customize your excerpts. Allows you to limit the length of excerpts with a jQuery character counter, display a custom title and description for the excerpt box and show the excerpt box on pages. 5 8 Author: Marcus Downing and Zack Kakia 6 Version: 0.4 9 Author URI: http://www.bang-on.net/ 10 Version: 0.5 7 11 */ 8 12 9 13 $jscounter = plugins_url( 'js/jquery.charcounter.js', __FILE__ ); 10 14 11 add_action('admin_init', 'e_tools_box_init');15 add_action('admin_init', __NAMESPACE__.'\box_init'); 12 16 13 17 // Checks options to see if custom excerpts are turned on. if so, adds them 14 function e_tools_box_init() {18 function box_init() { 15 19 $options = get_option('e_tools'); 16 20 do_action('log', 'Excerpt tools: init', $options); … … 21 25 22 26 foreach (get_post_types(array(), 'objects') as $post_type) { 23 if ( $options['enable_'.$post_type->name] == 1) {27 if (isset($options['enable_'.$post_type->name]) && $options['enable_'.$post_type->name] == 1) { 24 28 do_action('log', 'Excerpt tools: Add meta box', $post_type->name, $title); 25 29 remove_meta_box('postexcerpt', $post_type->name, 'core'); 26 add_meta_box('e_tools_excerpt', $title, 'e_tools_meta_box', $post_type->name, 'normal', 'high');30 add_meta_box('e_tools_excerpt', $title, __NAMESPACE__.'\meta_box', $post_type->name, 'normal', 'high'); 27 31 } 28 32 } 29 33 } 30 34 31 add_action('admin_init', 'e_tools_init'); 32 add_action('admin_menu', 'e_tools_add_page'); 35 add_action('init', __NAMESPACE__.'\init'); 36 add_action('admin_init', __NAMESPACE__.'\admin_init'); 37 add_action('admin_menu', __NAMESPACE__.'\add_page'); 33 38 34 39 // Init plugin options to white list our options 35 function e_tools_init() {40 function admin_init() { 36 41 register_setting('e_tools_options', 'e_tools'); 37 42 } 38 43 39 44 // Add menu page 40 function e_tools_add_page() { 41 add_options_page('Excerpt Options', 'Excerpt Tools', 'manage_options', 'e_tools_handler', 'e_tools_page'); 45 function add_page() { 46 add_options_page('Excerpt Options', 'Excerpt Tools', 'manage_options', 'e_tools_handler', __NAMESPACE__.'\settings_page'); 47 } 48 49 // Check if we need to adjust all excerpts 50 function init() { 51 $options = get_option('e_tools'); 52 if ($options['enforce_length']) { 53 add_filter('wp_trim_excerpt', __NAMESPACE__.'\filter_trim_excerpt', 11, 2); 54 add_filter('option_relevanssi_excerpt_length', __NAMESPACE__.'\option_relevanssi_excerpt_length', 99); 55 } 56 } 57 58 function filter_trim_excerpt($excerpt, $raw) { 59 do_action('log', 'wp_trim_excerpt', '@filter', 'wp_trim_excerpt'); 60 61 $options = get_option('e_tools'); 62 $len = intval($options['excerpt_length']); 63 64 if (mb_strlen($excerpt) > $len) { 65 $short = mb_substr($excerpt, 0, $len + 1); 66 $pos = mb_strrpos($short, ' '); 67 do_action('log', 'trim excerpt: excerpt length = %s; desired length = %s; found space at %s: "%s%', mb_strlen($excerpt), $len, $pos, $short); 68 if ($pos !== false && $pos > 0) 69 $excerpt = mb_substr($short, 0, $pos); 70 else 71 $excerpt = $short; 72 } 73 74 return $excerpt; 75 } 76 77 function option_relevanssi_excerpt_length($length) { 78 $options = get_option('e_tools'); 79 $len = intval($options['excerpt_length']); 80 if ($length > $len) $length = $len; 81 return $length; 42 82 } 43 83 44 84 // Draw the menu page itself 45 function e_tools_page() {85 function settings_page() { 46 86 global $jscounter; 47 87 $options = get_option('e_tools'); … … 85 125 $i++; 86 126 echo "<td><label for='e_tools_enable_$key'>"; 87 echo "<input type='checkbox' name='e_tools[enable_$key]' id='e_tools_enable_$key' value='1' "; checked( '1', $options["enable_$key"]); echo ">";127 echo "<input type='checkbox' name='e_tools[enable_$key]' id='e_tools_enable_$key' value='1' "; checked(isset($options["enable_$key"]) && intval($options["enable_$key"])); echo ">"; 88 128 if (isset($post_type_icons[$key])) 89 129 echo " <i class='dashicons ${post_type_icons[$key]}'></i> "; … … 98 138 $length = $len; 99 139 } 140 141 $enforce_length = isset($options['enforce_length']) && (boolean) $options['enforce_length']; 100 142 ?> 101 143 102 144 <tr valign="top"> 103 145 <th scope="row"><?php _e('Excerpt Length', 'excerpt-tools'); ?></th> 104 <td><input type="text" name="e_tools[excerpt_length]" id='excerpt_length' value="<?php echo $length; ?>" placeholder='150' style='text-align: right; width: 4em;' /> characters</td> 146 <td><input type="text" name="e_tools[excerpt_length]" id='excerpt_length' value="<?php echo $length; ?>" placeholder='150' style='text-align: right; width: 4em;' /> characters 147 <p><label for='enforce_length'><input type='checkbox' name='e_tools[enforce_length]' id='enforce_length' <?php checked($enforce_length); ?>> 148 <?php _e('Enforce this length limit on all excerpts', 'excerpt-tools'); ?></p></td> 105 149 </tr> 106 150 … … 133 177 134 178 135 function e_tools_meta_box($post) {179 function meta_box($post) { 136 180 wp_enqueue_script('jquery'); 137 181 $options = get_option('e_tools'); -
excerpt-tools/trunk/readme.txt
r926472 r958672 20 20 3. Configure your options under the "Excerpt Tools" item in the Settings menu. 21 21 22 === Requirements === 23 24 Note that from version 0.5, this plugin requires PHP version 5.3 or above. 25 22 26 ==Screenshots== 23 27 … … 26 30 27 31 == Changelog == 32 33 = 0.5 = 34 * Moved to a new namespace (requires PHP 5.3) 35 * Added option to enforce excerpt length 36 * Set excerpt length with Relevanssi as well 28 37 29 38 = 0.4 =
Note: See TracChangeset
for help on using the changeset viewer.