Media File Renamer - Version 3.5.6

Version Description

  • Fix: Sometimes numbered files were renamed something like abc-2-2.jpg.
  • Update: Rename with lowercase to avoid issues.
  • Add: Option for Pro, Media Title is synchronized with Title of Attached Post.
Download this release

Release Info

Developer TigrouMeow
Plugin Icon 128x128 Media File Renamer
Version 3.5.6
Comparing to
See all releases

Code changes from version 3.5.4 to 3.5.6

Files changed (4) hide show
  1. core.php +23 -5
  2. media-file-renamer.php +3 -3
  3. mfrh_admin.php +30 -0
  4. readme.txt +6 -1
core.php CHANGED
@@ -346,7 +346,8 @@ class Meow_MFRH_Core {
346
  delete_post_meta( $id, '_require_file_renaming' );
347
  return false;
348
  }
349
- add_post_meta( $post['ID'], '_numbered_filename', $output['desired_filename'], true );
 
350
  }
351
  else {
352
  $output['desired_filename_exists'] = true;
@@ -381,6 +382,9 @@ class Meow_MFRH_Core {
381
  }
382
 
383
  function generate_explanation( $file ) {
 
 
 
384
  if ( $file['post_title'] == "" ) {
385
  echo " <a class='button-primary' href='post.php?post=" . $file['post_id'] . "&action=edit'>" . __( 'Edit Media', 'media-file-renamer' ) . "</a><br /><small>" . __( 'This title cannot be used for a filename.', 'media-file-renamer' ) . "</small>";
386
  }
@@ -394,11 +398,21 @@ class Meow_MFRH_Core {
394
  $modify_url = "post.php?post=" . $file['post_id'] . "&action=edit";
395
  $page = isset( $_GET['page'] ) ? ( '&page=' . $_GET['page'] ) : "";
396
 
 
 
 
 
 
 
397
  echo "<a class='button-primary' href='?" . $page . $mfrh_scancheck . $mfrh_to_rename . "&mfrh_rename=" . $file['post_id'] . "'>" . __( 'Auto-Rename', 'media-file-renamer' ) . "</a>";
398
  echo "<a title='" . __( 'Click to lock it to manual only.', 'media-file-renamer' ) . "' href='?" . $page . "&mfrh_lock=" . $file['post_id'] . "'><span style='font-size: 16px; margin-top: 5px;' class='dashicons dashicons-unlock'></span></a>";
399
 
400
- echo"<br /><small style='line-height: 8px;'>" .
401
  sprintf( __( 'Rename to %s. You can also <a href="%s">edit this media</a>.', 'media-file-renamer' ), $file['desired_filename'], $modify_url ) . "</small>";
 
 
 
 
402
  }
403
  }
404
 
@@ -665,7 +679,7 @@ class Meow_MFRH_Core {
665
  if ( !empty( $forceFilename ) )
666
  $new_filename = $forceFilename;
667
  else {
668
- $title = $this->replace_chars( $title );
669
  $utf8_filename = apply_filters( 'mfrh_utf8', false );
670
  if ( $utf8_filename )
671
  $new_filename = sanitize_file_name( $title );
@@ -729,10 +743,12 @@ class Meow_MFRH_Core {
729
 
730
  $require = get_post_meta( $post['ID'], '_require_file_renaming', false );
731
  $method = apply_filters( 'mfrh_method', 'media_title' );
 
732
  $numbered_filename = get_post_meta( $post['ID'], '_numbered_filename', true );
733
  if ( !empty( $numbered_filename ) ) {
734
- $this->log( "Numbered filename ($numbered_filename) is being injected." );
735
- $forceFilename = $numbered_filename;
 
736
  delete_post_meta( $post['ID'], '_numbered_filename' );
737
  }
738
 
@@ -842,6 +858,8 @@ class Meow_MFRH_Core {
842
  }
843
  }
844
 
 
 
845
  // Exact same code as rename-media, it's a good idea to keep track of the original filename.
846
  $original_filename = get_post_meta( $post['ID'], '_original_filename', true );
847
  if ( empty( $original_filename ) )
346
  delete_post_meta( $id, '_require_file_renaming' );
347
  return false;
348
  }
349
+ //TODO: Why was this done...
350
+ //add_post_meta( $post['ID'], '_numbered_filename', $output['desired_filename'], true );
351
  }
352
  else {
353
  $output['desired_filename_exists'] = true;
382
  }
383
 
384
  function generate_explanation( $file ) {
385
+
386
+ static $previous = array();
387
+
388
  if ( $file['post_title'] == "" ) {
389
  echo " <a class='button-primary' href='post.php?post=" . $file['post_id'] . "&action=edit'>" . __( 'Edit Media', 'media-file-renamer' ) . "</a><br /><small>" . __( 'This title cannot be used for a filename.', 'media-file-renamer' ) . "</small>";
390
  }
398
  $modify_url = "post.php?post=" . $file['post_id'] . "&action=edit";
399
  $page = isset( $_GET['page'] ) ? ( '&page=' . $_GET['page'] ) : "";
400
 
401
+ $isNew = true;
402
+ if ( in_array( $file['desired_filename'], $previous ) )
403
+ $isNew = false;
404
+ else
405
+ array_push( $previous, $file['desired_filename'] );
406
+
407
  echo "<a class='button-primary' href='?" . $page . $mfrh_scancheck . $mfrh_to_rename . "&mfrh_rename=" . $file['post_id'] . "'>" . __( 'Auto-Rename', 'media-file-renamer' ) . "</a>";
408
  echo "<a title='" . __( 'Click to lock it to manual only.', 'media-file-renamer' ) . "' href='?" . $page . "&mfrh_lock=" . $file['post_id'] . "'><span style='font-size: 16px; margin-top: 5px;' class='dashicons dashicons-unlock'></span></a>";
409
 
410
+ echo "<br /><small style='line-height: 8px;'>" .
411
  sprintf( __( 'Rename to %s. You can also <a href="%s">edit this media</a>.', 'media-file-renamer' ), $file['desired_filename'], $modify_url ) . "</small>";
412
+
413
+ if ( !$isNew ) {
414
+ echo __( '<small style=\'line-height: 8px;\'>The first media you rename will actually get this filename; the next will be either not renamed or will have a counter behind it.</small>', 'media-file-renamer' );
415
+ }
416
  }
417
  }
418
 
679
  if ( !empty( $forceFilename ) )
680
  $new_filename = $forceFilename;
681
  else {
682
+ $title = strtolower( $this->replace_chars( $title ) );
683
  $utf8_filename = apply_filters( 'mfrh_utf8', false );
684
  if ( $utf8_filename )
685
  $new_filename = sanitize_file_name( $title );
743
 
744
  $require = get_post_meta( $post['ID'], '_require_file_renaming', false );
745
  $method = apply_filters( 'mfrh_method', 'media_title' );
746
+
747
  $numbered_filename = get_post_meta( $post['ID'], '_numbered_filename', true );
748
  if ( !empty( $numbered_filename ) ) {
749
+ // TODO: Why was this done...
750
+ // $this->log( "Numbered filename ($numbered_filename) is being injected." );
751
+ // $forceFilename = $numbered_filename;
752
  delete_post_meta( $post['ID'], '_numbered_filename' );
753
  }
754
 
858
  }
859
  }
860
 
861
+ //return;
862
+
863
  // Exact same code as rename-media, it's a good idea to keep track of the original filename.
864
  $original_filename = get_post_meta( $post['ID'], '_original_filename', true );
865
  if ( empty( $original_filename ) )
media-file-renamer.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Media File Renamer
4
  Plugin URI: http://meowapps.com
5
  Description: Auto-rename the files when titles are modified and update and the references (links). Manual Rename is a Pro option. Please read the description.
6
- Version: 3.5.4
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-file-renamer
@@ -14,14 +14,14 @@ http://www.opensource.org/licenses/mit-license.php
14
  http://www.gnu.org/licenses/gpl.html
15
 
16
  Originally developed for two of my websites:
17
- - Jordy Meow (http://jordymeow.com)
18
  - Haikyo (http://haikyo.org)
19
  */
20
 
21
  if ( is_admin() ) {
22
 
23
  global $mfrh_version;
24
- $mfrh_version = '3.5.4';
25
 
26
  // Admin
27
  require( 'mfrh_admin.php');
3
  Plugin Name: Media File Renamer
4
  Plugin URI: http://meowapps.com
5
  Description: Auto-rename the files when titles are modified and update and the references (links). Manual Rename is a Pro option. Please read the description.
6
+ Version: 3.5.6
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-file-renamer
14
  http://www.gnu.org/licenses/gpl.html
15
 
16
  Originally developed for two of my websites:
17
+ - Jordy Meow (http://offbeatjapan.org)
18
  - Haikyo (http://haikyo.org)
19
  */
20
 
21
  if ( is_admin() ) {
22
 
23
  global $mfrh_version;
24
+ $mfrh_version = '3.5.6';
25
 
26
  // Admin
27
  require( 'mfrh_admin.php');
mfrh_admin.php CHANGED
@@ -23,6 +23,8 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
23
  }
24
  $method = apply_filters( 'mfrh_method', 'media_title' );
25
  $sync_alt = get_option( 'mfrh_sync_alt' );
 
 
26
  if ( $sync_alt && $method == 'alt_text' ) {
27
  update_option( 'mfrh_sync_alt', false, false );
28
  ?>
@@ -31,6 +33,15 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
31
  </div>
32
  <?php
33
  }
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
  function common_url( $file ) {
@@ -91,11 +102,17 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
91
  array( $this, 'admin_sync_alt_callback' ),
92
  'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
93
  }
 
 
 
 
 
94
 
95
  register_setting( 'mfrh_advanced_settings', 'mfrh_undo' );
96
  register_setting( 'mfrh_advanced_settings', 'mfrh_manual_rename' );
97
  register_setting( 'mfrh_advanced_settings', 'mfrh_numbered_files' );
98
  register_setting( 'mfrh_advanced_settings', 'mfrh_sync_alt' );
 
99
 
100
  // SUBMENU > Settings > Developer Settings
101
  add_settings_section( 'mfrh_developer_settings', null, null, 'mfrh_developer_settings-menu' );
@@ -250,6 +267,19 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
250
  echo $html;
251
  }
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  function admin_undo_callback( $args ) {
254
  $html = '<input type="checkbox" id="mfrh_undo" name="mfrh_undo" value="1" ' .
255
  checked( 1, get_option( 'mfrh_undo', false ), false ) . '/>';
23
  }
24
  $method = apply_filters( 'mfrh_method', 'media_title' );
25
  $sync_alt = get_option( 'mfrh_sync_alt' );
26
+ $sync_meta_title = get_option( 'mfrh_sync_media_title' );
27
+
28
  if ( $sync_alt && $method == 'alt_text' ) {
29
  update_option( 'mfrh_sync_alt', false, false );
30
  ?>
33
  </div>
34
  <?php
35
  }
36
+
37
+ if ( $sync_meta_title && $method == 'media_title' ) {
38
+ update_option( 'mfrh_sync_media_title', false, false );
39
+ ?>
40
+ <div class="notice notice-warning is-dismissible">
41
+ <p><?php _e( 'The option Sync Media Title was turned off since it does not make sense to have it with this Auto-Rename mode.', 'media-file-renamer' ); ?></p>
42
+ </div>
43
+ <?php
44
+ }
45
  }
46
 
47
  function common_url( $file ) {
102
  array( $this, 'admin_sync_alt_callback' ),
103
  'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
104
  }
105
+ if ( $method == 'post_title' || $method == 'alt_text' ) {
106
+ add_settings_field( 'mfrh_sync_media_title', "Sync Media Title<br />(Pro)",
107
+ array( $this, 'admin_sync_media_title_callback' ),
108
+ 'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
109
+ }
110
 
111
  register_setting( 'mfrh_advanced_settings', 'mfrh_undo' );
112
  register_setting( 'mfrh_advanced_settings', 'mfrh_manual_rename' );
113
  register_setting( 'mfrh_advanced_settings', 'mfrh_numbered_files' );
114
  register_setting( 'mfrh_advanced_settings', 'mfrh_sync_alt' );
115
+ register_setting( 'mfrh_advanced_settings', 'mfrh_sync_media_title' );
116
 
117
  // SUBMENU > Settings > Developer Settings
118
  add_settings_section( 'mfrh_developer_settings', null, null, 'mfrh_developer_settings-menu' );
267
  echo $html;
268
  }
269
 
270
+ function admin_sync_media_title_callback( $args ) {
271
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_sync_media_title" name="mfrh_sync_media_title" value="1" ' .
272
+ checked( 1, get_option( 'mfrh_sync_media_title' ), false ) . '/>';
273
+ $method = apply_filters( 'mfrh_method', 'media_title' );
274
+ $what = __( "Error!", 'media-file-renamer' );
275
+ if ( $method == "alt_text" )
276
+ $what = __( "Media ALT", 'media-file-renamer' );
277
+ else if ( $method == "post_title" )
278
+ $what = __( "Attached Post Title", 'media-file-renamer' );
279
+ $html .= __( "<label>Media Title = <b>$what</b></label><br /><small>Keep in mind that the HTML in your posts and pages will be however not modified, that is too dangerous!</small>", 'media-file-renamer' );
280
+ echo $html;
281
+ }
282
+
283
  function admin_undo_callback( $args ) {
284
  $html = '<input type="checkbox" id="mfrh_undo" name="mfrh_undo" value="1" ' .
285
  checked( 1, get_option( 'mfrh_undo', false ), false ) . '/>';
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: TigrouMeow
3
  Tags: rename, file, media, management, image, renamer, wpml, wp-retina-2x
4
  Requires at least: 4.2
5
  Tested up to: 4.8
6
- Stable tag: 3.5.4
7
 
8
  Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
 
@@ -100,6 +100,11 @@ You are welcome to create plugins using Media File Renamer using special rules f
100
 
101
  == Changelog ==
102
 
 
 
 
 
 
103
  = 3.5.4 =
104
  * Add: mfrh_replace_rules filter allows you to personalize the renaming at the character level.
105
 
3
  Tags: rename, file, media, management, image, renamer, wpml, wp-retina-2x
4
  Requires at least: 4.2
5
  Tested up to: 4.8
6
+ Stable tag: 3.5.6
7
 
8
  Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
 
100
 
101
  == Changelog ==
102
 
103
+ = 3.5.6 =
104
+ * Fix: Sometimes numbered files were renamed something like abc-2-2.jpg.
105
+ * Update: Rename with lowercase to avoid issues.
106
+ * Add: Option for Pro, Media Title is synchronized with Title of Attached Post.
107
+
108
  = 3.5.4 =
109
  * Add: mfrh_replace_rules filter allows you to personalize the renaming at the character level.
110