Media Cleaner - Version 4.4.7

Version Description

  • Fix: Divi Single Image wasn't always properly detected.
  • Add: Option for CSS background.
  • Update: Code cleaning, slighlty faster now.
  • Info: This plugin is hard work, don't hesitate to review it :) Thank you.
Download this release

Release Info

Developer TigrouMeow
Plugin Icon 128x128 Media Cleaner
Version 4.4.7
Comparing to
See all releases

Code changes from version 4.4.6 to 4.4.7

Files changed (5) hide show
  1. core.php +35 -9
  2. media-cleaner.php +2 -2
  3. readme.txt +8 -2
  4. wpmc_admin.php +15 -7
  5. wpmc_checkers.php +6 -3
core.php CHANGED
@@ -59,7 +59,7 @@ class Meow_WPMC_Core {
59
  }
60
  $this->log( "Media Edit > Checking Media #{$post->ID}" );
61
  $success = $this->wpmc_check_media( $post->ID );
62
- $this->log( "Success " . $success . "\n" );
63
  if ( $success ) {
64
  if ( $this->last_analysis == "CONTENT" ) {
65
  echo "Found in content.";
@@ -175,12 +175,14 @@ class Meow_WPMC_Core {
175
  foreach ( $data as $piece ) {
176
  if ( $type == 'file' ) {
177
  $this->log( "Check File: {$piece}" );
178
- $success += ( apply_filters( 'wpmc_check_file', true, $piece ) ? 1 : 0 );
179
- $this->log( "Success " . $success . "\n" );
 
180
  } elseif ( $type == 'media' ) {
181
  $this->log( "Checking Media #{$piece}" );
182
- $success += ( $this->wpmc_check_media( $piece ) ? 1 : 0 );
183
- $this->log( "Success " . $success . "\n" );
 
184
  }
185
  }
186
  ob_end_clean();
@@ -291,7 +293,7 @@ class Meow_WPMC_Core {
291
  $dom = new DOMDocument();
292
  @$dom->loadHTML( $html );
293
 
294
- // Images
295
  $imgs = $dom->getElementsByTagName( 'img' );
296
  $results = array();
297
  foreach ( $imgs as $img ) {
@@ -299,11 +301,34 @@ class Meow_WPMC_Core {
299
  array_push( $results, $src );
300
  }
301
 
 
302
  $urls = $dom->getElementsByTagName( 'a' );
303
  foreach ( $urls as $url ) {
304
  $src = $this->wpmc_clean_url( $url->getAttribute('href') );
305
  array_push( $results, $src );
306
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  return $results;
308
  }
309
 
@@ -483,7 +508,6 @@ class Meow_WPMC_Core {
483
  $found['wpmc_postmeta_images_acf_ids'] = $postmeta_images_acf_ids;
484
  set_transient( "wpmc_postmeta_images_acf_urls", $postmeta_images_acf_urls, $this->transient_life );
485
  $found['wpmc_postmeta_images_acf_urls'] = $postmeta_images_acf_urls;
486
- //error_log( print_r( get_field_objects( $post ), 1 ) );
487
  }
488
  }
489
  }
@@ -497,7 +521,9 @@ class Meow_WPMC_Core {
497
  $posts_images_vc = array();
498
  preg_match_all( "/image=\"([0-9]+)\"/", $html, $res );
499
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
500
- $posts_images_vc = array_merge( $posts_images_vc, $res[1] );
 
 
501
  }
502
  set_transient( "wpmc_posts_images_visualcomposer", $posts_images_vc, $this->transient_life );
503
  $found['wpmc_posts_images_visualcomposer'] = $posts_images_vc;
@@ -1358,7 +1384,7 @@ class Meow_WPMC_Core {
1358
  <input type="search" name="s" style="width: 120px;" value="<?php echo $s ? $s : ""; ?>">
1359
  <input type="hidden" name="page" value="media-cleaner">
1360
  <input type="hidden" name="view" value="<?php echo $view; ?>">
1361
- <input type="hidden" name="paged" value="<?php echo $paged; ?>">
1362
  <input type="submit" class="button" value="<?php _e( 'Search', 'media-cleaner' ) ?>"><span style='border-right: #A2A2A2 solid 1px; margin-left: 5px; margin-right: 3px;'>&nbsp;</span>
1363
  </p>
1364
  </form>
59
  }
60
  $this->log( "Media Edit > Checking Media #{$post->ID}" );
61
  $success = $this->wpmc_check_media( $post->ID );
62
+ $this->log( "Success $success\n" );
63
  if ( $success ) {
64
  if ( $this->last_analysis == "CONTENT" ) {
65
  echo "Found in content.";
175
  foreach ( $data as $piece ) {
176
  if ( $type == 'file' ) {
177
  $this->log( "Check File: {$piece}" );
178
+ $result = ( apply_filters( 'wpmc_check_file', true, $piece ) ? 1 : 0 );
179
+ $this->log( "Success " . $result . "\n" );
180
+ $success += $result;
181
  } elseif ( $type == 'media' ) {
182
  $this->log( "Checking Media #{$piece}" );
183
+ $result = ( $this->wpmc_check_media( $piece ) ? 1 : 0 );
184
+ $this->log( "Success " . $result . "\n" );
185
+ $success += $result;
186
  }
187
  }
188
  ob_end_clean();
293
  $dom = new DOMDocument();
294
  @$dom->loadHTML( $html );
295
 
296
+ // Images, src
297
  $imgs = $dom->getElementsByTagName( 'img' );
298
  $results = array();
299
  foreach ( $imgs as $img ) {
301
  array_push( $results, $src );
302
  }
303
 
304
+ // Links, href
305
  $urls = $dom->getElementsByTagName( 'a' );
306
  foreach ( $urls as $url ) {
307
  $src = $this->wpmc_clean_url( $url->getAttribute('href') );
308
  array_push( $results, $src );
309
  }
310
+
311
+ // Single Image in Divi (Elegant Themes)
312
+ if ( function_exists( '_et_core_find_latest' ) ) {
313
+ preg_match_all( "/src=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
314
+ if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
315
+ foreach ( $res[1] as $url ) {
316
+ if ( !preg_match('/(elegantthemesimages\.com)|(elegantthemes\.com)/', $url ) )
317
+ array_push( $results, $this->wpmc_clean_url( $url ) );
318
+ }
319
+ }
320
+ }
321
+
322
+ if ( get_option( 'wpmc_background', false ) ) {
323
+ preg_match_all( "/url\(\"?((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"?\)/", $html, $res );
324
+ error_log( print_r( $res, 1 ) );
325
+ if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
326
+ foreach ( $res[1] as $url ) {
327
+ array_push( $results, $this->wpmc_clean_url( $url ) );
328
+ }
329
+ }
330
+ }
331
+
332
  return $results;
333
  }
334
 
508
  $found['wpmc_postmeta_images_acf_ids'] = $postmeta_images_acf_ids;
509
  set_transient( "wpmc_postmeta_images_acf_urls", $postmeta_images_acf_urls, $this->transient_life );
510
  $found['wpmc_postmeta_images_acf_urls'] = $postmeta_images_acf_urls;
 
511
  }
512
  }
513
  }
