Advertisement
harikaram

WP Media-Tags plugin patch #2

Nov 28th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.49 KB | None | 0 0
  1. From b74d96ec7dab9ca8ad7faabd9e77a1dd722674e2 Mon Sep 17 00:00:00 2001
  2. From: Hari Karam Singh <harikaram@regallygraceful.com>
  3. Date: Mon, 28 Nov 2011 12:35:32 +0000
  4. Subject: [PATCH] Fixed bogus on/off setting and added auto-tag slug suffix to
  5.  prevent conflicts with post tags etc
  6.  
  7. ---
  8. mediatags_admin.php    |   13 ++++++++++---
  9.  mediatags_settings.php |   13 ++++++++++++-
  10.  2 files changed, 22 insertions(+), 4 deletions(-)
  11.  
  12. diff --git a/mediatags_admin.php b/mediatags_admin.php
  13. index 0d97eb6..37cb00c 100755
  14. --- a/mediatags_admin.php
  15. +++ b/mediatags_admin.php
  16. @@ -1059,7 +1059,7 @@ function mediatags_autotag_from_iptc_keywords( $meta_id, $attachment_id, $meta_k
  17.      // Check that it's an upload and that our setting is on
  18.      // Do the action when _wp_attachment_metadata is first added in order to catch each attachment
  19.      if ( !$_POST['Upload'] || $meta_key != '_wp_attachment_metadata' ) return;
  20. -    if ( 'yes' !== get_option( 'mediatags_autotag_from_iptc_keywords', 'yes' ) ) return;
  21. +    if ( 'yes' !== get_option( 'mediatag_autotag_on_upload', 'no' ) ) return;
  22.      
  23.      // GRAB THE TAGS FROM THE IPTC KEYWORDS
  24.      // First get the supported image types
  25. @@ -1087,10 +1087,17 @@ function mediatags_autotag_from_iptc_keywords( $meta_id, $attachment_id, $meta_k
  26.      $media_tags_array = array();
  27.      if ($keywords) {
  28.          foreach($keywords as $tag) {
  29. -            $tag_slug = sanitize_title_with_dashes($tag);
  30. +            
  31. +            // Append suffix if specified
  32. +            $tag_slug = $tag;
  33. +            if ($slug_suffix = get_option('mediatag_autotag_slug_suffix')) {
  34. +                $tag_slug .= $slug_suffix;
  35. +            }
  36. +            // Clean up afterwards in case of a dodgy setting
  37. +            $tag_slug = sanitize_title_with_dashes($tag_slug);
  38.              
  39.              if ( ! ($id = term_exists( $tag_slug, MEDIA_TAGS_TAXONOMY ) ) )
  40. -                wp_insert_term($tag_val, MEDIA_TAGS_TAXONOMY, array('slug' => $tag_slug));
  41. +                wp_insert_term($tag, MEDIA_TAGS_TAXONOMY, array('slug' => $tag_slug));
  42.              
  43.              $media_tags_array[] = $tag_slug;
  44.          }
  45. diff --git a/mediatags_settings.php b/mediatags_settings.php
  46. index 3ff64e2..728b47d 100755
  47. --- a/mediatags_settings.php
  48. +++ b/mediatags_settings.php
  49. @@ -133,6 +133,11 @@ function mediatags_settings_panel()
  50.             update_option( 'mediatag_autotag_on_upload', $mediatag_autotag_on_upload );
  51.             $update_message = _x("Media-Tags Settings have been updated.", 'update message', MEDIA_TAGS_I18N_DOMAIN);
  52.         }
  53. +       if (isset($_REQUEST['mediatag_autotag_slug_suffix']))
  54. +       {
  55. +           update_option( 'mediatag_autotag_slug_suffix', $_REQUEST['mediatag_autotag_slug_suffix'] );
  56. +           $update_message = _x("Media-Tags Settings have been updated.", 'update message', MEDIA_TAGS_I18N_DOMAIN);
  57. +       }
  58.     }
  59.     $title = _x('Media-Tags Settings', 'settings panel title', MEDIA_TAGS_I18N_DOMAIN);
  60.     ?>
  61. @@ -222,7 +227,8 @@ function mediatags_settings_panel()
  62.                          mediatag_settings_boxheader('mediatag-options-auto-tagging',
  63.                                  __('Auto-Tag Settings for Uploaded Media', MEDIA_TAGS_I18N_DOMAIN));
  64.  
  65. -                        $mediatag_autotag_on_upload = get_option('mediatag_autotag_on_upload', 'yes');?>
  66. +                        $mediatag_autotag_on_upload = get_option('mediatag_autotag_on_upload', 'yes');
  67. +                        $mediatag_autotag_slug_suffix = get_option('mediatag_autotag_slug_suffix', '-media');?>
  68.                          
  69.                          <p><?php _e("Media-Tags can extract the IPTC keywords for media files and auto-save them to newly uploaded media.", MEDIA_TAGS_I18N_DOMAIN); ?></p>
  70.                          
  71. @@ -234,6 +240,11 @@ function mediatags_settings_panel()
  72.                          </select>
  73.                          <label for="mediatag_autotag_on_upload"><?php _e('Turn Auto-Tagging of Uploaded Files On/Off',
  74.                              MEDIA_TAGS_I18N_DOMAIN); ?></label>
  75. +                            
  76. +                        <p>
  77. +                        <label for="mediatag_autotag_slug_suffix"><?php _e('Append this suffix onto slugs to prevent conflicts with other taxonomies',
  78. +                            MEDIA_TAGS_I18N_DOMAIN); ?></label><br/>
  79. +                        <input type="text" id="mediatag_autotag_slug_suffix" name="mediatag_autotag_slug_suffix" value="<?php esc_attr_e($mediatag_autotag_slug_suffix)?>"></p>
  80.                          <?php mediatag_settings_boxfooter(false); ?>
  81.  
  82.  
  83. --
  84. 1.7.5.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement