Changeset 608028
- Timestamp:
- 10/04/2012 09:16:40 PM (13 years ago)
- Location:
- docs-auto-tags/trunk
- Files:
-
- 2 added
- 2 edited
-
assets (added)
-
assets/screenshot-1.png (added)
-
docs-auto-tags.php (modified) (8 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs-auto-tags/trunk/docs-auto-tags.php
r466444 r608028 4 4 Plugin URI: http://wordpress.org/extend/plugins/docs-auto-tags/ 5 5 Description: Assigns tags to posts containing specific text strings, handy for filtering within the loop. See query_posts() in the Codex for including/excluding posts by tag. 6 Version: 0. 56 Version: 0.6 7 7 Author: John LeBlanc 8 8 Author URI: http://johnleblanc.com … … 33 33 34 34 35 // set up constants36 if ( !defined('JPL_DOCS_AUTOTAGS_OPTION_NAME') )37 define(JPL_DOCS_AUTOTAGS_OPTION_NAME, 'docs_autotags_patterns');38 39 40 35 // internationalization 41 36 if( !load_plugin_textdomain( 'docs-auto-tags', ABSPATH . WP_CONTENT_DIR . '/languages/') ) … … 47 42 function jpl_docs_autotags_options_init() { 48 43 register_setting( 'jpl_docs_autotags_options', 'docs_autotags' ); 44 register_setting( 'jpl_docs_autocategories_options', 'docs_autocategories' ); 49 45 } 50 46 … … 55 51 $post = get_post($post_id); 56 52 if ( intval($post->ID) > 0 ) { 57 $options = get_option( 'docs_autotags' ); 58 if ( count($options) > 0 ) { 59 foreach ( $options as $pattern => $tags ) { 53 // append tags 54 $tag_options = get_option( 'docs_autotags' ); 55 if ( count($tag_options) > 0 ) { 56 foreach ( $tag_options as $pattern => $tags ) { 60 57 if ( strpos($post->post_content, $pattern) ) 61 58 wp_set_post_tags( $post->ID, $tags, TRUE ); // TRUE means append 59 } 60 } 61 // append categories 62 $category_options = get_option( 'docs_autocategories' ); 63 if ( count($category_options) > 0 ) { 64 foreach ( $category_options as $pattern => $categories ) { 65 if ( strpos($post->post_content, $pattern) ) 66 wp_set_object_terms( $post->ID, 'category', $categories, TRUE ); // TRUE means append 62 67 } 63 68 } … … 75 80 76 81 <div class="wrap"> 82 77 83 <h2><?php _e("Doc's Auto-Tags") ?></h2> 78 <p><?php _e('Posts that include the (case-sensitive) string patterns defined below will be assigned the specified tag(s) when saved.') ?></p> 84 85 <p>Assign tags and/or categories to posts containing specific text strings. Tags and/or categories are assigned when the post is saved, so new rules apply only to posts that are added or updated after those rules are added.</p> 86 79 87 <form method="post" action=""> 80 <?php settings_fields( 'docs_autotags_options' ); ?> 88 89 <?php settings_fields( 'docs_autotags_options' ); ?> 90 <?php settings_fields( 'docs_autocategories_options' ); ?> 91 92 <fieldset style="padding: 5px 20px 20px; margin: 10px 0; border: 1px #ccc solid"> 93 <legend style="font-size:150%"><?php _e('Tags') ?></legend> 94 <p><?php _e('Posts that include the (case-sensitive) string patterns defined below will be assigned the specified tag(s) when saved.') ?></p> 81 95 82 96 <?php 83 97 // receive post data 84 if ( isset($_POST[' pattern']) ) {98 if ( isset($_POST['tag-pattern']) ) { 85 99 $i = 0; 86 while ( $i <= count( $_POST[' pattern'] ) ) {87 if ( strlen( trim($_POST[' pattern'][$i]) ) > 0 && strlen( trim($_POST['tags'][$i]) ) > 0 )88 $ options[$_POST['pattern'][$i]] = $_POST['tags'][$i];100 while ( $i <= count( $_POST['tag-pattern'] ) ) { 101 if ( strlen( trim($_POST['tag-pattern'][$i]) ) > 0 && strlen( trim($_POST['tags'][$i]) ) > 0 ) 102 $tag_options[$_POST['tag-pattern'][$i]] = $_POST['tags'][$i]; 89 103 $i++; 90 104 } 91 update_option( 'docs_autotags', $ options );105 update_option( 'docs_autotags', $tag_options ); 92 106 } 93 107 ?> 94 108 95 <?php $ options = get_option( 'docs_autotags' ); ?>109 <?php $tag_options = get_option( 'docs_autotags' ); ?> 96 110 97 111 <?php $i=0; ?> 98 <?php if ( is_array($ options) && count($options) > 0 ): ?>99 <?php foreach ( $ options as $pattern => $tags ) : ?>100 <div id=" rule-<?php echo $i ?>">112 <?php if ( is_array($tag_options) && count($tag_options) > 0 ): ?> 113 <?php foreach ( $tag_options as $pattern => $tags ) : ?> 114 <div id="tag-rule-<?php echo $i ?>"> 101 115 <p> 102 <label for=" pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="pattern[<?php echo $i ?>]" value="<?php echo $pattern ?>" />103 <label for="tags[<?php echo $i ?>]"><?php _e('Tags') ?></label> <input class="suggest " name="tags[<?php echo $i ?>]" value="<?php echo $tags ?>" />104 <a href="#" class="delete" onclick="jQuery('# rule-<?php echo $i ?>').remove();return false">delete</a>116 <label for="tag-pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="tag-pattern[<?php echo $i ?>]" value="<?php echo $pattern ?>" /> 117 <label for="tags[<?php echo $i ?>]"><?php _e('Tags') ?></label> <input class="suggest-tag" name="tags[<?php echo $i ?>]" value="<?php echo $tags ?>" /> 118 <a href="#" class="delete" onclick="jQuery('#tag-rule-<?php echo $i ?>').remove();return false">delete</a> 105 119 </p> 106 120 </div> … … 109 123 <?php endif; ?> 110 124 111 <div id=" rule-new">125 <div id="tag-rule-new"> 112 126 <p> 113 <label for=" pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="pattern[<?php echo $i ?>]" value="" />114 <label for="tags[<?php echo $i ?>]"><?php _e('Tags') ?></label> <input class="suggest " name="tags[<?php echo $i ?>]" value="" />127 <label for="tag-pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="tag-pattern[<?php echo $i ?>]" value="" /> 128 <label for="tags[<?php echo $i ?>]"><?php _e('Tags') ?></label> <input class="suggest-tag" name="tags[<?php echo $i ?>]" value="" /> 115 129 </p> 116 130 </div> 117 118 <p class="submit"> 119 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> 120 </p> 131 </fieldset> 132 133 <fieldset style="padding: 5px 20px 20px; margin: 10px 0; border: 1px #ccc solid"> 134 <legend style="font-size:150%"><?php _e('Categories') ?></legend> 135 <p><?php _e('Posts that include the (case-sensitive) string patterns defined below will be assigned the specified category(s) when saved.') ?></p> 136 137 <?php 138 // receive post data 139 if ( isset($_POST['category-pattern']) ) { 140 $i = 0; 141 while ( $i <= count( $_POST['category-pattern'] ) ) { 142 if ( strlen( trim($_POST['category-pattern'][$i]) ) > 0 && strlen( trim($_POST['categories'][$i]) ) > 0 ) 143 $category_options[$_POST['category-pattern'][$i]] = $_POST['categories'][$i]; 144 $i++; 145 } 146 update_option( 'docs_autocategories', $category_options ); 147 } 148 ?> 149 150 <?php $category_options = get_option( 'docs_autocategories' ); ?> 151 152 <?php $i=0; ?> 153 <?php if ( is_array($category_options) && count($category_options) > 0 ): ?> 154 <?php foreach ( $category_options as $pattern => $categories ) : ?> 155 <div id="category-rule-<?php echo $i ?>"> 156 <p> 157 <label for="category-pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="category-pattern[<?php echo $i ?>]" value="<?php echo $pattern ?>" /> 158 <label for="categories[<?php echo $i ?>]"><?php _e('Categories') ?></label> <input class="suggest-category" name="categories[<?php echo $i ?>]" value="<?php echo $categories ?>" /> 159 <a href="#" class="delete" onclick="jQuery('#category-rule-<?php echo $i ?>').remove();return false">delete</a> 160 </p> 161 </div> 162 <?php $i++; ?> 163 <?php endforeach; ?> 164 <?php endif; ?> 165 166 <div id="category-rule-new"> 167 <p> 168 <label for="category-pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="category-pattern[<?php echo $i ?>]" value="" /> 169 <label for="categories[<?php echo $i ?>]"><?php _e('Categories') ?></label> <input class="suggest-category" name="categories[<?php echo $i ?>]" value="" /> 170 </p> 171 </div> 172 </fieldset> 173 174 <p class="submit"> 175 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> 176 </p> 121 177 </form> 122 178 </div> … … 131 187 wp_enqueue_script( 'suggest' ); 132 188 } 189 133 190 134 191 add_action('admin_head', 'jpl_docs_autotag_admin_head'); … … 137 194 <script type="text/javascript"> 138 195 jQuery(function() { 139 jQuery('.suggest').suggest("<?php echo get_bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag", {multiple:true, multipleSep: ","}); 196 jQuery('.suggest-tag').suggest("<?php echo get_bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag", {multiple:true, multipleSep: ","}); 197 jQuery('.suggest-category').suggest("<?php echo get_bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=category", {multiple:true, multipleSep: ","}); 140 198 }); 141 199 </script> -
docs-auto-tags/trunk/readme.txt
r466444 r608028 4 4 Tags: tags 5 5 Requires at least: 2.8 6 Tested up to: 3. 1.16 Tested up to: 3.4.2 7 7 Stable tag: 1.0 8 8 9 Assigns tags to posts containing specific text strings, handy for filtering within the loop.9 Assigns tags and/or categories to posts containing specific text strings, handy for filtering within the loop. 10 10 11 11 == Description == … … 19 19 1. Configure your settings within the 'Tools' area in the Dashboard 20 20 21 == Screenshots == 22 23 1. Configuration interface where text strings and corresponding tags (and/or categories) are defined: Tools -> Doc's Auto-Tags 24 21 25 == Changelog == 26 27 = 0.6 = 28 Added Category support by request. 22 29 23 30 = 0.5 = … … 43 50 == Frequently Asked Questions == 44 51 45 Great, my newly saved posts are being auto-tagged. How do I filter posts by tag within the WordPress Loop? 52 = Great, my newly saved posts are being auto-tagged. How do I filter posts by tag within the WordPress Loop? = 46 53 47 54 An example of query_posts():
Note: See TracChangeset
for help on using the changeset viewer.