Version Description
- Info: This is a MAJOR UPDATE both in term of optimization and detection. Keep my motivation up and give a good review to the plugin here: https://wordpress.org/support/plugin/media-cleaner/reviews/?rate=5#new-post. That helps me a lot.
- Update: Meta Data analysis is now cached, so much faster.
- Update: URL detections became a bit more safer.
- Update: Detect the images used by the themes more than before.
- Fix: Images in widgets weren't detected in many cases.
Download this release
Release Info
Developer | TigrouMeow |
Plugin | Media Cleaner |
Version | 4.4.0 |
Comparing to | |
See all releases |
Code changes from version 4.2.5 to 4.4.0
- core.php +283 -86
- media-cleaner.php +2 -2
- readme.txt +8 -1
- wpmc_checkers.php +44 -69
core.php
CHANGED
@@ -6,11 +6,14 @@ class Meow_WPMC_Core {
|
|
6 |
public $admin = null;
|
7 |
public $last_analysis = null;
|
8 |
public $last_analysis_ids = null;
|
9 |
-
|
|
|
|
|
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' ) );
|
@@ -33,6 +36,13 @@ class Meow_WPMC_Core {
|
|
33 |
$this->checkers = new Meow_WPMC_Checkers( $this );
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
/*******************************************************************************
|
37 |
* METABOX FOR USAGE
|
38 |
******************************************************************************/
|
@@ -52,22 +62,37 @@ class Meow_WPMC_Core {
|
|
52 |
$this->log( "Success " . $success . "\n" );
|
53 |
if ( $success ) {
|
54 |
if ( $this->last_analysis == "CONTENT" ) {
|
55 |
-
echo "Found in
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
else if ( $this->last_analysis == "THEME" ) {
|
58 |
-
echo "Found in
|
|
|
|
|
|
|
59 |
}
|
60 |
else if ( $this->last_analysis == "GALLERY" ) {
|
61 |
-
echo "Found in
|
62 |
}
|
63 |
else if ( $this->last_analysis == "META" ) {
|
64 |
echo "Found in meta.";
|
65 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
else if ( $this->last_analysis == "WIDGET" ) {
|
67 |
echo "Found in widget.";
|
68 |
}
|
69 |
else {
|
70 |
-
echo
|
71 |
}
|
72 |
}
|
73 |
else {
|
@@ -195,14 +220,126 @@ class Meow_WPMC_Core {
|
|
195 |
die;
|
196 |
}
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
function wp_ajax_wpmc_prepare_do() {
|
199 |
$limit = isset( $_POST['limit'] ) ? $_POST['limit'] : 0;
|
200 |
$limitsize = get_option( 'wpmc_posts_buffer', 10 );
|
201 |
if ( empty( $limit ) )
|
202 |
$this->wpmc_reset_issues();
|
|
|
203 |
$check_posts = get_option( 'wpmc_posts', false );
|
204 |
$check_galleries = get_option( 'wpmc_galleries', false );
|
205 |
-
if ( !$check_galleries && !$check_posts ) {
|
206 |
echo json_encode( array(
|
207 |
'results' => array(),
|
208 |
'success' => true,
|
@@ -225,47 +362,81 @@ class Meow_WPMC_Core {
|
|
225 |
$found = array();
|
226 |
$shortcode_support = get_option( 'wpmc_shortcode', false );
|
227 |
|
228 |
-
|
229 |
-
|
230 |
-
$
|
231 |
-
|
232 |
-
$
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
$i = 0;
|
238 |
-
foreach ( $widgets as $widget ) {
|
239 |
-
$widget_class = $syswidgets[$widget]['callback'][0]->option_name;
|
240 |
-
$instance_id = $syswidgets[$widget]['params'][0]['number'];
|
241 |
-
$widget_data = get_option($widget_class);
|
242 |
-
if ( !empty( $widget_data[$instance_id]['text'] ) ) {
|
243 |
-
if ( $shortcode_support )
|
244 |
-
$widgets_content .= do_shortcode( $widget_data[$instance_id]['text'] );
|
245 |
-
else
|
246 |
-
$widgets_content .= $widget_data[$instance_id]['text'];
|
247 |
-
}
|
248 |
-
$i++;
|
249 |
-
}
|
250 |
-
}
|
251 |
-
}
|
252 |
-
$widgets_images = array();
|
253 |
-
preg_match_all( "/https?:\/\/[^\/\s]+\/\S+\.(jpg|png|gif)/", $widgets_content, $res );
|
254 |
-
if ( !empty( $res ) && isset( $res[0] ) && count( $res[0] ) > 0 ) {
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
}
|
263 |
|
|
|
|
|
|
|
|
|
|
|
264 |
// Analyze Posts
|
265 |
foreach ( $posts as $post ) {
|
266 |
|
267 |
$html = get_post_field( 'post_content', $post );
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
if ( $check_posts ) {
|
270 |
|
271 |
// Single Image in Visual Composer (WPBakery)
|
@@ -289,11 +460,9 @@ class Meow_WPMC_Core {
|
|
289 |
$posts_images_urls = get_transient( "wpmc_posts_images_urls" );
|
290 |
if ( empty( $posts_images_urls ) )
|
291 |
$posts_images_urls = array();
|
292 |
-
|
293 |
-
|
294 |
-
|
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 |
|
@@ -374,30 +543,56 @@ class Meow_WPMC_Core {
|
|
374 |
$finished = count( $posts ) < $limitsize;
|
375 |
if ( $finished ) {
|
376 |
$found = array();
|
|
|
|
|
|
|
|
|
|
|
377 |
$posts_images_urls = get_transient( "wpmc_posts_images_urls" );
|
378 |
$posts_images_ids = get_transient( "wpmc_posts_images_ids" );
|
|
|
|
|
379 |
$posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
|
380 |
$galleries_images = get_transient( "wpmc_galleries_images" );
|
381 |
$galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
|
382 |
$galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
|
383 |
$galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
|
384 |
-
|
|
|
|
|
|
|
|
|
385 |
$found['posts_images_urls'] = is_array( $posts_images_urls ) ? array_unique( $posts_images_urls ) : array();
|
386 |
$found['posts_images_ids'] = is_array( $posts_images_ids ) ? array_unique( $posts_images_ids ) : array();
|
|
|
|
|
387 |
$found['posts_images_vc'] = is_array( $posts_images_vc ) ? array_unique( $posts_images_vc ) : array();
|
388 |
$found['galleries_images'] = is_array( $galleries_images ) ? array_unique( $galleries_images ) : array();
|
389 |
$found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ) );
|
@@ -599,7 +794,11 @@ class Meow_WPMC_Core {
|
|
599 |
function wpmc_ignore( $id ) {
|
600 |
global $wpdb;
|
601 |
$table_name = $wpdb->prefix . "wpmcleaner";
|
602 |
-
$wpdb->
|
|
|
|
|
|
|
|
|
603 |
return true;
|
604 |
}
|
605 |
|
@@ -765,8 +964,10 @@ class Meow_WPMC_Core {
|
|
765 |
return $sizes;
|
766 |
}
|
767 |
|
768 |
-
function
|
769 |
-
$
|
|
|
|
|
770 |
}
|
771 |
|
772 |
// From a url to the shortened and cleaned url (for example '2013/02/file.png')
|
@@ -818,23 +1019,14 @@ class Meow_WPMC_Core {
|
|
818 |
$this->last_analysis = "IGNORED";
|
819 |
return true;
|
820 |
}
|
821 |
-
if ( $this->checkers->has_background_or_header( $mainfile, $attachmentId ) )
|
822 |
-
$this->last_analysis = "THEME";
|
823 |
return true;
|
824 |
-
|
825 |
-
if ( $this->checkers->has_content( $mainfile, $attachmentId ) ) {
|
826 |
-
if ( empty( $this->last_analysis ) )
|
827 |
-
$this->last_analysis = "CONTENT";
|
828 |
return true;
|
829 |
-
|
830 |
-
if ( $this->checkers->check_in_gallery( $mainfile, $attachmentId ) ) {
|
831 |
-
$this->last_analysis = "GALLERY";
|
832 |
return true;
|
833 |
-
|
834 |
-
if ( $this->checkers->has_meta( $mainfile, $attachmentId ) ) {
|
835 |
-
$this->last_analysis = "META";
|
836 |
return true;
|
837 |
-
}
|
838 |
|
839 |
// If images, check the other files as well
|
840 |
$countfiles = 0;
|
@@ -853,23 +1045,14 @@ class Meow_WPMC_Core {
|
|
853 |
$this->log( "Checking Media #{$attachmentId}: {$file}" );
|
854 |
|
855 |
// ANALYSIS
|
856 |
-
if ( $this->checkers->has_content( $file, $attachmentId ) )
|
857 |
-
$this->last_analysis = "CONTENT";
|
858 |
return true;
|
859 |
-
|
860 |
-
if ( $this->checkers->check_in_gallery( $file, $attachmentId ) ) {
|
861 |
-
$this->last_analysis = "GALLERY";
|
862 |
return true;
|
863 |
-
|
864 |
-
if ( $this->checkers->has_background_or_header( $file, $attachmentId ) ) {
|
865 |
-
$this->last_analysis = "THEME";
|
866 |
return true;
|
867 |
-
|
868 |
-
if ( $this->checkers->has_meta( $file, $attachmentId ) ) {
|
869 |
-
$this->last_analysis = "META";
|
870 |
return true;
|
871 |
-
}
|
872 |
-
|
873 |
}
|
874 |
}
|
875 |
}
|
@@ -904,14 +1087,19 @@ class Meow_WPMC_Core {
|
|
904 |
if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
|
905 |
file_put_contents( plugin_dir_path( __FILE__ ) . '/media-cleaner.log', '' );
|
906 |
}
|
|
|
|
|
|
|
|
|
907 |
delete_transient( "wpmc_posts_images_urls" );
|
908 |
delete_transient( "wpmc_posts_images_ids" );
|
|
|
|
|
909 |
delete_transient( "wpmc_posts_images_visualcomposer" );
|
910 |
delete_transient( "wpmc_galleries_images_visualcomposer" );
|
911 |
delete_transient( "wpmc_galleries_images_fusionbuilder" );
|
912 |
delete_transient( "wpmc_galleries_images_woocommerce" );
|
913 |
delete_transient( "wpmc_galleries_images" );
|
914 |
-
delete_transient( "wpmc_widgets_images" );
|
915 |
}
|
916 |
|
917 |
/**
|
@@ -957,11 +1145,14 @@ class Meow_WPMC_Core {
|
|
957 |
$table_name = $wpdb->prefix . "wpmcleaner";
|
958 |
$res = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE postId = %d", $post->ID ) );
|
959 |
if ( !empty( $res ) && isset( $actions['delete'] ) )
|
960 |
-
$actions['delete'] = "<a href='?page=media-cleaner&view=deleted'>
|
|
|
961 |
if ( !empty( $res ) && isset( $actions['trash'] ) )
|
962 |
-
$actions['trash'] = "<a href='?page=media-cleaner'>
|
|
|
963 |
if ( !empty( $res ) && isset( $actions['untrash'] ) ) {
|
964 |
-
$actions['untrash'] = "<a href='?page=media-cleaner&view=deleted'>
|
|
|
965 |
}
|
966 |
return $actions;
|
967 |
}
|
@@ -1059,7 +1250,13 @@ class Meow_WPMC_Core {
|
|
1059 |
<?php } ?>
|
1060 |
|
1061 |
<!-- IGNORE SELECTED -->
|
1062 |
-
<a id='wpmc_ignore' onclick='wpmc_ignore()' class='button' style='float: left; margin-left: 5px;'><span style="top: 3px; position: relative; left: -5px;" class="dashicons dashicons-yes"></span><?php
|
|
|
|
|
|
|
|
|
|
|
|
|
1063 |
|
1064 |
<!-- RESET -->
|
1065 |
<?php if ( $view != 'deleted' ) { ?>
|
@@ -1102,7 +1299,7 @@ class Meow_WPMC_Core {
|
|
1102 |
}
|
1103 |
|
1104 |
if ( !MEDIA_TRASH ) {
|
1105 |
-
_e( "<div class='notice notice-warning'><p>The trash for the Media Library is disabled. Any media removed by the plugin will be <b>permanently deleted</b>. To enable it, modify your wp-config.php file and add this line (preferably at the top):<br /><b>define( 'MEDIA_TRASH', true );</b></p></div>" );
|
1106 |
}
|
1107 |
|
1108 |
if ( !$this->admin->is_registered() ) {
|
@@ -1111,19 +1308,19 @@ class Meow_WPMC_Core {
|
|
1111 |
echo "</p></div>";
|
1112 |
}
|
1113 |
|
1114 |
-
$anychecks = get_option( 'wpmc_posts',
|
1115 |
-
get_option('
|
1116 |
$check_library = get_option(' wpmc_media_library', false );
|
1117 |
|
1118 |
if ( $method == 'media' ) {
|
1119 |
if ( !$anychecks )
|
1120 |
-
_e( "<div class='error'><p>Media Cleaner will analyze your Media Library. There is
|
1121 |
else
|
1122 |
_e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Media Library.</p></div>", 'media-cleaner' );
|
1123 |
}
|
1124 |
else if ( $method == 'files' ) {
|
1125 |
if ( !$anychecks && !$check_library )
|
1126 |
-
_e( "<div class='error'><p>Media Cleaner will analyze your Filesystem. There is
|
1127 |
else
|
1128 |
_e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Filesystem.</p></div>", 'media-cleaner' );
|
1129 |
}
|
6 |
public $admin = null;
|
7 |
public $last_analysis = null;
|
8 |
public $last_analysis_ids = null;
|
9 |
+
private $transient_life = 604800; // 7 days
|
10 |
+
private $regex_file = '/[A-Za-z0-9-_,\s]+[.]{1}(MIMETYPES)/';
|
11 |
+
private $metakeys = array( '%gallery%', '%ids%' );
|
12 |
|
13 |
public function __construct( $admin ) {
|
14 |
$this->admin = $admin;
|
15 |
$this->transient_life = 60 * 60 * 24 * 7; // 7 days
|
16 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
17 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
18 |
add_action( 'admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
|
19 |
add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ) );
|
36 |
$this->checkers = new Meow_WPMC_Checkers( $this );
|
37 |
}
|
38 |
|
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 |
+
|
46 |
/*******************************************************************************
|
47 |
* METABOX FOR USAGE
|
48 |
******************************************************************************/
|
62 |
$this->log( "Success " . $success . "\n" );
|
63 |
if ( $success ) {
|
64 |
if ( $this->last_analysis == "CONTENT" ) {
|
65 |
+
echo "Found in content.";
|
66 |
+
}
|
67 |
+
else if ( $this->last_analysis == "CONTENT (ID)" ) {
|
68 |
+
echo "Found in content (as an ID).";
|
69 |
+
}
|
70 |
+
else if ( $this->last_analysis == "CONTENT (URL)" ) {
|
71 |
+
echo "Found in content (as an URL).";
|
72 |
}
|
73 |
else if ( $this->last_analysis == "THEME" ) {
|
74 |
+
echo "Found in theme.";
|
75 |
+
}
|
76 |
+
else if ( $this->last_analysis == "VISUAL COMPOSER" ) {
|
77 |
+
echo "Found in Visual Composer.";
|
78 |
}
|
79 |
else if ( $this->last_analysis == "GALLERY" ) {
|
80 |
+
echo "Found in gallery.";
|
81 |
}
|
82 |
else if ( $this->last_analysis == "META" ) {
|
83 |
echo "Found in meta.";
|
84 |
}
|
85 |
+
else if ( $this->last_analysis == "META (ID)" ) {
|
86 |
+
echo "Found in meta (as an ID).";
|
87 |
+
}
|
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 |
}
|
94 |
else {
|
95 |
+
echo $this->last_analysis;
|
96 |
}
|
97 |
}
|
98 |
else {
|
220 |
die;
|
221 |
}
|
222 |
|
223 |
+
function array_to_ids_or_urls( &$meta, &$ids, &$urls ) {
|
224 |
+
foreach ( $meta as $k => $m ) {
|
225 |
+
if ( is_numeric( $m ) ) {
|
226 |
+
// Probably a Media ID
|
227 |
+
if ( $m > 0 )
|
228 |
+
array_push( $ids, $m );
|
229 |
+
}
|
230 |
+
else if ( is_array( $m ) ) {
|
231 |
+
// If it's an array with a width, probably that the index is the Media ID
|
232 |
+
if ( isset( $m['width'] ) && is_numeric( $k ) ) {
|
233 |
+
if ( $k > 0 )
|
234 |
+
array_push( $ids, $k );
|
235 |
+
}
|
236 |
+
}
|
237 |
+
else if ( !empty( $m ) ) {
|
238 |
+
// If it's a string, maybe it's a file (with an extension)
|
239 |
+
if ( preg_match($this->regex_file, $m ) )
|
240 |
+
array_push( $urls, $m );
|
241 |
+
}
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
function get_images_from_widgets( &$ids, &$urls ) {
|
246 |
+
global $wp_registered_widgets;
|
247 |
+
$syswidgets = $wp_registered_widgets;
|
248 |
+
$active_widgets = get_option( 'sidebars_widgets' );
|
249 |
+
$shortcode_support = get_option( 'wpmc_shortcode', false );
|
250 |
+
foreach ( $active_widgets as $sidebar_name => $widgets ) {
|
251 |
+
if ( $sidebar_name != 'wp_inactive_widgets' && !empty( $widgets ) && is_array( $widgets ) ) {
|
252 |
+
$i = 0;
|
253 |
+
foreach ( $widgets as $key => $widget ) {
|
254 |
+
$widget_class = $syswidgets[$widget]['callback'][0]->option_name;
|
255 |
+
$instance_id = $syswidgets[$widget]['params'][0]['number'];
|
256 |
+
$widget_data = get_option( $widget_class );
|
257 |
+
// error_log( "INSTANCE $key ($instance_id)" );
|
258 |
+
// error_log( print_r( $widget_data, 1 ) );
|
259 |
+
if ( !empty( $widget_data[$instance_id]['text'] ) ) {
|
260 |
+
$html = $shortcode_support ? do_shortcode( $widget_data[$instance_id]['text'] ) : $widget_data[$instance_id]['text'];
|
261 |
+
$urls = array_merge( $urls, $this->get_urls_from_html( $html ) );
|
262 |
+
}
|
263 |
+
if ( !empty( $widget_data[$instance_id]['attachment_id'] ) ) {
|
264 |
+
$id = $widget_data[$instance_id]['attachment_id'];
|
265 |
+
array_push( $ids, $id );
|
266 |
+
}
|
267 |
+
if ( !empty( $widget_data[$instance_id]['url'] ) ) {
|
268 |
+
$url = $this->wpmc_clean_url( $widget_data[$instance_id]['url'] );
|
269 |
+
array_push( $urls, $url );
|
270 |
+
}
|
271 |
+
if ( !empty( $widget_data[$instance_id]['ids'] ) ) {
|
272 |
+
$newIds = $widget_data[$instance_id]['ids'];
|
273 |
+
$ids = array_merge( $ids, $newIds );
|
274 |
+
}
|
275 |
+
$i++;
|
276 |
+
}
|
277 |
+
}
|
278 |
+
}
|
279 |
+
}
|
280 |
+
|
281 |
+
function get_urls_from_html( $html ) {
|
282 |
+
if ( empty( $html ) )
|
283 |
+
return array();
|
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 |
+
|
296 |
+
function get_images_from_themes( &$ids, &$urls ) {
|
297 |
+
global $wpdb;
|
298 |
+
|
299 |
+
// PARSE OPTIONS
|
300 |
+
// $metas = $wpdb->get_col( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE 'theme_mods_%'" );
|
301 |
+
// foreach ( $metas as $meta ) {
|
302 |
+
// $decoded = @unserialize( $meta );
|
303 |
+
// if ( is_array( $decoded ) ) {
|
304 |
+
// error_log( print_r( $decoded, 1 ) );
|
305 |
+
// $this->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
|
306 |
+
// continue;
|
307 |
+
// }
|
308 |
+
// }
|
309 |
+
|
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 );
|
319 |
+
}
|
320 |
+
$cd = get_background_image();
|
321 |
+
if ( !empty( $cd ) ) {
|
322 |
+
array_push( $urls, $this->wpmc_clean_url( $cd ) );
|
323 |
+
}
|
324 |
+
$photography_hero_image = get_theme_mod( 'photography_hero_image' );
|
325 |
+
if ( !empty( $photography_hero_image ) ) {
|
326 |
+
array_push( $ids, $photography_hero_image );
|
327 |
+
}
|
328 |
+
$author_profile_picture = get_theme_mod( 'author_profile_picture' );
|
329 |
+
if ( !empty( $author_profile_picture ) ) {
|
330 |
+
array_push( $ids, $author_profile_picture );
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
function wp_ajax_wpmc_prepare_do() {
|
335 |
$limit = isset( $_POST['limit'] ) ? $_POST['limit'] : 0;
|
336 |
$limitsize = get_option( 'wpmc_posts_buffer', 10 );
|
337 |
if ( empty( $limit ) )
|
338 |
$this->wpmc_reset_issues();
|
339 |
+
$check_postmeta = get_option( 'wpmc_postmeta', false );
|
340 |
$check_posts = get_option( 'wpmc_posts', false );
|
341 |
$check_galleries = get_option( 'wpmc_galleries', false );
|
342 |
+
if ( !$check_galleries && !$check_posts && !$check_postmeta ) {
|
343 |
echo json_encode( array(
|
344 |
'results' => array(),
|
345 |
'success' => true,
|
362 |
$found = array();
|
363 |
$shortcode_support = get_option( 'wpmc_shortcode', false );
|
364 |
|
365 |
+
if ( empty( $limit ) ) {
|
366 |
+
$theme_ids = array();
|
367 |
+
$theme_urls = array();
|
368 |
+
$this->get_images_from_themes( $theme_ids, $theme_urls );
|
369 |
+
set_transient( "wpmc_theme_ids", $theme_ids, $this->transient_life );
|
370 |
+
set_transient( "wpmc_theme_urls", $theme_urls, $this->transient_life );
|
371 |
+
$found['wpmc_theme_ids'] = $theme_ids;
|
372 |
+
$found['wpmc_theme_urls'] = $theme_urls;
|
373 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
374 |
|
375 |
+
// Analyze Widgets (only on start)
|
376 |
+
if ( get_option( 'wpmc_widgets', false ) && empty( $limit ) ) {
|
377 |
+
$widgets_ids = array();
|
378 |
+
$widgets_urls = array();
|
379 |
+
$this->get_images_from_widgets( $widgets_ids, $widgets_urls );
|
380 |
+
set_transient( "wpmc_widgets_ids", $widgets_ids, $this->transient_life );
|
381 |
+
set_transient( "wpmc_widgets_urls", $widgets_urls, $this->transient_life );
|
382 |
+
$found['wpmc_widgets_ids'] = $widgets_ids;
|
383 |
+
$found['wpmc_widgets_urls'] = $widgets_urls;
|
384 |
}
|
385 |
|
386 |
+
// Prepare likes for SQL
|
387 |
+
$like = "";
|
388 |
+
foreach ( $this->metakeys as $metakey )
|
389 |
+
$like .= "OR meta_key LIKE '$metakey' ";
|
390 |
+
|
391 |
// Analyze Posts
|
392 |
foreach ( $posts as $post ) {
|
393 |
|
394 |
$html = get_post_field( 'post_content', $post );
|
395 |
|
396 |
+
if ( $check_postmeta ) {
|
397 |
+
global $wpdb;
|
398 |
+
$metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta
|
399 |
+
WHERE post_id = %d
|
400 |
+
AND meta_key = '_thumbnail_id' $like", $post )
|
401 |
+
);
|
402 |
+
if ( count( $metas ) > 0 ) {
|
403 |
+
$postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
|
404 |
+
if ( empty( $postmeta_images_ids ) )
|
405 |
+
$postmeta_images_ids = array();
|
406 |
+
$postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
|
407 |
+
if ( empty( $postmeta_images_urls ) )
|
408 |
+
$postmeta_images_urls = array();
|
409 |
+
|
410 |
+
foreach ( $metas as $meta ) {
|
411 |
+
// Just a number, let's assume it's a Media ID
|
412 |
+
if ( is_numeric( $meta ) ) {
|
413 |
+
//error_log( "META NUMERIC: " . $meta );
|
414 |
+
if ( $meta > 0 )
|
415 |
+
array_push( $postmeta_images_ids, $meta );
|
416 |
+
continue;
|
417 |
+
}
|
418 |
+
$decoded = @unserialize( $meta );
|
419 |
+
if ( is_array( $decoded ) ) {
|
420 |
+
// error_log( "META DECODED" );
|
421 |
+
// error_log( print_r( $decoded, 1 ) );
|
422 |
+
$this->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
|
423 |
+
continue;
|
424 |
+
}
|
425 |
+
$exploded = explode( ',', $meta );
|
426 |
+
if ( is_array( $exploded ) ) {
|
427 |
+
// error_log( "META EXPLODED" );
|
428 |
+
// error_log( print_r( $exploded, 1 ) );
|
429 |
+
$this->array_to_ids_or_urls( $exploded, $postmeta_images_ids, $postmeta_images_urls );
|
430 |
+
continue;
|
431 |
+
}
|
432 |
+
}
|
433 |
+
set_transient( "wpmc_postmeta_images_ids", $postmeta_images_ids, $this->transient_life );
|
434 |
+
$found['wpmc_postmeta_images_ids'] = $postmeta_images_ids;
|
435 |
+
set_transient( "wpmc_postmeta_images_urls", $postmeta_images_urls, $this->transient_life );
|
436 |
+
$found['wpmc_postmeta_images_urls'] = $postmeta_images_urls;
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
if ( $check_posts ) {
|
441 |
|
442 |
// Single Image in Visual Composer (WPBakery)
|
460 |
$posts_images_urls = get_transient( "wpmc_posts_images_urls" );
|
461 |
if ( empty( $posts_images_urls ) )
|
462 |
$posts_images_urls = array();
|
463 |
+
|
464 |
+
$new_urls = $this->get_urls_from_html( $html );
|
465 |
+
$posts_images_urls = array_merge( $posts_images_urls, $new_urls );
|
|
|
|
|
466 |
set_transient( "wpmc_posts_images_urls", $posts_images_urls, $this->transient_life );
|
467 |
$found['wpmc_posts_images_urls'] = $posts_images_urls;
|
468 |
|
543 |
$finished = count( $posts ) < $limitsize;
|
544 |
if ( $finished ) {
|
545 |
$found = array();
|
546 |
+
|
547 |
+
$theme_urls = get_transient( "wpmc_theme_urls" );
|
548 |
+
$theme_ids = get_transient( "wpmc_theme_ids" );
|
549 |
+
$widgets_urls = get_transient( "wpmc_widgets_urls" );
|
550 |
+
$widgets_ids = get_transient( "wpmc_widgets_ids" );
|
551 |
$posts_images_urls = get_transient( "wpmc_posts_images_urls" );
|
552 |
$posts_images_ids = get_transient( "wpmc_posts_images_ids" );
|
553 |
+
$postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
|
554 |
+
$postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
|
555 |
$posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
|
556 |
$galleries_images = get_transient( "wpmc_galleries_images" );
|
557 |
$galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
|
558 |
$galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
|
559 |
$galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
|
560 |
+
|
561 |
+
$found['theme_urls'] = is_array( $theme_urls ) ? array_unique( $theme_urls ) : array();
|
562 |
+
$found['theme_ids'] = is_array( $theme_ids ) ? array_unique( $theme_ids ) : array();
|
563 |
+
$found['widgets_urls'] = is_array( $widgets_urls ) ? array_unique( $widgets_urls ) : array();
|
564 |
+
$found['widgets_ids'] = is_array( $widgets_ids ) ? array_unique( $widgets_ids ) : array();
|
565 |
$found['posts_images_urls'] = is_array( $posts_images_urls ) ? array_unique( $posts_images_urls ) : array();
|
566 |
$found['posts_images_ids'] = is_array( $posts_images_ids ) ? array_unique( $posts_images_ids ) : array();
|
567 |
+
$found['postmeta_images_urls'] = is_array( $postmeta_images_urls ) ? array_unique( $postmeta_images_urls ) : array();
|
568 |
+
$found['postmeta_images_ids'] = is_array( $postmeta_images_ids ) ? array_unique( $postmeta_images_ids ) : array();
|
569 |
$found['posts_images_vc'] = is_array( $posts_images_vc ) ? array_unique( $posts_images_vc ) : array();
|
570 |
$found['galleries_images'] = is_array( $galleries_images ) ? array_unique( $galleries_images ) : array();
|
571 |
$found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
|
572 |
$found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
|
573 |
$found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
|
574 |
+
|
575 |
+
// For safety, remove the resolutions...
|
576 |
+
// That will match more files, especially the sizes created before, used before, but not part of the
|
577 |
+
// media metadata anymore.
|
578 |
+
array_walk( $found['theme_urls'], array( $this, 'clean_url_from_resolution' ) );
|
579 |
+
array_walk( $found['widgets_urls'], array( $this, 'clean_url_from_resolution' ) );
|
580 |
+
array_walk( $found['posts_images_urls'], array( $this, 'clean_url_from_resolution' ) );
|
581 |
+
array_walk( $found['postmeta_images_urls'], array( $this, 'clean_url_from_resolution' ) );
|
582 |
+
|
583 |
+
set_transient( "wpmc_theme_urls", $found['theme_urls'], $this->transient_life );
|
584 |
+
set_transient( "wpmc_theme_ids", $found['theme_ids'], $this->transient_life );
|
585 |
+
set_transient( "wpmc_widgets_urls", $found['widgets_urls'], $this->transient_life );
|
586 |
+
set_transient( "wpmc_widgets_ids", $found['widgets_ids'], $this->transient_life );
|
587 |
set_transient( "wpmc_posts_images_urls", $found['posts_images_urls'], $this->transient_life );
|
588 |
set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], $this->transient_life );
|
589 |
+
set_transient( "wpmc_postmeta_images_urls", $found['postmeta_images_urls'], $this->transient_life );
|
590 |
+
set_transient( "wpmc_postmeta_images_ids", $found['postmeta_images_ids'], $this->transient_life );
|
591 |
set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], $this->transient_life );
|
592 |
set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], $this->transient_life );
|
593 |
set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], $this->transient_life );
|
594 |
set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], $this->transient_life );
|
595 |
set_transient( "wpmc_galleries_images", $found['galleries_images'], $this->transient_life );
|
|
|
596 |
}
|
597 |
if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
|
598 |
$this->log( print_r( $found, true ) );
|
794 |
function wpmc_ignore( $id ) {
|
795 |
global $wpdb;
|
796 |
$table_name = $wpdb->prefix . "wpmcleaner";
|
797 |
+
$has = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $table_name WHERE id = %d AND ignored = 1", $id ) );
|
798 |
+
if ( $has > 0 )
|
799 |
+
$wpdb->query( $wpdb->prepare( "UPDATE $table_name SET ignored = 0 WHERE id = %d", $id ) );
|
800 |
+
else
|
801 |
+
$wpdb->query( $wpdb->prepare( "UPDATE $table_name SET ignored = 1 WHERE id = %d", $id ) );
|
802 |
return true;
|
803 |
}
|
804 |
|
964 |
return $sizes;
|
965 |
}
|
966 |
|
967 |
+
function clean_url_from_resolution( &$url ) {
|
968 |
+
$pattern = '/[_-]\d+x\d+(?=\.[a-z]{3,4}$)/';
|
969 |
+
$url = preg_replace( $pattern, '', $url );
|
970 |
+
return $url;
|
971 |
}
|
972 |
|
973 |
// From a url to the shortened and cleaned url (for example '2013/02/file.png')
|
1019 |
$this->last_analysis = "IGNORED";
|
1020 |
return true;
|
1021 |
}
|
1022 |
+
if ( $this->checkers->has_background_or_header( $mainfile, $attachmentId ) )
|
|
|
1023 |
return true;
|
1024 |
+
if ( $this->checkers->has_content( $mainfile, $attachmentId ) )
|
|
|
|
|
|
|
1025 |
return true;
|
1026 |
+
if ( $this->checkers->check_in_gallery( $mainfile, $attachmentId ) )
|
|
|
|
|
1027 |
return true;
|
1028 |
+
if ( $this->checkers->has_meta( $mainfile, $attachmentId ) )
|
|
|
|
|
1029 |
return true;
|
|
|
1030 |
|
1031 |
// If images, check the other files as well
|
1032 |
$countfiles = 0;
|
1045 |
$this->log( "Checking Media #{$attachmentId}: {$file}" );
|
1046 |
|
1047 |
// ANALYSIS
|
1048 |
+
if ( $this->checkers->has_content( $file, $attachmentId ) )
|
|
|
1049 |
return true;
|
1050 |
+
if ( $this->checkers->check_in_gallery( $file, $attachmentId ) )
|
|
|
|
|
1051 |
return true;
|
1052 |
+
if ( $this->checkers->has_background_or_header( $file, $attachmentId ) )
|
|
|
|
|
1053 |
return true;
|
1054 |
+
if ( $this->checkers->has_meta( $file, $attachmentId ) )
|
|
|
|
|
1055 |
return true;
|
|
|
|
|
1056 |
}
|
1057 |
}
|
1058 |
}
|
1087 |
if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
|
1088 |
file_put_contents( plugin_dir_path( __FILE__ ) . '/media-cleaner.log', '' );
|
1089 |
}
|
1090 |
+
delete_transient( "wpmc_theme_ids" );
|
1091 |
+
delete_transient( "wpmc_theme_urls" );
|
1092 |
+
delete_transient( "wpmc_widgets_ids" );
|
1093 |
+
delete_transient( "wpmc_widgets_urls" );
|
1094 |
delete_transient( "wpmc_posts_images_urls" );
|
1095 |
delete_transient( "wpmc_posts_images_ids" );
|
1096 |
+
delete_transient( "wpmc_postmeta_images_urls" );
|
1097 |
+
delete_transient( "wpmc_postmeta_images_ids" );
|
1098 |
delete_transient( "wpmc_posts_images_visualcomposer" );
|
1099 |
delete_transient( "wpmc_galleries_images_visualcomposer" );
|
1100 |
delete_transient( "wpmc_galleries_images_fusionbuilder" );
|
1101 |
delete_transient( "wpmc_galleries_images_woocommerce" );
|
1102 |
delete_transient( "wpmc_galleries_images" );
|
|
|
1103 |
}
|
1104 |
|
1105 |
/**
|
1145 |
$table_name = $wpdb->prefix . "wpmcleaner";
|
1146 |
$res = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE postId = %d", $post->ID ) );
|
1147 |
if ( !empty( $res ) && isset( $actions['delete'] ) )
|
1148 |
+
$actions['delete'] = "<a href='?page=media-cleaner&view=deleted'>" .
|
1149 |
+
__( 'Delete with Media Cleaner', 'media-cleaner' ) . "</a>";
|
1150 |
if ( !empty( $res ) && isset( $actions['trash'] ) )
|
1151 |
+
$actions['trash'] = "<a href='?page=media-cleaner'>" .
|
1152 |
+
__( 'Trash with Media Cleaner', 'media-cleaner' ) . "</a>";
|
1153 |
if ( !empty( $res ) && isset( $actions['untrash'] ) ) {
|
1154 |
+
$actions['untrash'] = "<a href='?page=media-cleaner&view=deleted'>" .
|
1155 |
+
__( 'Restore with Media Cleaner', 'media-cleaner' ) . "</a>";
|
1156 |
}
|
1157 |
return $actions;
|
1158 |
}
|
1250 |
<?php } ?>
|
1251 |
|
1252 |
<!-- IGNORE SELECTED -->
|
1253 |
+
<a id='wpmc_ignore' onclick='wpmc_ignore()' class='button' style='float: left; margin-left: 5px;'><span style="top: 3px; position: relative; left: -5px;" class="dashicons dashicons-yes"></span><?php
|
1254 |
+
if ( $view == 'ignored' )
|
1255 |
+
_e( "Mark as Issue", 'media-cleaner' );
|
1256 |
+
else
|
1257 |
+
_e( "Ignore", 'media-cleaner' );
|
1258 |
+
?>
|
1259 |
+
</a>
|
1260 |
|
1261 |
<!-- RESET -->
|
1262 |
<?php if ( $view != 'deleted' ) { ?>
|
1299 |
}
|
1300 |
|
1301 |
if ( !MEDIA_TRASH ) {
|
1302 |
+
_e( "<div class='notice notice-warning'><p>The trash for the Media Library is disabled. Any media removed by the plugin will be <b>permanently deleted</b>. To enable it, modify your wp-config.php file and add this line (preferably at the top):<br /><b>define( 'MEDIA_TRASH', true );</b></p></div>", 'media-cleaner' );
|
1303 |
}
|
1304 |
|
1305 |
if ( !$this->admin->is_registered() ) {
|
1308 |
echo "</p></div>";
|
1309 |
}
|
1310 |
|
1311 |
+
$anychecks = get_option( 'wpmc_posts', false ) || get_option( 'wpmc_galleries', false ) ||
|
1312 |
+
get_option( 'wpmc_postmeta', false );
|
1313 |
$check_library = get_option(' wpmc_media_library', false );
|
1314 |
|
1315 |
if ( $method == 'media' ) {
|
1316 |
if ( !$anychecks )
|
1317 |
+
_e( "<div class='error'><p>Media Cleaner will analyze your Media Library. However, There is <b>NOTHING MARKED TO BE CHECKED</b> in the Settings. If you scan now, everything will be detected as NOT in used.</p></div>", 'media-cleaner' );
|
1318 |
else
|
1319 |
_e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Media Library.</p></div>", 'media-cleaner' );
|
1320 |
}
|
1321 |
else if ( $method == 'files' ) {
|
1322 |
if ( !$anychecks && !$check_library )
|
1323 |
+
_e( "<div class='error'><p>Media Cleaner will analyze your Filesystem. However, There is <b>NOTHING MARKED TO BE CHECKED</b> in the Settings. If you scan now, everything will be detected as NOT in used.</p></div>", 'media-cleaner' );
|
1324 |
else
|
1325 |
_e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Filesystem.</p></div>", 'media-cleaner' );
|
1326 |
}
|
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.
|
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.
|
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.0
|
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.0';
|
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.
|
7 |
|
8 |
Clean your Media Library and Uploads directory. It has an internal trash and recovery features. Please read the description.
|
9 |
|
@@ -50,6 +50,13 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
|
|
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.
|
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.0
|
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.4.0 =
|
54 |
+
* Info: This is a MAJOR UPDATE both in term of optimization and detection. Keep my motivation up and give a good review to the plugin here: https://wordpress.org/support/plugin/media-cleaner/reviews/?rate=5#new-post. That helps me a lot.
|
55 |
+
* Update: Meta Data analysis is now cached, so much faster.
|
56 |
+
* Update: URL detections became a bit more safer.
|
57 |
+
* Update: Detect the images used by the themes more than before.
|
58 |
+
* Fix: Images in widgets weren't detected in many cases.
|
59 |
+
|
60 |
= 4.2.5 =
|
61 |
* Update: Support for WP 4.9.
|
62 |
* Fix: Could not empty trash if Media was already removed.
|
wpmc_checkers.php
CHANGED
@@ -12,42 +12,18 @@ class Meow_WPMC_Checkers {
|
|
12 |
}
|
13 |
|
14 |
function has_background_or_header( $file, $mediaId = null ) {
|
15 |
-
if ( current_theme_supports( 'custom-header' ) ) {
|
16 |
-
$custom_header = get_custom_header();
|
17 |
-
if ( $custom_header && $custom_header->url ) {
|
18 |
-
if ( strpos( $custom_header->url, $file ) !== false ) {
|
19 |
-
$this->core->log( "{$file} found in theme (Custom Header)" );
|
20 |
-
return true;
|
21 |
-
}
|
22 |
-
}
|
23 |
-
}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
return true;
|
31 |
-
}
|
32 |
-
}
|
33 |
}
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
$
|
38 |
-
|
39 |
-
if ( $photography_hero_image == $mediaId ) {
|
40 |
-
$this->core->log( "{$file} found in theme (Photography Hero Image)" );
|
41 |
-
return true;
|
42 |
-
}
|
43 |
-
}
|
44 |
-
$author_profile_picture = get_theme_mod( 'author_profile_picture' );
|
45 |
-
if ( !empty( $author_profile_picture ) ) {
|
46 |
-
if ( $author_profile_picture == $mediaId ) {
|
47 |
-
$this->core->log( "{$file} found in theme (Author Profile Photo)" );
|
48 |
-
return true;
|
49 |
-
}
|
50 |
-
}
|
51 |
}
|
52 |
|
53 |
return false;
|
@@ -68,6 +44,7 @@ class Meow_WPMC_Checkers {
|
|
68 |
$galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
|
69 |
if ( is_array( $galleries_images_vc ) && in_array( $mediaId, $galleries_images_vc ) ) {
|
70 |
$this->core->log( "Media {$mediaId} found in a Visual Composer gallery" );
|
|
|
71 |
return true;
|
72 |
}
|
73 |
}
|
@@ -77,6 +54,7 @@ class Meow_WPMC_Checkers {
|
|
77 |
$galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
|
78 |
if ( is_array( $galleries_images_fb ) && in_array( $mediaId, $galleries_images_fb ) ) {
|
79 |
$this->core->log( "Media {$mediaId} found in post_content (Fusion Builder)" );
|
|
|
80 |
return true;
|
81 |
}
|
82 |
}
|
@@ -86,6 +64,7 @@ class Meow_WPMC_Checkers {
|
|
86 |
$galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
|
87 |
if ( is_array( $galleries_images_wc ) && in_array( $mediaId, $galleries_images_wc ) ) {
|
88 |
$this->core->log( "Media {$mediaId} found in a WooCommerce gallery" );
|
|
|
89 |
return true;
|
90 |
}
|
91 |
}
|
@@ -94,6 +73,7 @@ class Meow_WPMC_Checkers {
|
|
94 |
$galleries_images = get_transient( "wpmc_galleries_images" );
|
95 |
if ( is_array( $galleries_images ) && in_array( $file, $galleries_images ) ) {
|
96 |
$this->core->log( "URL {$file} found in a standard WP Gallery" );
|
|
|
97 |
return true;
|
98 |
}
|
99 |
|
@@ -105,41 +85,25 @@ class Meow_WPMC_Checkers {
|
|
105 |
if ( !get_option( 'wpmc_postmeta', true ) )
|
106 |
return false;
|
107 |
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
global $wpdb;
|
112 |
-
$uploads = wp_upload_dir();
|
113 |
-
$parsedURL = parse_url( $uploads['baseurl'] );
|
114 |
$file = $this->core->wpmc_clean_uploaded_filename( $file );
|
115 |
-
$
|
116 |
-
$
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
$
|
122 |
-
|
123 |
-
FROM $wpdb->postmeta
|
124 |
-
WHERE post_id != %d
|
125 |
-
AND meta_key != '_wp_attached_file'
|
126 |
-
AND (meta_value REGEXP %s OR meta_value = %d)",
|
127 |
-
$mediaId, $regex_mysql, $mediaId
|
128 |
-
)
|
129 |
-
);
|
130 |
-
} else {
|
131 |
-
$mediaCount = $wpdb->get_var(
|
132 |
-
$wpdb->prepare( "SELECT COUNT(*)
|
133 |
-
FROM $wpdb->postmeta
|
134 |
-
WHERE meta_key != '_wp_attached_file'
|
135 |
-
AND meta_value REGEXP %s",
|
136 |
-
$regex_mysql
|
137 |
-
)
|
138 |
-
);
|
139 |
}
|
140 |
-
|
141 |
-
|
142 |
-
return $mediaCount > 0;
|
143 |
}
|
144 |
|
145 |
|
@@ -161,6 +125,7 @@ class Meow_WPMC_Checkers {
|
|
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 |
}
|
166 |
|
@@ -169,6 +134,7 @@ class Meow_WPMC_Checkers {
|
|
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 |
}
|
174 |
}
|
@@ -178,15 +144,24 @@ class Meow_WPMC_Checkers {
|
|
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 |
}
|
183 |
}
|
184 |
|
185 |
// Search in widgets
|
186 |
if ( get_option( 'wpmc_widgets', false ) ) {
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
$this->core->last_analysis = "WIDGET";
|
191 |
return true;
|
192 |
}
|
12 |
}
|
13 |
|
14 |
function has_background_or_header( $file, $mediaId = null ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
$theme_ids = get_transient( "wpmc_theme_ids" );
|
17 |
+
if ( is_array( $theme_ids ) && in_array( $mediaId, $theme_ids ) ) {
|
18 |
+
$this->core->log( "Media {$mediaId} found in theme" );
|
19 |
+
$this->core->last_analysis = "THEME";
|
20 |
+
return true;
|
|
|
|
|
|
|
21 |
}
|
22 |
+
$theme_urls = get_transient( "wpmc_theme_urls" );
|
23 |
+
if ( is_array( $theme_urls ) && in_array( $file, $theme_urls ) ) {
|
24 |
+
$this->core->log( "Media {$mediaId} found in theme" );
|
25 |
+
$this->core->last_analysis = "THEME";
|
26 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
|
29 |
return false;
|
44 |
$galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
|
45 |
if ( is_array( $galleries_images_vc ) && in_array( $mediaId, $galleries_images_vc ) ) {
|
46 |
$this->core->log( "Media {$mediaId} found in a Visual Composer gallery" );
|
47 |
+
$this->core->last_analysis = "GALLERY";
|
48 |
return true;
|
49 |
}
|
50 |
}
|
54 |
$galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
|
55 |
if ( is_array( $galleries_images_fb ) && in_array( $mediaId, $galleries_images_fb ) ) {
|
56 |
$this->core->log( "Media {$mediaId} found in post_content (Fusion Builder)" );
|
57 |
+
$this->core->last_analysis = "GALLERY";
|
58 |
return true;
|
59 |
}
|
60 |
}
|
64 |
$galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
|
65 |
if ( is_array( $galleries_images_wc ) && in_array( $mediaId, $galleries_images_wc ) ) {
|
66 |
$this->core->log( "Media {$mediaId} found in a WooCommerce gallery" );
|
67 |
+
$this->core->last_analysis = "GALLERY";
|
68 |
return true;
|
69 |
}
|
70 |
}
|
73 |
$galleries_images = get_transient( "wpmc_galleries_images" );
|
74 |
if ( is_array( $galleries_images ) && in_array( $file, $galleries_images ) ) {
|
75 |
$this->core->log( "URL {$file} found in a standard WP Gallery" );
|
76 |
+
$this->core->last_analysis = "GALLERY";
|
77 |
return true;
|
78 |
}
|
79 |
|
85 |
if ( !get_option( 'wpmc_postmeta', true ) )
|
86 |
return false;
|
87 |
|
88 |
+
$postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
|
89 |
+
if ( is_array( $postmeta_images_ids ) && in_array( $mediaId, $postmeta_images_ids ) ) {
|
90 |
+
$this->core->log( "Media {$mediaId} found in content (Post Meta IDs)" );
|
91 |
+
$this->core->last_analysis = "META (ID)";
|
92 |
+
return true;
|
93 |
+
}
|
94 |
|
|
|
|
|
|
|
95 |
$file = $this->core->wpmc_clean_uploaded_filename( $file );
|
96 |
+
$pinfo = pathinfo( $file );
|
97 |
+
$url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
|
98 |
+
( isset( $pinfo['extension'] ) ? ( '.' . $pinfo['extension'] ) : '' );
|
99 |
+
$postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
|
100 |
+
if ( is_array( $postmeta_images_urls ) && in_array( $url, $postmeta_images_urls ) ) {
|
101 |
+
$this->core->log( "URL {$url} found in content (Post Meta URLs)" );
|
102 |
+
$this->core->last_analysis = "META (URL)";
|
103 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
+
|
106 |
+
return false;
|
|
|
107 |
}
|
108 |
|
109 |
|
125 |
$posts_images_ids = get_transient( "wpmc_posts_images_ids" );
|
126 |
if ( is_array( $posts_images_ids ) && in_array( $mediaId, $posts_images_ids ) ) {
|
127 |
$this->core->log( "Media {$mediaId} found in content (Posts Images IDs)" );
|
128 |
+
$this->core->last_analysis = "CONTENT (ID)";
|
129 |
return true;
|
130 |
}
|
131 |
|
134 |
$posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
|
135 |
if ( is_array( $posts_images_vc ) && in_array( $mediaId, $posts_images_vc ) ) {
|
136 |
$this->core->log( "Media {$mediaId} found in content (Visual Composer)" );
|
137 |
+
$this->core->last_analysis = "VISUAL COMPOSER";
|
138 |
return true;
|
139 |
}
|
140 |
}
|
144 |
$posts_images_urls = get_transient( "wpmc_posts_images_urls" );
|
145 |
if ( is_array( $posts_images_urls ) && in_array( $url, $posts_images_urls ) ) {
|
146 |
$this->core->log( "URL {$url} found in content (Posts Images URLs)" );
|
147 |
+
$this->core->last_analysis = "CONTENT (URL)";
|
148 |
return true;
|
149 |
}
|
150 |
}
|
151 |
|
152 |
// Search in widgets
|
153 |
if ( get_option( 'wpmc_widgets', false ) ) {
|
154 |
+
if ( !empty( $mediaId ) ) {
|
155 |
+
$widgets_ids = get_transient( "wpmc_widgets_ids" );
|
156 |
+
if ( is_array( $widgets_ids ) && in_array( $mediaId, $widgets_ids ) ) {
|
157 |
+
$this->core->log( "Media {$mediaId} found in widgets (Widgets IDs)" );
|
158 |
+
$this->core->last_analysis = "WIDGET";
|
159 |
+
return true;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
$widgets_urls = get_transient( "wpmc_widgets_urls" );
|
163 |
+
if ( is_array( $widgets_urls ) && in_array( $url, $widgets_urls ) ) {
|
164 |
+
$this->core->log( "URL {$url} found in widgets (Widgets URLs)" );
|
165 |
$this->core->last_analysis = "WIDGET";
|
166 |
return true;
|
167 |
}
|