Advertisement
gizmomol

Wordpress plugin "Format Media Titles" mod

Oct 13th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.36 KB | None | 0 0
  1. diff -crB orig/format-media-titles.php new/format-media-titles.php
  2. *** orig/format-media-titles.php    2011-10-24 12:00:00.000000000 -0700
  3. --- new/format-media-titles.php 2012-10-13 17:07:20.000000000 -0700
  4. ***************
  5. *** 91,96 ****
  6. --- 91,98 ----
  7.                         <label><input name="fmt_options[chk_tilde]" type="checkbox" value="1" <?php if (isset($options['chk_tilde'])) { checked('1', $options['chk_tilde']); } ?> /> Tilde (~)</label><br />
  8.  
  9.                         <label><input name="fmt_options[chk_plus]" type="checkbox" value="1" <?php if (isset($options['chk_plus'])) { checked('1', $options['chk_plus']); } ?> /> Plus (+)</label>
  10. +                         <br />
  11. +                       <label><input name="fmt_options[chk_digits]" type="checkbox" value="1" <?php if (isset($options['chk_digits'])) { checked('1', $options['chk_digits']); } ?> /> Remove digits (0 - 9) excluding DCF camera names</label><br />
  12.                     </td>
  13.                 </tr>
  14.  
  15. ***************
  16. *** 163,168 ****
  17. --- 165,183 ----
  18.     $uploaded_post_id = get_post( $id );
  19.     $title = $uploaded_post_id->post_title;
  20.  
  21. +     /* remove trailing numbers if less than 4 digits so will keep DCF file names (camera formatted names) */
  22. +   if( isset($options['chk_digits']) && $options['chk_digits'] ) {
  23. +         if (is_numeric(substr($title, -4))) {
  24. +           unset($options['chk_underscore']);
  25. +           unset($options['chk_hyphen']);
  26. +             if (substr($title,0, 1) == '_') $title = substr($title, 1); // WP removes leading '_' from filename. This is so DCF title matchs
  27. +         }
  28. +         else {
  29. +             // remove any digits 0 - 9
  30. +             $title = preg_replace("/\d+/", "", $title);
  31. +         }
  32. +     }
  33. +
  34.     /* Update post. */
  35.     $char_array = array();
  36.     if( isset($options['chk_hyphen']) && $options['chk_hyphen'] ) $char_array[] = '-';
  37. ***************
  38. *** 200,206 ****
  39.     // Update the post into the database
  40.     $uploaded_post = array();
  41.     $uploaded_post['ID'] = $id;
  42. !   $uploaded_post['post_title'] = $title;
  43.     wp_update_post( $uploaded_post );
  44.   }
  45. ! add_action( 'add_attachment', 'fmt_update_media_title' );
  46. \ No newline at end of file
  47. --- 215,221 ----
  48.     // Update the post into the database
  49.     $uploaded_post = array();
  50.     $uploaded_post['ID'] = $id;
  51. !   $uploaded_post['post_title'] = trim($title);
  52.     wp_update_post( $uploaded_post );
  53.   }
  54. ! add_action( 'add_attachment', 'fmt_update_media_title' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement