Media File Renamer - Version 4.2.2

Version Description

  • Add: Polylang compatibility.
  • Update: UI enhancements and attempt to make the renaming faster.
  • Note: If you like it, please review the plugin here: https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post. It's important for us :) Thank you!
Download this release

Release Info

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

Code changes from version 4.2.1 to 4.2.2

Files changed (7) hide show
  1. common/admin.php +6 -4
  2. core.php +39 -3
  3. media-file-renamer.php +2 -2
  4. readme.txt +11 -6
  5. scripts/media-library.js +28 -2
  6. ui.php +29 -3
  7. updates.php +51 -1
common/admin.php CHANGED
@@ -11,7 +11,7 @@ if ( !class_exists( 'MeowApps_Admin' ) ) {
11
  public $mainfile; // plugin main file (media-file-renamer.php)
12
  public $domain; // domain used for translation (media-file-renamer)
13
 
14
- public function __construct( $prefix, $mainfile, $domain ) {
15
 
16
  // Core Admin (used by all Meow Apps plugins)
17
  if ( !MeowApps_Admin::$loaded ) {
@@ -36,9 +36,11 @@ if ( !class_exists( 'MeowApps_Admin' ) ) {
36
  if ( ( !empty( $license ) ) && !file_exists( plugin_dir_path( $this->mainfile ) . 'common/meowapps/admin.php' ) ) {
37
  add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) );
38
  }
39
- $rating_date = $this->create_rating_date();
40
- if ( time() > $rating_date ) {
41
- add_action( 'admin_notices', array( $this, 'admin_notices_rating' ) );
 
 
42
  }
43
  }
44
  }
11
  public $mainfile; // plugin main file (media-file-renamer.php)
12
  public $domain; // domain used for translation (media-file-renamer)
13
 
14
+ public function __construct( $prefix, $mainfile, $domain, $disableReview = false ) {
15
 
16
  // Core Admin (used by all Meow Apps plugins)
17
  if ( !MeowApps_Admin::$loaded ) {
36
  if ( ( !empty( $license ) ) && !file_exists( plugin_dir_path( $this->mainfile ) . 'common/meowapps/admin.php' ) ) {
37
  add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) );
38
  }
39
+ if ( !$disableReview ) {
40
+ $rating_date = $this->create_rating_date();
41
+ if ( time() > $rating_date ) {
42
+ add_action( 'admin_notices', array( $this, 'admin_notices_rating' ) );
43
+ }
44
  }
45
  }
46
  }
core.php CHANGED
@@ -115,6 +115,36 @@ class Meow_MFRH_Core {
115
  return get_post( $postid, OBJECT );
116
  }
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  /*****************************************************************************
119
  RENAME ON UPLOAD
120
  *****************************************************************************/
@@ -706,7 +736,7 @@ class Meow_MFRH_Core {
706
  if ( $meta ) {
707
  if ( isset( $meta['file'] ) && !empty( $meta['file'] ) )
708
  $meta['file'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['file'] );
709
- if ( isset( $meta['url'] ) && !empty( $meta['url'] ) && count( $meta['url'] ) > 4 )
710
  $meta['url'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['url'] );
711
  else
712
  $meta['url'] = $noext_new_filename . '.' . $old_ext;
@@ -738,8 +768,14 @@ class Meow_MFRH_Core {
738
  $orig_image_urls[$size] = $orig_image_data[0];
739
 
740
  // Double check files exist before trying to rename.
741
- if ( $force_rename || ( file_exists( $meta_old_filepath )
742
- && ( ( !file_exists( $meta_new_filepath ) ) || is_writable( $meta_new_filepath ) ) ) ) {
 
 
 
 
 
 
743
  // WP Retina 2x is detected, let's rename those files as well
744
  if ( function_exists( 'wr2x_get_retina' ) ) {
745
  $wr2x_old_filepath = $this->str_replace( '.' . $old_ext, '@2x.' . $old_ext, $meta_old_filepath );
115
  return get_post( $postid, OBJECT );
116
  }
117
 
118
+ /**
119
+ * Returns all the media sharing the same file
120
+ * @param string $file The attached file path
121
+ * @param int|array $excludes The post ID(s) to exclude from the results
122
+ * @return array An array of IDs
123
+ */
124
+ function get_posts_by_attached_file( $file, $excludes = null ) {
125
+ global $wpdb;
126
+ $r = array ();
127
+ $q = <<< SQL
128
+ SELECT post_id
129
+ FROM {$wpdb->postmeta}
130
+ WHERE meta_key = '%s'
131
+ AND meta_value = '%s'
132
+ SQL;
133
+ $rows = $wpdb->get_results( $wpdb->prepare( $q, '_wp_attached_file', _wp_relative_upload_path( $file ) ), OBJECT );
134
+ if ( $rows && is_array( $rows ) ) {
135
+ if ( !is_array( $excludes ) )
136
+ $excludes = $excludes ? array ( (int) $excludes ) : array ();
137
+
138
+ foreach ( $rows as $item ) {
139
+ $id = (int) $item->post_id;
140
+ if ( in_array( $id, $excludes ) ) continue;
141
+ $r[] = $id;
142
+ }
143
+ $r = array_unique( $r );
144
+ }
145
+ return $r;
146
+ }
147
+
148
  /*****************************************************************************
149
  RENAME ON UPLOAD
150
  *****************************************************************************/
736
  if ( $meta ) {
737
  if ( isset( $meta['file'] ) && !empty( $meta['file'] ) )
738
  $meta['file'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['file'] );
739
+ if ( isset( $meta['url'] ) && !empty( $meta['url'] ) && strlen( $meta['url'] ) > 4 )
740
  $meta['url'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['url'] );
741
  else
742
  $meta['url'] = $noext_new_filename . '.' . $old_ext;
768
  $orig_image_urls[$size] = $orig_image_data[0];
769
 
770
  // Double check files exist before trying to rename.
771
+ if (
772
+ $force_rename || (
773
+ file_exists( $meta_old_filepath ) && (
774
+ ( !file_exists( $meta_new_filepath ) ) ||
775
+ is_writable( $meta_new_filepath )
776
+ )
777
+ )
778
+ ) {
779
  // WP Retina 2x is detected, let's rename those files as well
780
  if ( function_exists( 'wr2x_get_retina' ) ) {
781
  $wr2x_old_filepath = $this->str_replace( '.' . $old_ext, '@2x.' . $old_ext, $meta_old_filepath );
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: 4.2.1
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-file-renamer
@@ -29,7 +29,7 @@ if ( class_exists( 'Meow_MFRH_Core' ) ) {
29
  if ( is_admin() ) {
30
 
31
  global $mfrh_version, $mfrh_core;
32
- $mfrh_version = '4.2.1';
33
 
34
  // Admin
35
  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: 4.2.2
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-file-renamer
29
  if ( is_admin() ) {
30
 
31
  global $mfrh_version, $mfrh_core;
32
+ $mfrh_version = '4.2.2';
33
 
34
  // Admin
35
  require( 'mfrh_admin.php');
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: TigrouMeow
3
  Tags: rename, file, files, media, manager, image, renamer, wpml, optimization, seo, retina, gutenberg
4
  Requires at least: 4.6
5
- Tested up to: 4.9.6
6
- Stable tag: 4.2.1
7
 
8
  Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
 
@@ -13,17 +13,17 @@ The Media File Auto Renamer is a WordPress plugin that physically renames media
13
 
14
  **IMPORTANT**. This is originally an *automatic* renamer based on the Media title. This plugin features were all meant to be automatic depending on the title of the Media. Manual Rename (and a few more features) were added two years later, in a Pro version. I add complex features based on requests usually in the Pro to be able to maintain the quality of the plugin and its support.
15
 
16
- **HOW IT WORKS**. The plugin automatically renames your media filenames depending on their titles. When files are renamed, the references to it are also updated (posts, pages, custom types and their metadata). A new column in the Media Manager will display to you the new ideal filename and a button will allow you to rename it straight away. You can lock and unlock the renaming automatic process through little icons. There is also a little dashboard called File Renamer in Media that will help you rename all your files at once. Advanced users can change the way the files are renamed by using the plugin's filters (check the FAQ). There is also a LOCK option on every image to avoid the filename to be modified any further.
17
 
18
  **PRO VERSION**. The [Pro Version](https://meowapps.com/media-file-renamer/) gives a few more features like manual renaming, renaming depending on the post the media is attached to or the content of the alternative text (ALT), logging of SQL queries and a few more options. A good process is to actually let the plugin do the renaming automatically (like in the free version) and to do manual renaming for the files that require fine tuning.
19
 
20
- **BE CAREFUL**. File renaming is a dangerous process. Before renaming everything automatically, try to rename a few files first and check if all the references to those files have been properly updated on your website. WordPress has so many themes and plugins that this renaming process can't unfortunately cover all the cases, especially if other plugins are using unconventional ways. If references aren't updated properly, please write a nice post (not an angry one) in the support threads :) I will try my best to cover more and more special cases. In any case, always make a **backup** of your database and files before using a plugin that alter your install. For backup, you can use such a plugin as [UpdraftPlus](https://updraftplus.com/?afref=460). Also, it your website seems broken after a few renames, try to **clear your cache**. The cached HTML will indeed not be linked to the new filenames.
21
 
22
  **FOR DEVELOPER**. The plugin can be tweaked and reference updates enhanced for your themes/plugins. Have a look [here](https://wordpress.org/plugins/media-file-renamer/faq/).
23
 
24
  **JUST TO MAKE SURE**. This plugin will not allow you to change the filename manually in its standard version. The [Pro Version](https://meowapps.com/media-file-renamer/) is required. If you are about to *write an angry review* because this feature is not available, please *mention that you read the whole description*.
25
 
26
- This plugin works perfectly with WP Retina 2x, WPML and many more. Is has been tested in Windows, Linux, BSD and OSX systems.
27
 
28
  Languages: English, French.
29
 
@@ -47,6 +47,11 @@ Check the FAQ on the official website, [here](https://meowapps.com/media-file-re
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
50
  = 4.2.1 =
51
  * Add: All the actions in the Media Library are now asynchronous. No more page reload!
52
  * Update: Many changes and little enhancements in the code, for speed, security and code-tidyness.
@@ -170,7 +175,7 @@ Check the FAQ on the official website, [here](https://meowapps.com/media-file-re
170
  * Fix: Little naming issue when numbering + custom filter is used.
171
 
172
  = 2.6.0 =
173
- * Add: Lock/Unlock icons in the Media Manager.
174
  * Add: Rename depending on the title of the post the media is attached to.
175
 
176
  = 2.5.0 =
2
  Contributors: TigrouMeow
3
  Tags: rename, file, files, media, manager, image, renamer, wpml, optimization, seo, retina, gutenberg
4
  Requires at least: 4.6
5
+ Tested up to: 4.9.7
6
+ Stable tag: 4.2.2
7
 
8
  Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
 
13
 
14
  **IMPORTANT**. This is originally an *automatic* renamer based on the Media title. This plugin features were all meant to be automatic depending on the title of the Media. Manual Rename (and a few more features) were added two years later, in a Pro version. I add complex features based on requests usually in the Pro to be able to maintain the quality of the plugin and its support.
15
 
16
+ **HOW IT WORKS**. The plugin automatically renames your media filenames depending on their titles. When files are renamed, the references to it are also updated (posts, pages, custom types and their metadata). A new column in the Media Library will display to you the new ideal filename and a button will allow you to rename it straight away. You can lock and unlock the renaming automatic process through little icons. There is also a little dashboard called File Renamer in Media that will help you rename all your files at once. Advanced users can change the way the files are renamed by using the plugin's filters (check the FAQ). There is also a LOCK option on every image to avoid the filename to be modified any further.
17
 
18
  **PRO VERSION**. The [Pro Version](https://meowapps.com/media-file-renamer/) gives a few more features like manual renaming, renaming depending on the post the media is attached to or the content of the alternative text (ALT), logging of SQL queries and a few more options. A good process is to actually let the plugin do the renaming automatically (like in the free version) and to do manual renaming for the files that require fine tuning.
19
 
20
+ **BE CAREFUL**. File renaming is a dangerous process. Before renaming everything automatically, try to rename a few files first and check carefully that all the references to those files have been properly updated on your website. WordPress has so many themes and plugins that this renaming process can't unfortunately cover all the cases, especially if other plugins are using unconventional ways. If references aren't updated properly, please write a nice post (not an angry one) in the support threads :) I will try my best to cover more and more special cases. In any case, always make a **backup** of your database and files before using a plugin that alter your install. For backup, you can use such a plugin as [UpdraftPlus](https://updraftplus.com/?afref=460). Also, if your website seems broken after a few renames, try to **clear your cache**. The cached HTML will indeed not be linked to the new filenames.
21
 
22
  **FOR DEVELOPER**. The plugin can be tweaked and reference updates enhanced for your themes/plugins. Have a look [here](https://wordpress.org/plugins/media-file-renamer/faq/).
23
 
24
  **JUST TO MAKE SURE**. This plugin will not allow you to change the filename manually in its standard version. The [Pro Version](https://meowapps.com/media-file-renamer/) is required. If you are about to *write an angry review* because this feature is not available, please *mention that you read the whole description*.
25
 
26
+ This plugin works perfectly with WP Retina 2x, WPML and many more. Is has been tested in Windows, Linux, BSD and macOS systems.
27
 
28
  Languages: English, French.
29
 
47
 
48
  == Changelog ==
49
 
50
+ = 4.2.2 =
51
+ * Add: Polylang compatibility.
52
+ * Update: UI enhancements and attempt to make the renaming faster.
53
+ * Note: If you like it, please review the plugin here: https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post. It's important for us :) Thank you!
54
+
55
  = 4.2.1 =
56
  * Add: All the actions in the Media Library are now asynchronous. No more page reload!
57
  * Update: Many changes and little enhancements in the code, for speed, security and code-tidyness.
175
  * Fix: Little naming issue when numbering + custom filter is used.
176
 
177
  = 2.6.0 =
178
+ * Add: Lock/Unlock icons in the Media Library.
179
  * Add: Rename depending on the title of the post the media is attached to.
180
 
181
  = 2.5.0 =
scripts/media-library.js CHANGED
@@ -92,11 +92,24 @@
92
  }
93
 
94
  }).done(function(result) {
 
 
 
 
 
 
 
 
 
95
  if (result.success === false) { // Rejected
96
  alert(result.data);
97
  return;
98
  }
99
- update(col, result.data);
 
 
 
 
100
  });
101
  });
102
  })();
@@ -204,11 +217,24 @@
204
  data: data
205
 
206
  }).done(function(result) {
 
 
 
 
 
 
 
 
 
207
  if (result.success === false) { // Rejected
208
  alert(result.data);
209
  return;
210
  }
211
- update(col, result.data);
 
 
 
 
212
  });
213
  }
214
 
92
  }
93
 
94
  }).done(function(result) {
95
+ /**
96
+ * Expected result format: {
97
+ * success: True or False
98
+ * data: {
99
+ * filename: New Filename
100
+ * ids: Affected Posts IDs
101
+ * }
102
+ * }
103
+ */
104
  if (result.success === false) { // Rejected
105
  alert(result.data);
106
  return;
107
  }
108
+ // Update all the affected posts' columns
109
+ for (var i = 0; i < result.data.ids.length; i++) {
110
+ var id = result.data.ids[i];
111
+ update('#post-' + id + ' .mfrh_column', result.data.filename);
112
+ }
113
  });
114
  });
115
  })();
217
  data: data
218
 
219
  }).done(function(result) {
220
+ /**
221
+ * Expected result format: {
222
+ * success: True or False
223
+ * data: {
224
+ * filename: New Filename
225
+ * ids: Affected Posts IDs
226
+ * }
227
+ * }
228
+ */
229
  if (result.success === false) { // Rejected
230
  alert(result.data);
231
  return;
232
  }
233
+ // Update all the affected posts' columns
234
+ for (var i = 0; i < result.data.ids.length; i++) {
235
+ var id = result.data.ids[i];
236
+ update('#post-' + id + ' .mfrh_column', result.data.filename);
237
+ }
238
  });