521
  $posts_images_vc = array();
522
  preg_match_all( "/image=\"([0-9]+)\"/", $html, $res );
523
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
524
+ foreach ( $res[1] as $url ) {
525
+ array_push( $posts_images_vc, $this->wpmc_clean_url( $url ) );
526
+ }
527
  }
528
  set_transient( "wpmc_posts_images_visualcomposer", $posts_images_vc, $this->transient_life );
529
  $found['wpmc_posts_images_visualcomposer'] = $posts_images_vc;
1384
  <input type="search" name="s" style="width: 120px;" value="<?php echo $s ? $s : ""; ?>">
1385
  <input type="hidden" name="page" value="media-cleaner">
1386
  <input type="hidden" name="view" value="<?php echo $view; ?>">
1387
+ <input type="hidden" name="paged" value="1">
1388
  <input type="submit" class="button" value="<?php _e( 'Search', 'media-cleaner' ) ?>"><span style='border-right: #A2A2A2 solid 1px; margin-left: 5px; margin-right: 3px;'>&nbsp;</span>
1389
  </p>
1390
  </form>
media-cleaner.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Media Cleaner
4
  Plugin URI: http://meowapps.com
5
  Description: Clean your Media Library, many options, trash system.
6
- Version: 4.4.6
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-cleaner
@@ -27,7 +27,7 @@ if ( class_exists( 'Meow_WPMC_Core' ) ) {
27
  if ( is_admin() ) {
28
 
29
  global $wpmc_version;
30
- $wpmc_version = '4.4.6';
31
 
32
  // Admin
33
  require( 'wpmc_admin.php' );
3
  Plugin Name: Media Cleaner
4
  Plugin URI: http://meowapps.com
5
  Description: Clean your Media Library, many options, trash system.
6
+ Version: 4.4.7
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-cleaner
27
  if ( is_admin() ) {
28
 
29
  global $wpmc_version;
30
+ $wpmc_version = '4.4.7';
31
 
32
  // Admin
33
  require( 'wpmc_admin.php' );
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: TigrouMeow
3
  Tags: management, admin, file, files, images, image, media, library, upload, clean, cleaning
4
  Requires at least: 4.2
5
  Tested up to: 4.9
6
- Stable tag: 4.4.6
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
@@ -17,7 +17,7 @@ A tutorial is available on the official website, here: [Media Cleaner](https://m
17
 
18
  **COMPATIBILITY**. I am adding support for page builders and specific plugins little by little. Currently, I have been working with ACF, Divi (Elegant Themes), Fusion Builder (Avada), WooCommerce, Visual Composer (WPBakery), Beaver Builder, and Gutenberg.
19
 
20
- **SPECIAL PLUGIN**. Such a plugin is difficult to create and to maintain. If you understand WordPress, you probably know why. This plugin does its best to help you. Get used to it and you will get awesome results.
21
 
22
  **DASHBOARD**. The files detected as not used will be listed in a specific dashboard. At this point, it will be up to you to delete them. They will be then moved to a trash internal to the plugin. After more testing, you can trash them permanently.
23
 
@@ -52,6 +52,12 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
 
55
  = 4.4.6 =
56
  * Update: Support for ACF (Image Field as Object, URL and ID).
57
  * Info: This plugin is hard work, don't hesitate to review it :) Thank you.
3
  Tags: management, admin, file, files, images, image, media, library, upload, clean, cleaning
4
  Requires at least: 4.2
5
  Tested up to: 4.9
6
+ Stable tag: 4.4.7
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
17
 
18
  **COMPATIBILITY**. I am adding support for page builders and specific plugins little by little. Currently, I have been working with ACF, Divi (Elegant Themes), Fusion Builder (Avada), WooCommerce, Visual Composer (WPBakery), Beaver Builder, and Gutenberg.
19
 
20
+ **SPECIAL PLUGIN**. Such a plugin is difficult to create and to maintain. If you understand WordPress, you probably know why. This plugin does its best to help you. Learn how to use it and you will get awesome results.
21
 
22
  **DASHBOARD**. The files detected as not used will be listed in a specific dashboard. At this point, it will be up to you to delete them. They will be then moved to a trash internal to the plugin. After more testing, you can trash them permanently.
23
 
52
 
53
  == Changelog ==
54
 
55
+ = 4.4.7 =
56
+ * Fix: Divi Single Image wasn't always properly detected.
57
+ * Add: Option for CSS background.
58
+ * Update: Code cleaning, slighlty faster now.
59
+ * Info: This plugin is hard work, don't hesitate to review it :) Thank you.
60
+
61
  = 4.4.6 =
62
  * Update: Support for ACF (Image Field as Object, URL and ID).
63
  * Info: This plugin is hard work, don't hesitate to review it :) Thank you.
wpmc_admin.php CHANGED
@@ -63,16 +63,15 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
63
  add_settings_field( 'wpmc_widgets', "Widgets",
64
  array( $this, 'admin_widgets_callback' ),
65
  'wpmc_settings-menu', 'wpmc_settings' );
66
-
67
- if ( get_option( 'wpmc_posts', true ) ) {
68
- add_settings_field( 'wpmc_shortcode', "Shortcodes<br />(Pro)",
69
- array( $this, 'admin_shortcode_callback' ),
70
- 'wpmc_settings-menu', 'wpmc_settings' );
71
- }
72
  add_settings_field( 'wpmc_utf8', "UTF-8",
73
  array( $this, 'admin_utf8_callback' ),
74
  'wpmc_settings-menu', 'wpmc_settings' );
75
-
76
  add_settings_field( 'wpmc_debuglogs', "Logs",
77
  array( $this, 'admin_debuglogs_callback' ),
78
  'wpmc_settings-menu', 'wpmc_settings', array( "Enable" ) );
@@ -105,6 +104,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
105
  register_setting( 'wpmc_settings', 'wpmc_method' );
106
  register_setting( 'wpmc_settings', 'wpmc_posts' );
107
  register_setting( 'wpmc_settings', 'wpmc_shortcode' );
 
108
  register_setting( 'wpmc_settings', 'wpmc_galleries' );
109
  register_setting( 'wpmc_settings', 'wpmc_widgets' );
110
  register_setting( 'wpmc_settings', 'wpmc_media_library' );
@@ -265,6 +265,14 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
265
  echo $html;
266
  }
267
 
 
 
 
 
 
 
 
 
268
  function admin_utf8_callback( $args ) {
269
  $value = get_option( 'wpmc_utf8', null );
270
  $html = '<input type="checkbox" id="wpmc_utf8" name="wpmc_utf8" value="1" ' .
63
  add_settings_field( 'wpmc_widgets', "Widgets",
64
  array( $this, 'admin_widgets_callback' ),
65
  'wpmc_settings-menu', 'wpmc_settings' );
66
+ add_settings_field( 'wpmc_shortcode', "Shortcodes<br />(Pro)",
67
+ array( $this, 'admin_shortcode_callback' ),
68
+ 'wpmc_settings-menu', 'wpmc_settings' );
69
+ add_settings_field( 'wpmc_background', "Background CSS<br />(Pro)",
70
+ array( $this, 'admin_background_callback' ),
71
+ 'wpmc_settings-menu', 'wpmc_settings' );
72
  add_settings_field( 'wpmc_utf8', "UTF-8",
73
  array( $this, 'admin_utf8_callback' ),
74
  'wpmc_settings-menu', 'wpmc_settings' );
 
75
  add_settings_field( 'wpmc_debuglogs', "Logs",
76
  array( $this, 'admin_debuglogs_callback' ),
77
  'wpmc_settings-menu', 'wpmc_settings', array( "Enable" ) );
104
  register_setting( 'wpmc_settings', 'wpmc_method' );
105
  register_setting( 'wpmc_settings', 'wpmc_posts' );
106
  register_setting( 'wpmc_settings', 'wpmc_shortcode' );
107
+ register_setting( 'wpmc_settings', 'wpmc_background' );
108
  register_setting( 'wpmc_settings', 'wpmc_galleries' );
109
  register_setting( 'wpmc_settings', 'wpmc_widgets' );
110
  register_setting( 'wpmc_settings', 'wpmc_media_library' );
265
  echo $html;
266
  }
267
 
268
+ function admin_background_callback( $args ) {
269
+ $value = get_option( 'wpmc_background', null );
270
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_background" name="wpmc_background" value="1" ' .
271
+ checked( 1, get_option( 'wpmc_background' ), false ) . '/>';
272
+ $html .= '<label>Analyze</label><br /><small>When parsing HTML, the CSS inline background will also be analyzed. A few page builders are using this.</small>';
273
+ echo $html;
274
+ }
275
+
276
  function admin_utf8_callback( $args ) {
277
  $value = get_option( 'wpmc_utf8', null );
278
  $html = '<input type="checkbox" id="wpmc_utf8" name="wpmc_utf8" value="1" ' .
wpmc_checkers.php CHANGED
@@ -154,9 +154,12 @@ class Meow_WPMC_Checkers {
154
  $this->core->last_analysis_ids = null;
155
  $shortcode_support = get_option( 'wpmc_shortcode', false );
156
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
157
- $pinfo = pathinfo( $file );
158
- $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
159
- ( isset( $pinfo['extension'] ) ? ( '.' . $pinfo['extension'] ) : '' );
 
 
 
160
 
161
  // Check in Posts Content
162
  if ( get_option( 'wpmc_posts', true ) ) {
154
  $this->core->last_analysis_ids = null;
155
  $shortcode_support = get_option( 'wpmc_shortcode', false );
156
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
157
+
158
+ // I think that was making sense before, but now now.
159
+ // $pinfo = pathinfo( $file );
160
+ // $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
161
+ // ( isset( $pinfo['extension'] ) ? ( '.' . $pinfo['extension'] ) : '' );
162
+ $url = $file;
163
 
164
  // Check in Posts Content
165
  if ( get_option( 'wpmc_posts', true ) ) {