Media Cleaner - Version 4.4.4

Version Description

  • Update: Check DIVI Galleries and Single Images in Beaver Builder.
  • Update: Support for files which aren't images and links (href's).
Download this release

Release Info

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

Code changes from version 4.4.2 to 4.4.4

Files changed (4) hide show
  1. core.php +34 -2
  2. media-cleaner.php +2 -2
  3. readme.txt +12 -6
  4. wpmc_checkers.php +10 -0
core.php CHANGED
@@ -39,7 +39,7 @@ class Meow_WPMC_Core {
39
  function admin_init() {
40
  //$types = get_allowed_mime_types();
41
  //$types = implode( '|', array_keys( $types ) );
42
- $types = "jpg|jpeg|jpe|gif|png|tiff|bmp|csv|pdf|xls|xlsx|doc|docx|tiff|mp3|mp4";
43
  $this->regex_file = str_replace( "MIMETYPES", $types, $this->regex_file );
44
  }
45
 
@@ -284,12 +284,20 @@ class Meow_WPMC_Core {
284
  libxml_use_internal_errors( false );
285
  $dom = new DOMDocument();
286
  @$dom->loadHTML( $html );
 
 
287
  $imgs = $dom->getElementsByTagName( 'img' );
288
  $results = array();
289
  foreach ( $imgs as $img ) {
290
  $src = $this->wpmc_clean_url( $img->getAttribute('src') );
291
  array_push( $results, $src );
292
  }
 
 
 
 
 
 
293
  return $results;
294
  }
295
 
@@ -310,9 +318,11 @@ class Meow_WPMC_Core {
310
  // USE CURRENT THEME AND WP API
311
  $ch = get_custom_header();
312
  if ( !empty( $ch ) && !empty( $ch->url ) ) {
313
- array_push( $ids, $ch->attachment_id );
314
  array_push( $urls, $this->wpmc_clean_url( $ch->url ) );
315
  }
 
 
 
316
  $cl = get_custom_logo();
317
  if ( !empty( $cl ) ) {
318
  $urls = array_merge( $this->get_urls_from_html( $cl ), $urls );
@@ -482,6 +492,22 @@ class Meow_WPMC_Core {
482
 
483
  if ( $check_galleries ) {
484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
  // Galleries in Visual Composer (WPBakery)
486
  if ( class_exists( 'Vc_Manager' ) ) {
487
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
@@ -560,6 +586,7 @@ class Meow_WPMC_Core {
560
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
561
  $galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
562
  $galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
 
563
 
564
  $found['theme_urls'] = is_array( $theme_urls ) ? array_unique( $theme_urls ) : array();
565
  $found['theme_ids'] = is_array( $theme_ids ) ? array_unique( $theme_ids ) : array();
@@ -574,6 +601,7 @@ class Meow_WPMC_Core {
574
  $found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
575
  $found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
576
  $found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
 
577
 
578
  // For safety, remove the resolutions...
579
  // That will match more files, especially the sizes created before, used before, but not part of the
@@ -595,6 +623,7 @@ class Meow_WPMC_Core {
595
  set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], $this->transient_life );
596
  set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], $this->transient_life );
597
  set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], $this->transient_life );
 
598
  set_transient( "wpmc_galleries_images", $found['galleries_images'], $this->transient_life );
599
  }
600
  if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
@@ -991,6 +1020,7 @@ class Meow_WPMC_Core {
991
  $upload_folder = wp_upload_dir();
992
  $basedir = $upload_folder['basedir'];
993
  $file = str_replace( $basedir, '', $fullpath );
 
994
  $file = trim( $file, "/" );
995
  return $file;
996
  }
@@ -1060,6 +1090,7 @@ class Meow_WPMC_Core {
1060
  }
1061
  }
1062
  } else {
 
1063
  $issue = 'ORPHAN_MEDIA';
1064
  }
1065
 
@@ -1102,6 +1133,7 @@ class Meow_WPMC_Core {
1102
  delete_transient( "wpmc_galleries_images_visualcomposer" );
1103
  delete_transient( "wpmc_galleries_images_fusionbuilder" );
1104
  delete_transient( "wpmc_galleries_images_woocommerce" );
 
1105
  delete_transient( "wpmc_galleries_images" );
1106
  }
1107
 
39
  function admin_init() {
40
  //$types = get_allowed_mime_types();
41
  //$types = implode( '|', array_keys( $types ) );
42
+ $types = "jpg|jpeg|jpe|gif|png|tiff|bmp|csv|pdf|xls|xlsx|doc|docx|tiff|mp3|mp4|wav|lua";
43
  $this->regex_file = str_replace( "MIMETYPES", $types, $this->regex_file );
44
  }
45
 
284
  libxml_use_internal_errors( false );
285
  $dom = new DOMDocument();
286
  @$dom->loadHTML( $html );