239
  }
240
 
ui.php CHANGED
@@ -18,6 +18,7 @@ class Meow_MFRH_UI {
18
  add_action( 'admin_notices', array( $this, 'admin_notices' ) );
19
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
20
  add_filter( 'media_send_to_editor', array( $this, 'media_send_to_editor' ), 20, 3 );
 
21
 
22
  // Column for Media Library
23
  $method = apply_filters( 'mfrh_method', 'media_title' );
@@ -31,6 +32,22 @@ class Meow_MFRH_UI {
31
  add_filter( 'handle_bulk_actions-upload', array( $this, 'library_bulk_actions_handler' ), 10, 3 );
32
  }
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  /**
35
  * Renders a view within the views directory.
36
  * @param string $view The name of the view to render
@@ -173,12 +190,13 @@ class Meow_MFRH_UI {
173
  * @return string Rendered content
174
  */
175
  function render_column( $id ) {
176
- return $this->render_view( 'column', array(
177
  'ui' => $this,
178
  'core' => $this->core,
179
  'admin' => $this->admin,
180
  'id' => $id
181
  ) );
 
182
  }
183
 
184
  function generate_explanation( $file ) {
@@ -298,7 +316,11 @@ class Meow_MFRH_UI {
298
  }
299
  }
300
  $this->core->rename( $id, $newName );
301
- wp_send_json_success( basename( get_attached_file( $id ) ) );
 
 
 
 
302
  }
303
  echo 0;
304
  die();
@@ -322,7 +344,11 @@ class Meow_MFRH_UI {
322
  $original_filename = get_post_meta( $id, '_original_filename', true );
323
  $this->core->rename( $id, $original_filename );
324
  delete_post_meta( $id, '_original_filename' );
325
- wp_send_json_success( basename( get_attached_file( $id ) ) );
 
 
 
 
326
  }
327
  echo 0;
328
  die();
18
  add_action( 'admin_notices', array( $this, 'admin_notices' ) );
19
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
20
  add_filter( 'media_send_to_editor', array( $this, 'media_send_to_editor' ), 20, 3 );
21
+ add_filter( 'option_active_plugins', array( $this, 'active_plugins' ) );
22
 
23
  // Column for Media Library
24
  $method = apply_filters( 'mfrh_method', 'media_title' );
32
  add_filter( 'handle_bulk_actions-upload', array( $this, 'library_bulk_actions_handler' ), 10, 3 );
33
  }
34
 
35
+ function active_plugins( $plugins ) {
36
+ if ( // Media File Renamer is doing Ajax
37
+ wp_doing_ajax() &&
38
+ isset( $_REQUEST['action'] ) &&
39
+ substr( $_REQUEST['action'], 0, 5 ) == 'mfrh_'
40
+ ) {
41
+ // Remove the all active plugins except for this plugin itself and a few supported plugins
42
+ foreach ( $plugins as $i => $plugin ) {
43
+ if ( preg_match( '/\/media-file-renamer(-pro)?\.php$/', $plugin ) ) continue;
44
+ if ( preg_match( '/^polylang(-pro)\//', $plugin ) ) continue; // Polylang
45
+ unset( $plugins[$i] );
46
+ }
47
+ }
48
+ return $plugins;
49
+ }
50
+
51
  /**
52
  * Renders a view within the views directory.
53
  * @param string $view The name of the view to render
190
  * @return string Rendered content
191
  */
192
  function render_column( $id ) {
193
+ $r = $this->render_view( 'column', array(
194
  'ui' => $this,
195
  'core' => $this->core,
196
  'admin' => $this->admin,
197
  'id' => $id
198
  ) );
199
+ return $r;
200
  }
201
 
202
  function generate_explanation( $file ) {
316
  }
317
  }
318
  $this->core->rename( $id, $newName );
319
+ $file = get_attached_file( $id );
320
+ wp_send_json_success( array (
321
+ 'filename' => basename( $file ),
322
+ 'ids' => $this->core->get_posts_by_attached_file( $file )
323
+ ) );
324
  }
325
  echo 0;
326
  die();
344
  $original_filename = get_post_meta( $id, '_original_filename', true );
345
  $this->core->rename( $id, $original_filename );
346
  delete_post_meta( $id, '_original_filename' );
347
+ $file = get_attached_file( $id );
348
+ wp_send_json_success( array (
349
+ 'filename' => basename( $file ),
350
+ 'ids' => $this->core->get_posts_by_attached_file( $file )
351
+ ) );
352
  }
353
  echo 0;
354
  die();
updates.php CHANGED
@@ -17,9 +17,11 @@ class Meow_MFRH_Updates {
17
  // Support for Beaver Builder
18
  if ( class_exists( 'FLBuilderModel' ) )
19
  require( 'plugins/beaverbuilder.php' );
20
- }
21
 
