Plugin Directory

Changeset 372705


Ignore:
Timestamp:
04/13/2011 10:44:52 PM (15 years ago)
Author:
johnleblanc
Message:

added management page

Location:
docs-auto-tags/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • docs-auto-tags/trunk/docs-auto-tags.php

    r372436 r372705  
    44Plugin URI: http://wordpress.org/extend/plugins/docs-auto-tags/
    55Description: Assigns tags to posts containing specific text strings, handy for filtering within the loop. A gift to @docrock from @johnleblanc to help keep Instagr.am image posts out of the mrdocrock.com homepage loop April, 2011.
    6 Version: 0.1
     6Version: 0.2
    77Author: John LeBlanc
    88Author URI: http://johnleblanc.com
     
    5151
    5252// main auto-tagging functionality
     53add_action( 'save_post', 'jpl_docs_autotag' );
    5354function jpl_docs_autotag($post_id) {
    54     $instagram_pattern = 'httpimagesinsta';
    5555    $post = get_post($post_id);
    56     if ( intval($post->ID) > 0 && strpos( $post->post_content, $instagram_pattern ) ) {
    57         wp_set_post_tags( $post->ID, $tags, TRUE ); // TRUE means append
     56    if ( intval($post->ID) > 0 ) {
     57        $options = get_option( 'docs_autotags' );
     58        foreach ( $options as $pattern => $tags ) {
     59            if ( strpos($post->post_content, $pattern) )
     60                wp_set_post_tags( $post->ID, $tags, TRUE ); // TRUE means append
     61        }
    5862    }
    5963}
     
    6367function jpl_docs_autotags_options_page() {
    6468    if ( !current_user_can( 'manage_options' ) ) {
    65         // Doc might would include profanity, but he can manage his own language file
     69        // Doc might include profanity, but he can manage his own language file
    6670        wp_die( __('You do not have sufficient permissions to access this page.') );
    6771    }
     
    7074    <div class="wrap">
    7175        <h2><?php _e("Doc's Autotags") ?></h2>
    72         <form method="post" action="tools.php">
     76        <p><?php _e('Posts that include the (case-sensitive) string patterns defined below will be assigned the specified tag(s) when saved.') ?></p>
     77        <form method="post" action="">
    7378            <?php settings_fields( 'docs_autotags_options' ); ?>
    74             <?php do_settings( 'docs_autotags_options' ); ?>
     79
     80            <?php
     81            // receive post data
     82            if ( isset($_POST['pattern']) ) {
     83                $i = 0;
     84                while ( $i <= count($_POST['pattern']) ) {
     85                    if ( strlen(trim($_POST['pattern'][$i])) > 0 && strlen(trim($_POST['tags'][$i])) > 0 )
     86                        $options[$_POST['pattern'][$i]] = $_POST['tags'][$i];
     87                    $i++;
     88                }
     89                update_option( 'docs_autotags', $options );
     90            }
     91            ?>
     92
    7593            <?php $options = get_option( 'docs_autotags' ); ?>
    7694
     95            <?php $i=0; ?>
     96            <?php foreach ( $options as $pattern => $tags ) :?>
     97                <div id="rule-<?php echo $i ?>">
     98                    <p>
     99                        <label for="pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="pattern[<?php echo $i ?>]" value="<?php echo $pattern ?>" />
     100                        <label for="tags[<?php echo $i ?>]"><?php _e('Tags') ?></label> <input class="suggest" name="tags[<?php echo $i ?>]" value="<?php echo $tags ?>" />
     101                        <a href="#" class="delete" onclick="jQuery('#rule-<?php echo $i ?>').remove();return false">delete</a>
     102                    </p>
     103                </div>
     104                <?php $i++; ?>
     105            <?php endforeach; ?>
     106
     107            <div id="rule-new">
     108                <p>
     109                    <label for="pattern[<?php echo $i ?>]"><?php _e('Pattern') ?></label> <input name="pattern[<?php echo $i ?>]" value="" />
     110                    <label for="tags[<?php echo $i ?>]"><?php _e('Tags') ?></label> <input class="suggest" name="tags[<?php echo $i ?>]" value="" />
     111                </p>
     112            </div>
     113
     114            <p class="submit">
     115                <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
     116            </p>
    77117        </form>
    78         <p class="submit">
    79             <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
    80         </p>
    81118    </div>
    82119
    83120    <?php
     121}
     122
     123
     124// use "suggest" for tag input
     125add_action('admin_print_scripts', 'jpl_docs_autotag_scripts');
     126function jpl_docs_autotag_scripts() {
     127    wp_enqueue_script( 'suggest' );
     128}
     129
     130add_action('admin_head', 'jpl_docs_autotag_admin_head');
     131function jpl_docs_autotag_admin_head() {
     132    ?>
     133    <script type="text/javascript">
     134        jQuery(function() {
     135            jQuery('.suggest').suggest("<?php echo get_bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag", {multiple:true, multipleSep: ","});
     136        });
     137    </script>
     138    <?php
    84139}
    85140
  • docs-auto-tags/trunk/lang/en_US.po

    r372418 r372705  
    33"Project-Id-Version: Doc's Auto Tag WordPress Plugin\n"
    44"Report-Msgid-Bugs-To: \n"
    5 "POT-Creation-Date: 2011-04-12 23:57-1000\n"
    6 "PO-Revision-Date: 2011-04-12 23:58-1000\n"
     5"POT-Creation-Date: 2011-04-13 12:43-1000\n"
     6"PO-Revision-Date: 2011-04-13 12:43-1000\n"
    77"Last-Translator: John <poedit@johnleblanc.com>\n"
    88"Language-Team: johnleblanc <wordpress@johnleblanc.com>\n"
     
    1616"X-Poedit-SearchPath-1: .\n"
    1717
    18 #: docs-auto-tags.php:71
     18#: ../trunk/docs-auto-tags.php:75
     19#: docs-auto-tags.php:75
    1920msgid "Doc's Autotags"
    2021msgstr ""
    2122
    22 #: docs-auto-tags.php:77
     23#: ../trunk/docs-auto-tags.php:76
     24#: docs-auto-tags.php:76
     25msgid "Posts that include the (case-sensitive) string patterns defined below will be assigned the specified tag(s) when saved."
     26msgstr ""
     27
     28#: ../trunk/docs-auto-tags.php:99
     29#: ../trunk/docs-auto-tags.php:109
     30#: docs-auto-tags.php:99
     31#: docs-auto-tags.php:109
     32msgid "Pattern"
     33msgstr ""
     34
     35#: ../trunk/docs-auto-tags.php:100
     36#: ../trunk/docs-auto-tags.php:110
     37#: docs-auto-tags.php:100
     38#: docs-auto-tags.php:110
     39msgid "Tags"
     40msgstr ""
     41
     42#: ../trunk/docs-auto-tags.php:115
     43#: docs-auto-tags.php:115
    2344msgid "Save Changes"
    2445msgstr ""
  • docs-auto-tags/trunk/readme.txt

    r372418 r372705  
    2121== Changelog ==
    2222
     23= 0.2 =
     24Added management page
     25
    2326= 0.1 =
    2427Initial Release
Note: See TracChangeset for help on using the changeset viewer.