287
+
288
+ // Images
289
  $imgs = $dom->getElementsByTagName( 'img' );
290
  $results = array();
291
  foreach ( $imgs as $img ) {
292
  $src = $this->wpmc_clean_url( $img->getAttribute('src') );
293
  array_push( $results, $src );
294
  }
295
+
296
+ $urls = $dom->getElementsByTagName( 'a' );
297
+ foreach ( $urls as $url ) {
298
+ $src = $this->wpmc_clean_url( $url->getAttribute('href') );
299
+ array_push( $results, $src );
300
+ }
301
  return $results;
302
  }
303
 
318
  // USE CURRENT THEME AND WP API
319
  $ch = get_custom_header();
320
  if ( !empty( $ch ) && !empty( $ch->url ) ) {
 
321
  array_push( $urls, $this->wpmc_clean_url( $ch->url ) );
322
  }
323
+ if ( !empty( $ch ) && !empty( $ch->attachment_id ) ) {
324
+ array_push( $ids, $ch->attachment_id );
325
+ }
326
  $cl = get_custom_logo();
327
  if ( !empty( $cl ) ) {
328
  $urls = array_merge( $this->get_urls_from_html( $cl ), $urls );
492
 
493
  if ( $check_galleries ) {
494
 
495
+ // Galleries in Divi (Elegant Themes)
496
+ if ( function_exists( '_et_core_find_latest' ) ) {
497
+ $galleries_images_et = get_transient( "wpmc_galleries_images_divi" );
498
+ if ( empty( $galleries_images_et ) )
499
+ $galleries_images_et = array();
500
+ preg_match_all( "/gallery_ids=\"([0-9,]+)/", $html, $res );
501
+ if ( !empty( $res ) && isset( $res[1] ) ) {
502
+ foreach ( $res[1] as $r ) {
503
+ $ids = explode( ',', $r );
504
+ $galleries_images_et = array_merge( $galleries_images_et, $ids );
505
+ }
506
+ }
507
+ set_transient( "wpmc_galleries_images_divi", $galleries_images_et, $this->transient_life );
508
+ $found['wpmc_galleries_images_divi'] = $galleries_images_et;
509
+ }
510
+
511
  // Galleries in Visual Composer (WPBakery)
512
  if ( class_exists( 'Vc_Manager' ) ) {
513
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
586
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
587
  $galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
588
  $galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
589
+ $galleries_images_et = get_transient( "wpmc_galleries_images_divi" );
590
 
591
  $found['theme_urls'] = is_array( $theme_urls ) ? array_unique( $theme_urls ) : array();
592
  $found['theme_ids'] = is_array( $theme_ids ) ? array_unique( $theme_ids ) : array();
601
  $found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
602
  $found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
603
  $found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
604
+ $found['galleries_images_et'] = is_array( $galleries_images_et ) ? array_unique( $galleries_images_et ) : array();
605
 
606
  // For safety, remove the resolutions...
607
  // That will match more files, especially the sizes created before, used before, but not part of the
623
  set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], $this->transient_life );
624
  set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], $this->transient_life );
625
  set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], $this->transient_life );
626
+ set_transient( "wpmc_galleries_images_divi", $found['galleries_images_et'], $this->transient_life );
627
  set_transient( "wpmc_galleries_images", $found['galleries_images'], $this->transient_life );
628
  }
629
  if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
1020
  $upload_folder = wp_upload_dir();
1021
  $basedir = $upload_folder['basedir'];
1022
  $file = str_replace( $basedir, '', $fullpath );
1023
+ $file = str_replace( "./", "", $file );
1024
  $file = trim( $file, "/" );
1025
  return $file;
1026
  }
1090
  }
1091
  }
1092
  } else {
1093
+ $this->log( "File {$fullpath} does not exist." );
1094
  $issue = 'ORPHAN_MEDIA';
1095
  }
1096
 
1133
  delete_transient( "wpmc_galleries_images_visualcomposer" );
1134
  delete_transient( "wpmc_galleries_images_fusionbuilder" );
1135
  delete_transient( "wpmc_galleries_images_woocommerce" );
1136
+ delete_transient( "wpmc_galleries_images_divi" );
1137
  delete_transient( "wpmc_galleries_images" );
1138
  }
1139
 
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.2
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.2';
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.4
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.4';
31
 
32
  // Admin
33
  require( 'wpmc_admin.php' );
readme.txt CHANGED
@@ -3,23 +3,25 @@ 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.2
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
10
  == Description ==
11
 
12
- Clean your Media Library from the media which aren't used in any of your posts, gallery and so on. It features an internal trash, moving the files in there temporarily for you to make sure the files aren't actually in used; once checked, you can trash them permanently. **Before using this plugin, make sure you have a proper backup of your files and database. This is the most important step on the usage of this plugin as you can't trust any file deletion tools.** The Pro version of this plugin brings also scanning to the /uploads folder and will detect which files aren't registered in the Media Library, not used in your content and so on. Retina images are also detected and supported, shortcodes, HTML in sidebars and of course your posts, pages and all post types.
 
 
13
 
