Media Cleaner - Version 4.4.6

Version Description

  • Update: Support for ACF (Image Field as Object, URL and ID).
  • 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.6
Comparing to
See all releases

Code changes from version 4.4.4 to 4.4.6

Files changed (4) hide show
  1. core.php +47 -0
  2. media-cleaner.php +2 -2
  3. readme.txt +6 -2
  4. wpmc_checkers.php +19 -0
core.php CHANGED
@@ -88,6 +88,12 @@ class Meow_WPMC_Core {
88
  else if ( $this->last_analysis == "META (URL)" ) {
89
  echo "Found in meta (as an URL).";
90
  }
 
 
 
 
 
 
91
  else if ( $this->last_analysis == "WIDGET" ) {
92
  echo "Found in widget.";
93
  }
@@ -408,6 +414,8 @@ class Meow_WPMC_Core {
408
 
409
  if ( $check_postmeta ) {
410
  global $wpdb;
 
 
411
  $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta
412
  WHERE post_id = %d
413
  AND meta_key = '_thumbnail_id' $like", $post )
@@ -448,6 +456,36 @@ class Meow_WPMC_Core {
448
  set_transient( "wpmc_postmeta_images_urls", $postmeta_images_urls, $this->transient_life );
449
  $found['wpmc_postmeta_images_urls'] = $postmeta_images_urls;
450
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  }
452
 
453
  if ( $check_posts ) {
@@ -581,6 +619,8 @@ class Meow_WPMC_Core {
581
  $posts_images_ids = get_transient( "wpmc_posts_images_ids" );
582
  $postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
583
  $postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
 
 
584
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
585
  $galleries_images = get_transient( "wpmc_galleries_images" );
586
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
@@ -596,6 +636,8 @@ class Meow_WPMC_Core {
596
  $found['posts_images_ids'] = is_array( $posts_images_ids ) ? array_unique( $posts_images_ids ) : array();
597
  $found['postmeta_images_urls'] = is_array( $postmeta_images_urls ) ? array_unique( $postmeta_images_urls ) : array();
598
  $found['postmeta_images_ids'] = is_array( $postmeta_images_ids ) ? array_unique( $postmeta_images_ids ) : array();
 
 
599
  $found['posts_images_vc'] = is_array( $posts_images_vc ) ? array_unique( $posts_images_vc ) : array();
600
  $found['galleries_images'] = is_array( $galleries_images ) ? array_unique( $galleries_images ) : array();
601
  $found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
@@ -610,6 +652,7 @@ class Meow_WPMC_Core {
610
  array_walk( $found['widgets_urls'], array( $this, 'clean_url_from_resolution' ) );
611
  array_walk( $found['posts_images_urls'], array( $this, 'clean_url_from_resolution' ) );
612
  array_walk( $found['postmeta_images_urls'], array( $this, 'clean_url_from_resolution' ) );
 
613
 
614
  set_transient( "wpmc_theme_urls", $found['theme_urls'], $this->transient_life );
615
  set_transient( "wpmc_theme_ids", $found['theme_ids'], $this->transient_life );
@@ -619,6 +662,8 @@ class Meow_WPMC_Core {
619
  set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], $this->transient_life );
620
  set_transient( "wpmc_postmeta_images_urls", $found['postmeta_images_urls'], $this->transient_life );
621
  set_transient( "wpmc_postmeta_images_ids", $found['postmeta_images_ids'], $this->transient_life );
 
 
622
  set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], $this->transient_life );
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 );
@@ -1129,6 +1174,8 @@ class Meow_WPMC_Core {
1129
  delete_transient( "wpmc_posts_images_ids" );
1130
  delete_transient( "wpmc_postmeta_images_urls" );
1131
  delete_transient( "wpmc_postmeta_images_ids" );
 
 
1132
  delete_transient( "wpmc_posts_images_visualcomposer" );
1133
  delete_transient( "wpmc_galleries_images_visualcomposer" );
1134
  delete_transient( "wpmc_galleries_images_fusionbuilder" );
88
  else if ( $this->last_analysis == "META (URL)" ) {
89
  echo "Found in meta (as an URL).";
90
  }
91
+ else if ( $this->last_analysis == "META ACF (ID)" ) {
92
+ echo "Found in ACF meta (as an ID).";
93
+ }
94
+ else if ( $this->last_analysis == "META ACF (URL)" ) {
95
+ echo "Found in ACF meta (as an URL).";
96
+ }
97
  else if ( $this->last_analysis == "WIDGET" ) {
98
  echo "Found in widget.";
99
  }
414
 
415
  if ( $check_postmeta ) {
416
  global $wpdb;
417
+
418
+ // Detect values in the general (known, based on %like%) Meta Keys
419
  $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta
420
  WHERE post_id = %d
421
  AND meta_key = '_thumbnail_id' $like", $post )
456
  set_transient( "wpmc_postmeta_images_urls", $postmeta_images_urls, $this->transient_life );
457
  $found['wpmc_postmeta_images_urls'] = $postmeta_images_urls;
458
  }
459
+
460
+ // Advanced Custom Fields
461
+ if ( class_exists( 'acf' ) ) {
462
+ $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
463
+ if ( empty( $postmeta_images_acf_ids ) )
464
+ $postmeta_images_acf_ids = array();
465
+ $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
466
+ if ( empty( $postmeta_images_acf_urls ) )
467
+ $postmeta_images_acf_urls = array();
468
+ $fields = get_field_objects( $post );
469
+ if ( is_array( $fields ) ) {
470
+ foreach ( $fields as $field ) {
471
+ if ( $field['type'] == 'image' && $field['save_format'] == 'object' ) {
472
+ array_push( $postmeta_images_acf_ids, $field['value']['id'] );
473
+ array_push( $postmeta_images_acf_urls, $this->wpmc_clean_url( $field['value']['url'] ) );
474
+ }
475
+ if ( $field['type'] == 'image' && $field['save_format'] == 'id' ) {
476
+ array_push( $postmeta_images_acf_ids, $field['value'] );
477
+ }
478
+ if ( $field['type'] == 'image' && $field['save_format'] == 'url' ) {
479
+ array_push( $postmeta_images_acf_urls, $this->wpmc_clean_url( $field['value'] ) );
480
+ }
481
+ }
482
+ set_transient( "wpmc_postmeta_images_acf_ids", $postmeta_images_acf_ids, $this->transient_life );
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
  }
490
 
491
  if ( $check_posts ) {
619
  $posts_images_ids = get_transient( "wpmc_posts_images_ids" );
620
  $postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
621
  $postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
622
+ $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
623
+ $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
624
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
625
  $galleries_images = get_transient( "wpmc_galleries_images" );
626
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
636
  $found['posts_images_ids'] = is_array( $posts_images_ids ) ? array_unique( $posts_images_ids ) : array();
637
  $found['postmeta_images_urls'] = is_array( $postmeta_images_urls ) ? array_unique( $postmeta_images_urls ) : array();
638
  $found['postmeta_images_ids'] = is_array( $postmeta_images_ids ) ? array_unique( $postmeta_images_ids ) : array();
639
+ $found['postmeta_images_acf_urls'] = is_array( $postmeta_images_acf_urls ) ? array_unique( $postmeta_images_acf_urls ) : array();
640
+ $found['postmeta_images_acf_ids'] = is_array( $postmeta_images_acf_ids ) ? array_unique( $postmeta_images_acf_ids ) : array();
641
  $found['posts_images_vc'] = is_array( $posts_images_vc ) ? array_unique( $posts_images_vc ) : array();
642
  $found['galleries_images'] = is_array( $galleries_images ) ? array_unique( $galleries_images ) : array();
643
  $found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
652
  array_walk( $found['widgets_urls'], array( $this, 'clean_url_from_resolution' ) );
653
  array_walk( $found['posts_images_urls'], array( $this, 'clean_url_from_resolution' ) );
654
  array_walk( $found['postmeta_images_urls'], array( $this, 'clean_url_from_resolution' ) );
655
+ array_walk( $found['postmeta_images_acf_urls'], array( $this, 'clean_url_from_resolution' ) );
656
 
657
  set_transient( "wpmc_theme_urls", $found['theme_urls'], $this->transient_life );
658
  set_transient( "wpmc_theme_ids", $found['theme_ids'], $this->transient_life );
662
  set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], $this->transient_life );
663
  set_transient( "wpmc_postmeta_images_urls", $found['postmeta_images_urls'], $this->transient_life );
664
  set_transient( "wpmc_postmeta_images_ids", $found['postmeta_images_ids'], $this->transient_life );
665
+ set_transient( "wpmc_postmeta_images_acf_urls", $found['postmeta_images_acf_urls'], $this->transient_life );
666
+ set_transient( "wpmc_postmeta_images_acf_ids", $found['postmeta_images_acf_ids'], $this->transient_life );
667
  set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], $this->transient_life );
668
  set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], $this->transient_life );
