Media Cleaner - Version 4.2.5

Version Description

  • Update: Support for WP 4.9.
  • Fix: Could not empty trash if Media was already removed.
Download this release

Release Info

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

Code changes from version 4.2.4 to 4.2.5

Files changed (4) hide show
  1. core.php +20 -19
  2. media-cleaner.php +2 -2
  3. readme.txt +4 -3
  4. wpmc_checkers.php +4 -4
core.php CHANGED
@@ -4,12 +4,13 @@ class Meow_WPMC_Core {
4
 
5
  public $checkers = null;
6
  public $admin = null;
7
-
8
  public $last_analysis = null;
9
  public $last_analysis_ids = null;
 
10
 
11
  public function __construct( $admin ) {
12
  $this->admin = $admin;
 
13
  add_action( 'admin_menu', array( $this, 'admin_menu' ) );
14
  add_action( 'admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
15
  add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ) );
@@ -254,7 +255,7 @@ class Meow_WPMC_Core {
254
  array_walk( $res[0], array( $this, "wpmc_clean_url_direct" ) );
255
  $widgets_images = array_merge( $widgets_images, $res[0] );
256
  }
257
- set_transient( "wpmc_widgets_images", $widgets_images, 60 * 60 * 2 );
258
  $found['wpmc_widgets_images'] = $widgets_images;
259
 
260
 
@@ -276,7 +277,7 @@ class Meow_WPMC_Core {
276
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
277
  $posts_images_vc = array_merge( $posts_images_vc, $res[1] );
278
  }
279
- set_transient( "wpmc_posts_images_visualcomposer", $posts_images_vc, 60 * 60 * 2 );
280
  $found['wpmc_posts_images_visualcomposer'] = $posts_images_vc;
281
  }
282
 
@@ -288,12 +289,12 @@ class Meow_WPMC_Core {
288
  $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
289
  if ( empty( $posts_images_urls ) )
290
  $posts_images_urls = array();
291
- preg_match_all( "/https?:\/\/[^\/\s]+\/\S+\.(jpg|png|gif)/", $html, $res );
292
  if ( !empty( $res ) && isset( $res[0] ) && count( $res[0] ) > 0 ) {
293
  array_walk( $res[0], array( $this, "wpmc_clean_url_direct" ) );
294
  $posts_images_urls = array_merge( $posts_images_urls, $res[0] );
295
  }
296
- set_transient( "wpmc_posts_images_urls", $posts_images_urls, 60 * 60 * 2 );
297
  $found['wpmc_posts_images_urls'] = $posts_images_urls;
298
 
299
  // Check for images IDs through classes in in posts
@@ -303,7 +304,7 @@ class Meow_WPMC_Core {
303
  preg_match_all( "/wp-image-([0-9]+)/", $html, $res );
304
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
305
  $posts_images_ids = array_merge( $posts_images_ids, $res[1] );
306
- set_transient( "wpmc_posts_images_ids", $posts_images_ids, 60 * 60 * 2 );
307
  $found['wpmc_posts_images_ids'] = $posts_images_ids;
308
  }
309
 
@@ -321,7 +322,7 @@ class Meow_WPMC_Core {
321
  $galleries_images_vc = array_merge( $galleries_images_vc, $ids );
322
  }
323
  }
324
- set_transient( "wpmc_galleries_images_visualcomposer", $galleries_images_vc, 60 * 60 * 2 );
325
  $found['wpmc_galleries_images_visualcomposer'] = $galleries_images_vc;
326
  }
327
 
@@ -337,7 +338,7 @@ class Meow_WPMC_Core {
337
  $galleries_images_fb = array_merge( $galleries_images_fb, $ids );
338
  }
339
  }
340
- set_transient( "wpmc_galleries_images_fusionbuilder", $galleries_images_fb, 60 * 60 * 2 );
341
  $found['wpmc_galleries_images_fusionbuilder'] = $galleries_images_fb;
342
  }
343
 
@@ -352,7 +353,7 @@ class Meow_WPMC_Core {
352
  $ids = explode( ',', $values );
353
  $galleries_images_wc = array_merge( $galleries_images_wc, $ids );
354
  }
355
- set_transient( "wpmc_galleries_images_woocommerce", $galleries_images_wc, 60 * 60 * 2 );
356
  $found['wpmc_galleries_images_woocommerce'] = $galleries_images_wc;
357
  }
358
 
@@ -366,7 +367,7 @@ class Meow_WPMC_Core {
366
  array_push( $galleries_images, $this->wpmc_clean_url( $image ) );
367
  }
368
  }
369
- set_transient( "wpmc_galleries_images", $galleries_images, 60 * 60 * 2 );
370
  $found['wpmc_galleries_images'] = $galleries_images;
371
  }
372
  }
@@ -389,14 +390,14 @@ class Meow_WPMC_Core {
389
  $found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
390
  $found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
391
  $found['widgets_images'] = is_array( $widgets_images ) ? array_unique( $widgets_images ) : array();
392
- set_transient( "wpmc_posts_images_urls", $found['posts_images_urls'], 60 * 60 * 2 );
393
- set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], 60 * 60 * 2 );
394
- set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], 60 * 60 * 2 );
395
- set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], 60 * 60 * 2 );
396
- set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], 60 * 60 * 2 );
397
- set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], 60 * 60 * 2 );
398
- set_transient( "wpmc_galleries_images", $found['galleries_images'], 60 * 60 * 2 );
399
- set_transient( "wpmc_widgets_images", $found['widgets_images'], 60 * 60 * 2 );
400
  }
401
  if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
402
  $this->log( print_r( $found, true ) );
@@ -556,7 +557,7 @@ class Meow_WPMC_Core {
556
  }
557
  }
558
  if ( !wp_untrash_post( $issue->postId ) ) {
559
- die( "Failed to untrash Media {$issue->postId}." );
560
  }
561
  $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET deleted = 0 WHERE id = %d", $id ) );
562
  return true;
4
 
5
  public $checkers = null;
6
  public $admin = null;
 
7
  public $last_analysis = null;
8
  public $last_analysis_ids = null;
9
+ public $transient_life = 604800; // 7 days
10
 
11
  public function __construct( $admin ) {
12
  $this->admin = $admin;
13
+ $this->transient_life = 60 * 60 * 24 * 7; // 7 days
14
  add_action( 'admin_menu', array( $this, 'admin_menu' ) );
15
  add_action( 'admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
16
  add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ) );
255
  array_walk( $res[0], array( $this, "wpmc_clean_url_direct" ) );
256
  $widgets_images = array_merge( $widgets_images, $res[0] );
257
  }
258
+ set_transient( "wpmc_widgets_images", $widgets_images, $this->transient_life );
259
  $found['wpmc_widgets_images'] = $widgets_images;
260
 
261
 
277
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
278
  $posts_images_vc = array_merge( $posts_images_vc, $res[1] );
279
  }
280
+ set_transient( "wpmc_posts_images_visualcomposer", $posts_images_vc, $this->transient_life );
281
  $found['wpmc_posts_images_visualcomposer'] = $posts_images_vc;
282
  }
283
 
289
  $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
290
  if ( empty( $posts_images_urls ) )
291
  $posts_images_urls = array();
292
+ preg_match_all( "/https?:\/\/[^\/\s]+\/\S+\.(jpg|jpeg|tiff|png|gif)/", $html, $res );
293
  if ( !empty( $res ) && isset( $res[0] ) && count( $res[0] ) > 0 ) {
294
  array_walk( $res[0], array( $this, "wpmc_clean_url_direct" ) );
295
  $posts_images_urls = array_merge( $posts_images_urls, $res[0] );
296
  }
297
+ set_transient( "wpmc_posts_images_urls", $posts_images_urls, $this->transient_life );
298
  $found['wpmc_posts_images_urls'] = $posts_images_urls;
299
 
300
  // Check for images IDs through classes in in posts
304
  preg_match_all( "/wp-image-([0-9]+)/", $html, $res );
305
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
306
  $posts_images_ids = array_merge( $posts_images_ids, $res[1] );
307
+ set_transient( "wpmc_posts_images_ids", $posts_images_ids, $this->transient_life );
308
  $found['wpmc_posts_images_ids'] = $posts_images_ids;
309
  }
310
 
322
  $galleries_images_vc = array_merge( $galleries_images_vc, $ids );
323
  }
324
  }
325
+ set_transient( "wpmc_galleries_images_visualcomposer", $galleries_images_vc, $this->transient_life );
326
  $found['wpmc_galleries_images_visualcomposer'] = $galleries_images_vc;
327
  }
328
 
338
  $galleries_images_fb = array_merge( $galleries_images_fb, $ids );
339
  }
340
  }
341
+ set_transient( "wpmc_galleries_images_fusionbuilder", $galleries_images_fb, $this->transient_life );
342
  $found['wpmc_galleries_images_fusionbuilder'] = $galleries_images_fb;
343
  }
344
 
353
  $ids = explode( ',', $values );
354
  $galleries_images_wc = array_merge( $galleries_images_wc, $ids );
355
  }
356
+ set_transient( "wpmc_galleries_images_woocommerce", $galleries_images_wc, $this->transient_life );
357
  $found['wpmc_galleries_images_woocommerce'] = $galleries_images_wc;
358
  }
359
 
367
  array_push( $galleries_images, $this->wpmc_clean_url( $image ) );
368
  }
369
  }
370
+ set_transient( "wpmc_galleries_images", $galleries_images, $this->transient_life );
371
  $found['wpmc_galleries_images'] = $galleries_images;
372
  }
373
  }
390
  $found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
391
  $found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
392
  $found['widgets_images'] = is_array( $widgets_images ) ? array_unique( $widgets_images ) : array();
393
+ set_transient( "wpmc_posts_images_urls", $found['posts_images_urls'], $this->transient_life );
394
+ set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], $this->transient_life );
395
+ set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], $this->transient_life );
396
+ set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], $this->transient_life );
397
+ set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], $this->transient_life );
398
+ set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], $this->transient_life );
399
+ set_transient( "wpmc_galleries_images", $found['galleries_images'], $this->transient_life );
400
+ set_transient( "wpmc_widgets_images", $found['widgets_images'], $this->transient_life );
401
  }
402
  if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
403
  $this->log( print_r( $found, true ) );
557
  }
558
  }
559
  if ( !wp_untrash_post( $issue->postId ) ) {
560
+ error_log( "Cleaner: Failed to Untrash Post {$issue->postId} (but deleted it from Cleaner DB)." );
561
  }
562
  $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET deleted = 0 WHERE id = %d", $id ) );
563
  return true;
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.2.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.2.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.2.5
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.2.5';
31
 
32
  // Admin
33
  require( 'wpmc_admin.php' );
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  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.8
6
- Stable tag: 4.2.4
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
@@ -50,7 +50,8 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
50
 
51
  == Changelog ==
52
 
53
- = 4.2.4 =
 
54
  * Fix: Could not empty trash if Media was already removed.
55
 
56
  = 4.2.3 =
2
  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.2.5
7
 
8
  Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
9
 
50
 
51
  == Changelog ==
52
 
53
+ = 4.2.5 =
54
+ * Update: Support for WP 4.9.
55
  * Fix: Could not empty trash if Media was already removed.
56
 
57
  = 4.2.3 =
wpmc_checkers.php CHANGED
@@ -159,7 +159,7 @@ class Meow_WPMC_Checkers {
159
  if ( !empty( $mediaId ) ) {
160
  // Search through the CSS class
161
  $posts_images_ids = get_transient( "wpmc_posts_images_ids" );
162
- if ( in_array( $mediaId, $posts_images_ids ) ) {
163
  $this->core->log( "Media {$mediaId} found in content (Posts Images IDs)" );
164
  return true;
165
  }
@@ -167,7 +167,7 @@ class Meow_WPMC_Checkers {
167
  // Posts in Visual Composer (WPBakery)
168
  if ( class_exists( 'Vc_Manager' ) ) {
169
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
170
- if ( in_array( $mediaId, $posts_images_vc ) ) {
171
  $this->core->log( "Media {$mediaId} found in content (Visual Composer)" );
172
  return true;
173
  }
@@ -176,7 +176,7 @@ class Meow_WPMC_Checkers {
176
 
177
  // Search through the filename
178
  $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
179
- if ( in_array( $url, $posts_images_urls ) ) {
180
  $this->core->log( "URL {$url} found in content (Posts Images URLs)" );
181
  return true;
182
  }
@@ -185,7 +185,7 @@ class Meow_WPMC_Checkers {
185
  // Search in widgets
186
  if ( get_option( 'wpmc_widgets', false ) ) {
187
  $widgets_images = get_transient( "wpmc_widgets_images" );
188
- if ( in_array( $url, $widgets_images ) ) {
189
  $this->core->log( "URL {$url} found in widgets (Widgets Images)" );
190
  $this->core->last_analysis = "WIDGET";
191
  return true;
159
  if ( !empty( $mediaId ) ) {
160
  // Search through the CSS class
161
  $posts_images_ids = get_transient( "wpmc_posts_images_ids" );
162
+ if ( is_array( $posts_images_ids ) && in_array( $mediaId, $posts_images_ids ) ) {
163
  $this->core->log( "Media {$mediaId} found in content (Posts Images IDs)" );
164
  return true;
165
  }
167
  // Posts in Visual Composer (WPBakery)
168
  if ( class_exists( 'Vc_Manager' ) ) {
169
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
170
+ if ( is_array( $posts_images_vc ) && in_array( $mediaId, $posts_images_vc ) ) {
171
  $this->core->log( "Media {$mediaId} found in content (Visual Composer)" );
172
  return true;
173
  }
176
 
177
  // Search through the filename
178
  $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
179
+ if ( is_array( $posts_images_urls ) && in_array( $url, $posts_images_urls ) ) {
180
  $this->core->log( "URL {$url} found in content (Posts Images URLs)" );
181
  return true;
182
  }
185
  // Search in widgets
186
  if ( get_option( 'wpmc_widgets', false ) ) {
187
  $widgets_images = get_transient( "wpmc_widgets_images" );
188
+ if ( is_array( $widgets_images ) && in_array( $url, $widgets_images ) ) {
189
  $this->core->log( "URL {$url} found in widgets (Widgets Images)" );
190
  $this->core->last_analysis = "WIDGET";
191
  return true;