14
  **This tool is a knife. I do my best to make this knife a perfect one. However, this is still a knife, and in the hands of somebody who doesn't know how to use it, it might end badly. Don't use it if you don't have any backup, or if you don't know what it does. For backup, you can use such a plugin as [UpdraftPlus](https://updraftplus.com/?afref=460).**
15
 
16
- **PAGE BUILDER**. I am adding support for page builders little by little. Each page builder requires a particular code in the Media Cleaner. As for now, Visual Composer by WPBakery is supported.
17
 
18
- **UNIQUE PLUGIN**. Such a plugin is difficult to create and to maintain. If you understand WordPress, you probably know why. This plugin tries its best to help you. Get used to it and you will get awesome results. This is the only plugin to propose those functions and even a dashboard to cleanup your WordPress install from unused files.
19
 
20
- **DASHBOARD**. Those file will be shown in a specific dashboard. At this point, it will be up to you to delete them. Files detected as un-used are added to a specific dashboard where you can choose to trash them. They will be then moved to a trash internal to the plugin. After more testing, you can trash them definitely.
21
 
22
- **FREE / PRO**. The Free version of the plugin works with the media available in your Media Library. The Pro version adds scanning to your physical /uploads directory.
23
 
24
  **AGAIN, BE CAREFUL**. Again, this plugin deletes files so... be careful! Backup is not only important, it is **necessary**. Don't use this plugin if you don't understand how WordPress works. This is a knife, you need to understand what it does and how before using it.
25
 
@@ -50,6 +52,10 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
50
 
51
  == Changelog ==
52
 
 
 
 
 
53
  = 4.4.2 =
54
  * Fix: Too many files were detected as used if WooCommerce was installed.
55
 
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.4
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
10
  == Description ==
11
 
12
+ Clean your Media Library from the media which aren't used in any of your posts, gallery and so on. It features an internal trash, moving the files in there temporarily for you to make sure the files aren't actually in used; once checked, you can trash them permanently. **Before using this plugin, make sure you have a proper backup of your files and database. This is the most important step on the usage of this plugin as you can't trust any file deletion tools.** The Pro version of this plugin brings scanning to the /uploads folder and will detect which files aren't registered in the Media Library, not used in your content and so on. Retina images are also detected and supported, shortcodes, HTML in sidebars and of course your posts, pages and all post types.
13
+
14
+ A tutorial is available on the official website, here: [Media Cleaner](https://meowapps.com/media-cleaner).
15
 
16
  **This tool is a knife. I do my best to make this knife a perfect one. However, this is still a knife, and in the hands of somebody who doesn't know how to use it, it might end badly. Don't use it if you don't have any backup, or if you don't know what it does. For backup, you can use such a plugin as [UpdraftPlus](https://updraftplus.com/?afref=460).**
17
 
18
+ **COMPATIBILITY**. I am adding support for page builders and specific plugins little by little. Currently, I have been working with 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
 
24
+ **FREE / PRO**. The Free version of the plugin analyzes the medias available in your Media Library. [Media Cleaner Pro](https://meowapps.com/media-cleaner) can also scan your physical /uploads directory, and match it against the Media Library.
25
 
26
  **AGAIN, BE CAREFUL**. Again, this plugin deletes files so... be careful! Backup is not only important, it is **necessary**. Don't use this plugin if you don't understand how WordPress works. This is a knife, you need to understand what it does and how before using it.
27
 
52
 
53
  == Changelog ==
54
 
55
+ = 4.4.4 =
56
+ * Update: Check DIVI Galleries and Single Images in Beaver Builder.
57
+ * Update: Support for files which aren't images and links (href's).
58
+
59
  = 4.4.2 =
60
  * Fix: Too many files were detected as used if WooCommerce was installed.
61
 
wpmc_checkers.php CHANGED
@@ -75,6 +75,16 @@ class Meow_WPMC_Checkers {
75
  }
76
  }
77
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
 
80
  /***************************************************************************
75
  }
76
  }
77
 
78
+ // Check in Divi
79
+ if ( function_exists( '_et_core_find_latest' ) ) {
80
+ $galleries_images_et = get_transient( "wpmc_galleries_images_divi" );
81
+ if ( is_array( $galleries_images_et ) && in_array( $mediaId, $galleries_images_et ) ) {
82
+ $this->core->log( "Media {$mediaId} found in a Divi gallery" );
83
+ $this->core->last_analysis = "GALLERY";
84
+ return true;
85
+ }
86
+ }
87
+
88
  }
89
 
90
  /***************************************************************************