22
  function init_actions() {
 
 
23
  if ( get_option( "mfrh_update_posts", true ) )
24
  add_action( 'mfrh_url_renamed', array( $this, 'action_update_posts' ), 10, 3 );
25
  if ( get_option( "mfrh_update_postmeta", true ) )
@@ -127,4 +129,52 @@ class Meow_MFRH_Updates {
127
  $this->core->log( "GUID\t$old_guid -> $new_filepath." );
128
  }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
17
  // Support for Beaver Builder
18
  if ( class_exists( 'FLBuilderModel' ) )
19
  require( 'plugins/beaverbuilder.php' );
20
+ }
21
 
22
  function init_actions() {
23
+ add_action( 'mfrh_media_renamed', array( $this, 'action_update_media_file_references' ), 10, 3 );
24
+
25
  if ( get_option( "mfrh_update_posts", true ) )
26
  add_action( 'mfrh_url_renamed', array( $this, 'action_update_posts' ), 10, 3 );
27
  if ( get_option( "mfrh_update_postmeta", true ) )
129
  $this->core->log( "GUID\t$old_guid -> $new_filepath." );
130
  }
131
 
132
+ /**
133
+ * Updates renamed file references of all the duplicated media entries
134
+ * @param array $post
135
+ * @param string $old_filepath
136
+ * @param string $new_filepath
137
+ */
138
+ function action_update_media_file_references( $post, $old_filepath, $new_filepath ) {
139
+ global $wpdb;
140
+
141
+ // Source of sync on 'posts' table
142
+ $id = $post['ID'];
143
+ $src = $wpdb->get_row( "SELECT post_mime_type FROM {$wpdb->posts} WHERE ID = {$id}" );
144
+
145
+ // Source of sync on 'postmeta' table
146
+ $meta = array ( // Meta keys to sync
147
+ '_wp_attached_file' => null,
148
+ '_wp_attachment_metadata' => null
149
+ );
150
+ foreach ( array_keys( $meta ) as $i ) {
151
+ $meta[$i] = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = {$id} AND meta_key = '{$i}'" );
152
+ }
153
+
154
+ // Sync posts sharing the same attachment file
155
+ $dest = $this->core->get_posts_by_attached_file( $old_filepath, $id );
156
+ foreach ( $dest as $item ) {
157
+ if ( get_post_type( $item ) != 'attachment' ) continue;
158
+
159
+ // Set it as manual-renamed to avoid being marked as an issue
160
+ add_post_meta( $item, '_manual_file_renaming', true, true );
161
+
162
+ // Sync on 'posts' table
163
+ $wpdb->update( $wpdb->posts, array ( // Data
164
+ 'post_mime_type' => $src->post_mime_type
165
+ ), array ( // WHERE
166
+ 'ID' => $item
167
+ ) );
168
+
169
+ // Sync on 'postmeta' table
170
+ foreach ( $meta as $j => $jtem ) {
171
+ $wpdb->update( $wpdb->postmeta, array ( // Data
172
+ 'meta_value' => $jtem
173
+ ), array ( // WHERE
174
+ 'post_id' => $item, // AND
175
+ 'meta_key' => $j
176
+ ) );
177
+ }
178
+ }
179
+ }
180
  }