669
  set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], $this->transient_life );
1174
  delete_transient( "wpmc_posts_images_ids" );
1175
  delete_transient( "wpmc_postmeta_images_urls" );
1176
  delete_transient( "wpmc_postmeta_images_ids" );
1177
+ delete_transient( "wpmc_postmeta_images_acf_urls" );
1178
+ delete_transient( "wpmc_postmeta_images_acf_ids" );
1179
  delete_transient( "wpmc_posts_images_visualcomposer" );
1180
  delete_transient( "wpmc_galleries_images_visualcomposer" );
1181
  delete_transient( "wpmc_galleries_images_fusionbuilder" );
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.4
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.4';
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.6
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.6';
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.4
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
@@ -15,7 +15,7 @@ A tutorial is available on the official website, here: [Media Cleaner](https://m
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
 
@@ -52,6 +52,10 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
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).
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
 
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 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
 
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.
58
+
59
  = 4.4.4 =
60
  * Update: Check DIVI Galleries and Single Images in Beaver Builder.
61
  * Update: Support for files which aren't images and links (href's).
wpmc_checkers.php CHANGED
@@ -114,10 +114,20 @@ class Meow_WPMC_Checkers {
114
  return true;
115
  }
116
 
 
 
 
 
 
 
 
 
 
117
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
118
  $pinfo = pathinfo( $file );
119
  $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
120
  ( isset( $pinfo['extension'] ) ? ( '.' . $pinfo['extension'] ) : '' );
 
121
  $postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
122
  if ( is_array( $postmeta_images_urls ) && in_array( $url, $postmeta_images_urls ) ) {
123
  $this->core->log( "URL {$url} found in content (Post Meta URLs)" );
@@ -125,6 +135,15 @@ class Meow_WPMC_Checkers {
125
  return true;
126
  }
127
 
 
 
 
 
 
 
 
 
 
128
  return false;
129
  }
130
 
114
  return true;
115
  }
116
 
117
+ if ( class_exists( 'acf' ) ) {
118
+ $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
119
+ if ( is_array( $postmeta_images_acf_ids ) && in_array( $mediaId, $postmeta_images_acf_ids ) ) {
120
+ $this->core->log( "Media {$mediaId} found in content (Post Meta ACF IDs)" );
121
+ $this->core->last_analysis = "META ACF (ID)";
122
+ return true;
123
+ }
124
+ }
125
+
126
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
127
  $pinfo = pathinfo( $file );
128
  $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
129
  ( isset( $pinfo['extension'] ) ? ( '.' . $pinfo['extension'] ) : '' );
130
+
131
  $postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
132
  if ( is_array( $postmeta_images_urls ) && in_array( $url, $postmeta_images_urls ) ) {
133
  $this->core->log( "URL {$url} found in content (Post Meta URLs)" );
135
  return true;
136
  }
137
 
138
+ if ( class_exists( 'acf' ) ) {
139
+ $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
140
+ if ( is_array( $postmeta_images_acf_urls ) && in_array( $url, $postmeta_images_acf_urls ) ) {
141
+ $this->core->log( "URL {$url} found in content (Post Meta ACF URLs)" );
142
+ $this->core->last_analysis = "META ACF (URL)";
143
+ return true;
144
+ }
145
+ }
146
+
147
  return false;
148
  }
149