Media Cleaner - Version 4.5.4

Version Description

  • Update: Streamlined the plugin, tutorial has also been rewritten.
  • Update: Simplified the Settings. Removed the Gallery option, as it is part of the Posts or Post Meta.
  • Update: Support for UTF8, Background CSS, and Shortcodes have been moved to the Free version, and are now always enabled. Easier for everyone.
  • Add: Extra support for Page Builders is being added into the Pro version.
Download this release

Release Info

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

Code changes from version 4.5.0 to 4.5.4

Files changed (6) hide show
  1. core.php +202 -328
  2. media-cleaner.php +2 -2
  3. readme.txt +13 -9
  4. wpmc_admin.php +51 -60
  5. wpmc_checkers.php +3 -11
  6. wpmc_scan.php +169 -0
core.php CHANGED
@@ -6,13 +6,11 @@ class Meow_WPMC_Core {
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' ) );
@@ -26,21 +24,16 @@ class Meow_WPMC_Core {
26
  add_action( 'wp_ajax_wpmc_ignore_do', array( $this, 'wp_ajax_wpmc_ignore_do' ) );
27
  add_action( 'wp_ajax_wpmc_recover_do', array( $this, 'wp_ajax_wpmc_recover_do' ) );
28
  add_filter( 'media_row_actions', array( $this, 'media_row_actions' ), 10, 2 );
29
-
30
- if ( is_admin() ) {
31
- add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
32
- }
33
-
34
- // Checkers
35
- require( 'wpmc_checkers.php' );
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|wav|lua";
43
  $this->regex_file = str_replace( "MIMETYPES", $types, $this->regex_file );
 
 
 
 
44
  }
45
 
46
  /*******************************************************************************
@@ -73,8 +66,8 @@ class Meow_WPMC_Core {
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.";
@@ -254,7 +247,6 @@ class Meow_WPMC_Core {
254
  global $wp_registered_widgets;
255
  $syswidgets = $wp_registered_widgets;
256
  $active_widgets = get_option( 'sidebars_widgets' );
257
- $shortcode_support = get_option( 'wpmc_shortcode', false );
258
  foreach ( $active_widgets as $sidebar_name => $widgets ) {
259
  if ( $sidebar_name != 'wp_inactive_widgets' && !empty( $widgets ) && is_array( $widgets ) ) {
260
  $i = 0;
@@ -265,7 +257,7 @@ class Meow_WPMC_Core {
265
  // error_log( "INSTANCE $key ($instance_id)" );
266
  // error_log( print_r( $widget_data, 1 ) );
267
  if ( !empty( $widget_data[$instance_id]['text'] ) ) {
268
- $html = $shortcode_support ? do_shortcode( $widget_data[$instance_id]['text'] ) : $widget_data[$instance_id]['text'];
269
  $urls = array_merge( $urls, $this->get_urls_from_html( $html ) );
270
  }
271
  if ( !empty( $widget_data[$instance_id]['attachment_id'] ) ) {
@@ -290,15 +282,26 @@ class Meow_WPMC_Core {
290
  if ( empty( $html ) )
291
  return array();
292
  libxml_use_internal_errors( false );
 
293
  $dom = new DOMDocument();
294
  @$dom->loadHTML( $html );
295
 
296
- // Images, src
297
  $imgs = $dom->getElementsByTagName( 'img' );
298
  $results = array();
299
  foreach ( $imgs as $img ) {
300
  $src = $this->wpmc_clean_url( $img->getAttribute('src') );
301
  array_push( $results, $src );
 
 
 
 
 
 
 
 
 
 
302
  }
303
 
304
  // Links, href
@@ -308,55 +311,38 @@ class Meow_WPMC_Core {
308
  array_push( $results, $src );
309
  }
310
 
311
- // Single Image in Divi (Elegant Themes)
312
- if ( function_exists( '_et_core_find_latest' ) ) {
313
- preg_match_all( "/src=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
314
- if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
315
- foreach ( $res[1] as $url ) {
316
- if ( !preg_match('/(elegantthemesimages\.com)|(elegantthemes\.com)/', $url ) )
317
- array_push( $results, $this->wpmc_clean_url( $url ) );
318
- }
319
- }
320
- }
321
-
322
- // Background Image in Divi (Elegant Themes)
323
- if ( function_exists( '_et_core_find_latest' ) ) {
324
- preg_match_all( "/background_image=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
325
- if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
326
- foreach ( $res[1] as $url ) {
327
- if ( !preg_match('/(elegantthemesimages\.com)|(elegantthemes\.com)/', $url ) )
328
- array_push( $results, $this->wpmc_clean_url( $url ) );
329
- }
330
- }
331
- }
332
-
333
- if ( get_option( 'wpmc_background', false ) ) {
334
- preg_match_all( "/url\(\'?\"?((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\'?\"?\)/", $html, $res );
335
  //error_log( print_r( $res, 1 ) );
336
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
337
  foreach ( $res[1] as $url ) {
338
  array_push( $results, $this->wpmc_clean_url( $url ) );
339
  }
340
  }
341
- }
342
 
343
  return $results;
344
  }
345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  function get_images_from_themes( &$ids, &$urls ) {
347
  global $wpdb;
348
 
349
- // PARSE OPTIONS
350
- // $metas = $wpdb->get_col( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE 'theme_mods_%'" );
351
- // foreach ( $metas as $meta ) {
352
- // $decoded = @unserialize( $meta );
353
- // if ( is_array( $decoded ) ) {
354
- // error_log( print_r( $decoded, 1 ) );
355
- // $this->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
356
- // continue;
357
- // }
358
- // }
359
-
360
  // USE CURRENT THEME AND WP API
361
  $ch = get_custom_header();
362
  if ( !empty( $ch ) && !empty( $ch->url ) ) {
@@ -388,15 +374,27 @@ class Meow_WPMC_Core {
388
  $limitsize = get_option( 'wpmc_posts_buffer', 5 );
389
  if ( empty( $limit ) )
390
  $this->wpmc_reset_issues();
 
 
 
391
  $check_postmeta = get_option( 'wpmc_postmeta', false );
392
  $check_posts = get_option( 'wpmc_posts', false );
393
- $check_galleries = get_option( 'wpmc_galleries', false );
394
- if ( !$check_galleries && !$check_posts && !$check_postmeta ) {
395
  echo json_encode( array(
396
  'results' => array(),
397
  'success' => true,
398
  'finished' => true,
399
- 'message' => __( "Galleries and Posts analysis is off. Done.", 'media-cleaner' )
 
 
 
 
 
 
 
 
 
400
  ) );
401
  die();
402
  }
@@ -420,14 +418,13 @@ class Meow_WPMC_Core {
420
  );
421
 
422
  $found = array();
423
- $shortcode_support = get_option( 'wpmc_shortcode', false );
424
 
425
  if ( empty( $limit ) ) {
426
  $theme_ids = array();
427
  $theme_urls = array();
428
  $this->get_images_from_themes( $theme_ids, $theme_urls );
429
- set_transient( "wpmc_theme_ids", $theme_ids, $this->transient_life );
430
- set_transient( "wpmc_theme_urls", $theme_urls, $this->transient_life );
431
  $found['wpmc_theme_ids'] = $theme_ids;
432
  $found['wpmc_theme_urls'] = $theme_urls;
433
  }
@@ -437,8 +434,8 @@ class Meow_WPMC_Core {
437
  $widgets_ids = array();
438
  $widgets_urls = array();
439
  $this->get_images_from_widgets( $widgets_ids, $widgets_urls );
440
- set_transient( "wpmc_widgets_ids", $widgets_ids, $this->transient_life );
441
- set_transient( "wpmc_widgets_urls", $widgets_urls, $this->transient_life );
442
  $found['wpmc_widgets_ids'] = $widgets_ids;
443
  $found['wpmc_widgets_urls'] = $widgets_urls;
444
  }
@@ -449,7 +446,6 @@ class Meow_WPMC_Core {
449
  FROM $wpdb->termmeta
450
  WHERE meta_key LIKE '%thumbnail_id%'"
451
  );
452
- print_r( $metas, 1 );
453
  if ( count( $metas ) > 0 ) {
454
  $postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
455
  if ( empty( $postmeta_images_ids ) )
@@ -457,234 +453,24 @@ class Meow_WPMC_Core {
457
  foreach ( $metas as $meta )
458
  if ( is_numeric( $meta ) && $meta > 0 )
459
  array_push( $postmeta_images_ids, $meta );
460
- set_transient( "wpmc_postmeta_images_ids", $postmeta_images_ids, $this->transient_life );
461
  $found['wpmc_postmeta_images_ids'] = $postmeta_images_ids;
462
  }
463
  }
464
 
465
- // Prepare likes for SQL
466
- $like = "";
467
- foreach ( $this->metakeys as $metakey )
468
- $like .= "OR meta_key LIKE '$metakey' ";
469
-
470
  // Analyze Posts
471
  foreach ( $posts as $post ) {
472
 
 
473
  $html = get_post_field( 'post_content', $post );
474
-
475
- if ( $check_postmeta ) {
476
-
477
- // Detect values in the general (known, based on %like%) Meta Keys
478
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta
479
- WHERE post_id = %d
480
- AND meta_key = '_thumbnail_id' $like", $post )
481
- );
482
- if ( count( $metas ) > 0 ) {
483
- $postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
484
- if ( empty( $postmeta_images_ids ) )
485
- $postmeta_images_ids = array();
486
- $postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
487
- if ( empty( $postmeta_images_urls ) )
488
- $postmeta_images_urls = array();
489
-
490
- foreach ( $metas as $meta ) {
491
- // Just a number, let's assume it's a Media ID
492
- if ( is_numeric( $meta ) ) {
493
- //error_log( "META NUMERIC: " . $meta );
494
- if ( $meta > 0 )
495
- array_push( $postmeta_images_ids, $meta );
496
- continue;
497
- }
498
- $decoded = @unserialize( $meta );
499
- if ( is_array( $decoded ) ) {
500
- // error_log( "META DECODED" );
501
- // error_log( print_r( $decoded, 1 ) );
502
- $this->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
503
- continue;
504
- }
505
- $exploded = explode( ',', $meta );
506
- if ( is_array( $exploded ) ) {
507
- // error_log( "META EXPLODED" );
508
- // error_log( print_r( $exploded, 1 ) );
509
- $this->array_to_ids_or_urls( $exploded, $postmeta_images_ids, $postmeta_images_urls );
510
- continue;
511
- }
512
- }
513
- set_transient( "wpmc_postmeta_images_ids", $postmeta_images_ids, $this->transient_life );
514
- $found['wpmc_postmeta_images_ids'] = $postmeta_images_ids;
515
- set_transient( "wpmc_postmeta_images_urls", $postmeta_images_urls, $this->transient_life );
516
- $found['wpmc_postmeta_images_urls'] = $postmeta_images_urls;
517
- }
518
-
519
- // Advanced Custom Fields
520
- if ( class_exists( 'acf' ) ) {
521
- $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
522
- if ( empty( $postmeta_images_acf_ids ) )
523
- $postmeta_images_acf_ids = array();
524
- $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
525
- if ( empty( $postmeta_images_acf_urls ) )
526
- $postmeta_images_acf_urls = array();
527
- $fields = get_field_objects( $post );
528
- if ( is_array( $fields ) ) {
529
- foreach ( $fields as $field ) {
530
-
531
- $format = "";
532
- if ( isset( $field['return_format'] ) )
533
- $format = $field['return_format'];
534
- else if ( isset( $field['save_format'] ) )
535
- $format = $field['save_format'];
536
-
537
- if ( $field['type'] == 'image' && ( $format == 'array' || $format == 'object' ) ) {
538
- array_push( $postmeta_images_acf_ids, $field['value']['id'] );
539
- array_push( $postmeta_images_acf_urls, $this->wpmc_clean_url( $field['value']['url'] ) );
540
- }
541
- else if ( $field['type'] == 'image' && $format == 'id' ) {
542
- array_push( $postmeta_images_acf_ids, $field['value'] );
543
- }
544
- else if ( $field['type'] == 'image' && $format == 'url' ) {
545
- array_push( $postmeta_images_acf_urls, $this->wpmc_clean_url( $field['value'] ) );
546
- }
547
- else if ( $field['type'] == 'gallery' && !empty( $field['value'] ) ) {
548
- foreach ( $field['value'] as $media ) {
549
- array_push( $postmeta_images_acf_ids, $media['id'] );
550
- }
551
- }
552
- }
553
- set_transient( "wpmc_postmeta_images_acf_ids", $postmeta_images_acf_ids, $this->transient_life );
554
- $found['wpmc_postmeta_images_acf_ids'] = $postmeta_images_acf_ids;
555
- set_transient( "wpmc_postmeta_images_acf_urls", $postmeta_images_acf_urls, $this->transient_life );
556
- $found['wpmc_postmeta_images_acf_urls'] = $postmeta_images_acf_urls;
557
- }
558
- }
559
- }
560
-
561
- if ( $check_posts ) {
562
-
563
- // Single Image in Visual Composer (WPBakery)
564
- if ( class_exists( 'Vc_Manager' ) ) {
565
- $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
566
- if ( empty( $posts_images_vc ) )
567
- $posts_images_vc = array();
568
- preg_match_all( "/image=\"([0-9]+)\"/", $html, $res );
569
- if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
570
- foreach ( $res[1] as $url ) {
571
- array_push( $posts_images_vc, $this->wpmc_clean_url( $url ) );
572
- }
573
- }
574
- set_transient( "wpmc_posts_images_visualcomposer", $posts_images_vc, $this->transient_life );
575
- $found['wpmc_posts_images_visualcomposer'] = $posts_images_vc;
576
- }
577
-
578
- // Let's resolve the shortcodes if the option is on
579
- if ( $shortcode_support )
580
- $html = do_shortcode( $html );
581
-
582
- // Check for images urls in posts (and in the excerpt if WooCommerce is used, as
583
- // WooCommerce stores the Product Short Description in there.
584
- $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
585
- if ( empty( $posts_images_urls ) )
586
- $posts_images_urls = array();
587
- $new_urls = $this->get_urls_from_html( $html );
588
- $posts_images_urls = array_merge( $posts_images_urls, $new_urls );
589
- if ( class_exists( 'WooCommerce' ) ) {
590
- $excerpt = get_post_field( 'post_excerpt', $post );
591
- $new_urls = $this->get_urls_from_html( $excerpt );
592
- $posts_images_urls = array_merge( $posts_images_urls, $new_urls );
593
- set_transient( "wpmc_posts_images_urls", $posts_images_urls, $this->transient_life );
594
- $found['wpmc_posts_images_urls'] = $posts_images_urls;
595
- }
596
- set_transient( "wpmc_posts_images_urls", $posts_images_urls, $this->transient_life );
597
- $found['wpmc_posts_images_urls'] = $posts_images_urls;
598
-
599
- // Check for images IDs through classes in in posts
600
- $posts_images_ids = get_transient( "wpmc_posts_images_ids" );
601
- if ( empty( $posts_images_ids ) )
602
- $posts_images_ids = array();
603
- preg_match_all( "/wp-image-([0-9]+)/", $html, $res );
604
- if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
605
- $posts_images_ids = array_merge( $posts_images_ids, $res[1] );
606
- set_transient( "wpmc_posts_images_ids", $posts_images_ids, $this->transient_life );
607
- $found['wpmc_posts_images_ids'] = $posts_images_ids;
608
- }
609
-
610
- if ( $check_galleries ) {
611
-
612
- // Galleries in Divi (Elegant Themes)
613
- if ( function_exists( '_et_core_find_latest' ) ) {
614
- $galleries_images_et = get_transient( "wpmc_galleries_images_divi" );
615
- if ( empty( $galleries_images_et ) )
616
- $galleries_images_et = array();
617
- preg_match_all( "/gallery_ids=\"([0-9,]+)/", $html, $res );
618
- if ( !empty( $res ) && isset( $res[1] ) ) {
619
- foreach ( $res[1] as $r ) {
620
- $ids = explode( ',', $r );
621
- $galleries_images_et = array_merge( $galleries_images_et, $ids );
622
- }
623
- }
624
- set_transient( "wpmc_galleries_images_divi", $galleries_images_et, $this->transient_life );
625
- $found['wpmc_galleries_images_divi'] = $galleries_images_et;
626
- }
627
-
628
- // Galleries in Visual Composer (WPBakery)
629
- if ( class_exists( 'Vc_Manager' ) ) {
630
- $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
631
- if ( empty( $galleries_images_vc ) )
632
- $galleries_images_vc = array();
633
- preg_match_all( "/images=\"([0-9,]+)/", $html, $res );
634
- if ( !empty( $res ) && isset( $res[1] ) ) {
635
- foreach ( $res[1] as $r ) {
636
- $ids = explode( ',', $r );
637
- $galleries_images_vc = array_merge( $galleries_images_vc, $ids );
638
- }
639
- }
640
- set_transient( "wpmc_galleries_images_visualcomposer", $galleries_images_vc, $this->transient_life );
641
- $found['wpmc_galleries_images_visualcomposer'] = $galleries_images_vc;
642
- }
643
-
644
- // Galleries in Fusion Builder (Avada Theme)
645
- if ( function_exists( 'fusion_builder_map' ) ) {
646
- $galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
647
- if ( empty( $galleries_images_fb ) )
648
- $galleries_images_fb = array();
649
- preg_match_all( "/image_ids=\"([0-9,]+)/", $html, $res );
650
- if ( !empty( $res ) && isset( $res[1] ) ) {
651
- foreach ( $res[1] as $r ) {
652
- $ids = explode( ',', $r );
653
- $galleries_images_fb = array_merge( $galleries_images_fb, $ids );
654
- }
655
- }
656
- set_transient( "wpmc_galleries_images_fusionbuilder", $galleries_images_fb, $this->transient_life );
657
- $found['wpmc_galleries_images_fusionbuilder'] = $galleries_images_fb;
658
- }
659
-
660
- // WooCommerce
661
- if ( class_exists( 'WooCommerce' ) ) {
662
- $galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
663
- if ( empty( $galleries_images_wc ) )
664
- $galleries_images_wc = array();
665
- $res = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $post
666
- AND meta_key = '_product_image_gallery'" );
667
- foreach ( $res as $values ) {
668
- $ids = explode( ',', $values );
669
- $galleries_images_wc = array_merge( $galleries_images_wc, $ids );
670
- }
671
- set_transient( "wpmc_galleries_images_woocommerce", $galleries_images_wc, $this->transient_life );
672
- $found['wpmc_galleries_images_woocommerce'] = $galleries_images_wc;
673
- }
674
-
675
- // Standard WP Gallery
676
- $galleries_images = get_transient( "wpmc_galleries_images" );
677
- if ( empty( $galleries_images ) )
678
- $galleries_images = array();
679
- $galleries = get_post_galleries_images( $post );
680
- foreach ( $galleries as $gallery ) {
681
- foreach ( $gallery as $image ) {
682
- array_push( $galleries_images, $this->wpmc_clean_url( $image ) );
683
- }
684
- }
685
- set_transient( "wpmc_galleries_images", $galleries_images, $this->transient_life );
686
- $found['wpmc_galleries_images'] = $galleries_images;
687
- }
688
  }
689
  $finished = count( $posts ) < $limitsize;
690
  if ( $finished ) {
@@ -701,24 +487,25 @@ class Meow_WPMC_Core {
701
  $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
702
  $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
703
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
704
- $galleries_images = get_transient( "wpmc_galleries_images" );
705
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
706
  $galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
707
  $galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
708
  $galleries_images_et = get_transient( "wpmc_galleries_images_divi" );
709
 
710
  $found['theme_urls'] = is_array( $theme_urls ) ? array_unique( $theme_urls ) : array();
711
- $found['theme_ids'] = is_array( $theme_ids ) ? array_unique( $theme_ids ) : array();
712
  $found['widgets_urls'] = is_array( $widgets_urls ) ? array_unique( $widgets_urls ) : array();
713
- $found['widgets_ids'] = is_array( $widgets_ids ) ? array_unique( $widgets_ids ) : array();
714
  $found['posts_images_urls'] = is_array( $posts_images_urls ) ? array_unique( $posts_images_urls ) : array();
715
- $found['posts_images_ids'] = is_array( $posts_images_ids ) ? array_unique( $posts_images_ids ) : array();
716
  $found['postmeta_images_urls'] = is_array( $postmeta_images_urls ) ? array_unique( $postmeta_images_urls ) : array();
717
- $found['postmeta_images_ids'] = is_array( $postmeta_images_ids ) ? array_unique( $postmeta_images_ids ) : array();
718
  $found['postmeta_images_acf_urls'] = is_array( $postmeta_images_acf_urls ) ? array_unique( $postmeta_images_acf_urls ) : array();
 
 
 
 
 
 
719
  $found['postmeta_images_acf_ids'] = is_array( $postmeta_images_acf_ids ) ? array_unique( $postmeta_images_acf_ids ) : array();
720
  $found['posts_images_vc'] = is_array( $posts_images_vc ) ? array_unique( $posts_images_vc ) : array();
721
- $found['galleries_images'] = is_array( $galleries_images ) ? array_unique( $galleries_images ) : array();
722
  $found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
723
  $found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
724
  $found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
@@ -727,28 +514,57 @@ class Meow_WPMC_Core {
727
  // For safety, remove the resolutions...
728
  // That will match more files, especially the sizes created before, used before, but not part of the
729
  // media metadata anymore.
730
- array_walk( $found['theme_urls'], array( $this, 'clean_url_from_resolution' ) );
731
- array_walk( $found['widgets_urls'], array( $this, 'clean_url_from_resolution' ) );
732
- array_walk( $found['posts_images_urls'], array( $this, 'clean_url_from_resolution' ) );
733
- array_walk( $found['postmeta_images_urls'], array( $this, 'clean_url_from_resolution' ) );
734
- array_walk( $found['postmeta_images_acf_urls'], array( $this, 'clean_url_from_resolution' ) );
735
-
736
- set_transient( "wpmc_theme_urls", $found['theme_urls'], $this->transient_life );
737
- set_transient( "wpmc_theme_ids", $found['theme_ids'], $this->transient_life );
738
- set_transient( "wpmc_widgets_urls", $found['widgets_urls'], $this->transient_life );
739
- set_transient( "wpmc_widgets_ids", $found['widgets_ids'], $this->transient_life );
740
- set_transient( "wpmc_posts_images_urls", $found['posts_images_urls'], $this->transient_life );
741
- set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], $this->transient_life );
742
- set_transient( "wpmc_postmeta_images_urls", $found['postmeta_images_urls'], $this->transient_life );
743
- set_transient( "wpmc_postmeta_images_ids", $found['postmeta_images_ids'], $this->transient_life );
744
- set_transient( "wpmc_postmeta_images_acf_urls", $found['postmeta_images_acf_urls'], $this->transient_life );
745
- set_transient( "wpmc_postmeta_images_acf_ids", $found['postmeta_images_acf_ids'], $this->transient_life );
746
- set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], $this->transient_life );
747
- set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], $this->transient_life );
748
- set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], $this->transient_life );
749
- set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], $this->transient_life );
750
- set_transient( "wpmc_galleries_images_divi", $found['galleries_images_et'], $this->transient_life );
751
- set_transient( "wpmc_galleries_images", $found['galleries_images'], $this->transient_life );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752
  }
753
  if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
754
  $this->log( print_r( $found, true ) );
@@ -781,7 +597,7 @@ class Meow_WPMC_Core {
781
  $method = 'media';
782
  $path = isset( $_POST['path'] ) ? $_POST['path'] : null;
783
  $limit = isset( $_POST['limit'] ) ? $_POST['limit'] : 0;
784
- $limitsize = get_option( 'wpmc_medias_buffer', 50 );
785
 
786
  if ( $method == 'files' ) {
787
  $output = apply_filters( 'wpmc_list_uploaded_files', array(
@@ -984,7 +800,7 @@ class Meow_WPMC_Core {
984
  $table_name = $wpdb->prefix . "wpmcleaner";
985
  $issue = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d", $id ), OBJECT );
986
  $regex = "^(.*)(\\s\\(\\+.*)$";
987
- $issue->path = preg_replace('/'.$regex.'/i', '$1', $issue->path); // remove " (+ 6 files)" from path
988
 
989
  // Make sure there isn't a media DB entry
990
  if ( $issue->type == 0 ) {
@@ -1083,7 +899,7 @@ class Meow_WPMC_Core {
1083
  return ($count > 0);
1084
  }
1085
 
1086
- function wpmc_find_attachment_id_by_file ($file) {
1087
  global $wpdb;
1088
  $postmeta_table_name = $wpdb->prefix . 'postmeta';
1089
  $file = $this->wpmc_clean_uploaded_filename( $file );
@@ -1120,12 +936,16 @@ class Meow_WPMC_Core {
1120
  return $sizes;
1121
  }
1122
 
1123
- function clean_url_from_resolution( &$url ) {
1124
  $pattern = '/[_-]\d+x\d+(?=\.[a-z]{3,4}$)/';
1125
  $url = preg_replace( $pattern, '', $url );
1126
  return $url;
1127
  }
1128
 
 
 
 
 
1129
  // From a url to the shortened and cleaned url (for example '2013/02/file.png')
1130
  function wpmc_clean_url( $url ) {
1131
  $upload_folder = wp_upload_dir();
@@ -1167,6 +987,14 @@ class Meow_WPMC_Core {
1167
  $countfiles = 0;
1168
  $issue = 'NO_CONTENT';
1169
  if ( file_exists( $fullpath ) ) {
 
 
 
 
 
 
 
 
1170
  $size = filesize( $fullpath );
1171
 
1172
  // ANALYSIS
@@ -1262,7 +1090,7 @@ class Meow_WPMC_Core {
1262
  delete_transient( "wpmc_galleries_images_fusionbuilder" );
1263
  delete_transient( "wpmc_galleries_images_woocommerce" );
1264
  delete_transient( "wpmc_galleries_images_divi" );
1265
- delete_transient( "wpmc_galleries_images" );
1266
  }
1267
 
1268
  /**
@@ -1275,7 +1103,7 @@ class Meow_WPMC_Core {
1275
  echo "<script type='text/javascript'>\n";
1276
  echo 'var wpmc_cfg = {
1277
  delay: ' . get_option( 'wpmc_delay', 100 ) . ',
1278
- analysisBuffer: ' . get_option( 'wpmc_analysis_buffer', 10 ) . ',
1279
  isPro: ' . ( $this->admin->is_registered() ? '1' : '0') . ',
1280
  scanFiles: ' . ( ( get_option( 'wpmc_method', 'media' ) == 'files' && $this->admin->is_registered() ) ? '1' : '0' ) . ',
1281
  scanMedia: ' . ( get_option( 'wpmc_method', 'media' ) == 'media' ? '1' : '0' ) . ' };';
@@ -1467,23 +1295,59 @@ class Meow_WPMC_Core {
1467
 
1468
  if ( !$this->admin->is_registered() ) {
1469
  echo "<div class='notice notice-info'><p>";
1470
- _e( "<b>This version is not Pro.</b> This plugin is a lot of work so please consider in getting the Pro version in order to receive support and to help the plugin to evolve. Also, the Pro version will also give you the option <b>to scan the <u>physical files</u> in your /uploads folder</b>. You can <a target='_blank' href='http://meowapps.com/media-cleaner'>get a serial for the Pro version here</a></b>.", 'media-cleaner' );
1471
  echo "</p></div>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1472
  }
1473
 
1474
- $anychecks = get_option( 'wpmc_posts', false ) || get_option( 'wpmc_galleries', false ) ||
1475
- get_option( 'wpmc_postmeta', false );
1476
- $check_library = get_option(' wpmc_media_library', false );
1477
 
1478
  if ( $method == 'media' ) {
1479
  if ( !$anychecks )
1480
- _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' );
1481
  else
1482
  _e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Media Library.</p></div>", 'media-cleaner' );
1483
  }
1484
  else if ( $method == 'files' ) {
1485
  if ( !$anychecks && !$check_library )
1486
- _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' );
1487
  else
1488
  _e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Filesystem.</p></div>", 'media-cleaner' );
1489
  }
@@ -1552,11 +1416,21 @@ class Meow_WPMC_Core {
1552
  }
1553
  else {
1554
  // MEDIA
1555
- $attachmentsrc = wp_get_attachment_image_src( $issue->postId, 'thumbnail' );
1556
- $attachmentsrc_clean = htmlspecialchars( $attachmentsrc[0], ENT_QUOTES );
1557
- echo "<a target='_blank' href='" . $attachmentsrc_clean .
1558
- "'><img style='max-width: 48px; max-height: 48px;' src='" .
1559
- $attachmentsrc_clean . "' />";
 
 
 
 
 
 
 
 
 
 
1560
  }
1561
  }
1562
  if ( $issue->deleted == 1 ) {
6
  public $admin = null;
7
  public $last_analysis = null;
8
  public $last_analysis_ids = null;
9
+ public static $transient_life = 604800; // 7 days
10
  private $regex_file = '/[A-Za-z0-9-_,\s]+[.]{1}(MIMETYPES)/';
 
11
 
12
  public function __construct( $admin ) {
13
  $this->admin = $admin;
 
14
  add_action( 'admin_init', array( $this, 'admin_init' ) );
15
  add_action( 'admin_menu', array( $this, 'admin_menu' ) );
16
  add_action( 'admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
24
  add_action( 'wp_ajax_wpmc_ignore_do', array( $this, 'wp_ajax_wpmc_ignore_do' ) );
25
  add_action( 'wp_ajax_wpmc_recover_do', array( $this, 'wp_ajax_wpmc_recover_do' ) );
26
  add_filter( 'media_row_actions', array( $this, 'media_row_actions' ), 10, 2 );
27
+ add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
 
 
 
 
 
 
 
28
  }
29
 
30
  function admin_init() {
 
 
31
  $types = "jpg|jpeg|jpe|gif|png|tiff|bmp|csv|pdf|xls|xlsx|doc|docx|tiff|mp3|mp4|wav|lua";
32
  $this->regex_file = str_replace( "MIMETYPES", $types, $this->regex_file );
33
+ require( 'wpmc_scan.php' );
34
+ require( 'wpmc_checkers.php' );
35
+ new MeowApps_WPMC_Scan( $this );
36
+ $this->checkers = new Meow_WPMC_Checkers( $this );
37
  }
38
 
39
  /*******************************************************************************
66
  else if ( $this->last_analysis == "THEME" ) {
67
  echo "Found in theme.";
68
  }
69
+ else if ( $this->last_analysis == "PAGE BUILDER" ) {
70
+ echo "Found in Page Builder.";
71
  }
72
  else if ( $this->last_analysis == "GALLERY" ) {
73
  echo "Found in gallery.";
247
  global $wp_registered_widgets;
248
  $syswidgets = $wp_registered_widgets;
249
  $active_widgets = get_option( 'sidebars_widgets' );
 
250
  foreach ( $active_widgets as $sidebar_name => $widgets ) {
251
  if ( $sidebar_name != 'wp_inactive_widgets' && !empty( $widgets ) && is_array( $widgets ) ) {
252
  $i = 0;
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 = do_shortcode( $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'] ) ) {
282
  if ( empty( $html ) )
283
  return array();
284
  libxml_use_internal_errors( false );
285
+
286
  $dom = new DOMDocument();
287
  @$dom->loadHTML( $html );
288
 
289
+ // Images, src, srcset
290
  $imgs = $dom->getElementsByTagName( 'img' );
291
  $results = array();
292
  foreach ( $imgs as $img ) {
293
  $src = $this->wpmc_clean_url( $img->getAttribute('src') );
294
  array_push( $results, $src );
295
+ $srcset = $img->getAttribute('srcset');
296
+ if ( !empty( $srcset ) ) {
297
+ $setImgs = explode( ',', trim( $srcset ) );
298
+ foreach ( $setImgs as $setImg ) {
299
+ $finalSetImg = explode( ' ', trim( $setImg ) );
300
+ if ( is_array( $finalSetImg ) ) {
301
+ array_push( $results, $this->wpmc_clean_url( $finalSetImg[0] ) );
302
+ }
303
+ }
304
+ }
305
  }
306
 
307
  // Links, href
311
  array_push( $results, $src );
312
  }
313
 
314
+ // if ( get_option( 'wpmc_background', false ) ) {
315
+ preg_match_all( "/url\(\'?\"?((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png))\'?\"?/", $html, $res );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  //error_log( print_r( $res, 1 ) );
317
  if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 ) {
318
  foreach ( $res[1] as $url ) {
319
  array_push( $results, $this->wpmc_clean_url( $url ) );
320
  }
321
  }
322
+ // }
323
 
324
  return $results;
325
  }
326
 
327
+ // Parse a meta, visit all the arrays, look for the attributes, fill $ids and $urls arrays
328
+ function get_from_meta( $meta, $lookFor, &$ids, &$urls ) {
329
+ foreach ( $meta as $key => $value ) {
330
+ if ( is_object( $value ) || is_array( $value ) )
331
+ $this->get_from_meta( $value, $lookFor, $ids, $urls );
332
+ else if ( in_array( $key, $lookFor ) ) {
333
+ if ( empty( $value ) )
334
+ continue;
335
+ else if ( is_numeric( $value ) )
336
+ array_push( $ids, $value );
337
+ else
338
+ array_push( $urls, $this->wpmc_clean_url( $value ) );
339
+ }
340
+ }
341
+ }
342
+
343
  function get_images_from_themes( &$ids, &$urls ) {
344
  global $wpdb;
345
 
 
 
 
 
 
 
 
 
 
 
 
346
  // USE CURRENT THEME AND WP API
347
  $ch = get_custom_header();
348
  if ( !empty( $ch ) && !empty( $ch->url ) ) {
374
  $limitsize = get_option( 'wpmc_posts_buffer', 5 );
375
  if ( empty( $limit ) )
376
  $this->wpmc_reset_issues();
377
+
378
+ $method = get_option( 'wpmc_method', 'media' );
379
+ $check_library = get_option(' wpmc_media_library', true );
380
  $check_postmeta = get_option( 'wpmc_postmeta', false );
381
  $check_posts = get_option( 'wpmc_posts', false );
382
+ $check_widgets = get_option( 'wpmc_widgets', false );
383
+ if ( $method == 'media' && !$check_posts && !$check_postmeta && !$check_widgets ) {
384
  echo json_encode( array(
385
  'results' => array(),
386
  'success' => true,
387
  'finished' => true,
388
+ 'message' => __( "Posts, Meta and Widgets analysis are all off. Done.", 'media-cleaner' )
389
+ ) );
390
+ die();
391
+ }
392
+ if ( $method == 'files' && $check_library && !$check_posts && !$check_postmeta && !$check_widgets ) {
393
+ echo json_encode( array(
394
+ 'results' => array(),
395
+ 'success' => true,
396
+ 'finished' => true,
397
+ 'message' => __( "Posts, Meta and Widgets analysis are all off. Done.", 'media-cleaner' )
398
  ) );
399
  die();
400
  }
418
  );
419
 
420
  $found = array();
 
421
 
422
  if ( empty( $limit ) ) {
423
  $theme_ids = array();
424
  $theme_urls = array();
425
  $this->get_images_from_themes( $theme_ids, $theme_urls );
426
+ set_transient( "wpmc_theme_ids", $theme_ids, Meow_WPMC_Core::$transient_life );
427
+ set_transient( "wpmc_theme_urls", $theme_urls, Meow_WPMC_Core::$transient_life );
428
  $found['wpmc_theme_ids'] = $theme_ids;
429
  $found['wpmc_theme_urls'] = $theme_urls;
430
  }
434
  $widgets_ids = array();
435
  $widgets_urls = array();
436
  $this->get_images_from_widgets( $widgets_ids, $widgets_urls );
437
+ set_transient( "wpmc_widgets_ids", $widgets_ids, Meow_WPMC_Core::$transient_life );
438
+ set_transient( "wpmc_widgets_urls", $widgets_urls, Meow_WPMC_Core::$transient_life );
439
  $found['wpmc_widgets_ids'] = $widgets_ids;
440
  $found['wpmc_widgets_urls'] = $widgets_urls;
441
  }
446
  FROM $wpdb->termmeta
447
  WHERE meta_key LIKE '%thumbnail_id%'"
448
  );
 
449
  if ( count( $metas ) > 0 ) {
450
  $postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
451
  if ( empty( $postmeta_images_ids ) )
453
  foreach ( $metas as $meta )
454
  if ( is_numeric( $meta ) && $meta > 0 )
455
  array_push( $postmeta_images_ids, $meta );
456
+ set_transient( "wpmc_postmeta_images_ids", $postmeta_images_ids, Meow_WPMC_Core::$transient_life );
457
  $found['wpmc_postmeta_images_ids'] = $postmeta_images_ids;
458
  }
459
  }
460
 
 
 
 
 
 
461
  // Analyze Posts
462
  foreach ( $posts as $post ) {
463
 
464
+ // Get HTML for this post
465
  $html = get_post_field( 'post_content', $post );
466
+ $html = do_shortcode( $html );
467
+ $html = wp_make_content_images_responsive( $html );
468
+
469
+ // Run the scanners
470
+ if ( $check_postmeta )
471
+ do_action( 'wpmc_scan_postmeta', $post );
472
+ if ( $check_posts )
473
+ do_action( "wpmc_scan_post", $html, $post );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  }
475
  $finished = count( $posts ) < $limitsize;
476
  if ( $finished ) {
487
  $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
488
  $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
489
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
490
+ $galleries_images_urls = get_transient( "wpmc_galleries_images_urls" );
491
  $galleries_images_vc = get_transient( "wpmc_galleries_images_visualcomposer" );
492
  $galleries_images_fb = get_transient( "wpmc_galleries_images_fusionbuilder" );
493
  $galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
494
  $galleries_images_et = get_transient( "wpmc_galleries_images_divi" );
495
 
496
  $found['theme_urls'] = is_array( $theme_urls ) ? array_unique( $theme_urls ) : array();
 
497
  $found['widgets_urls'] = is_array( $widgets_urls ) ? array_unique( $widgets_urls ) : array();
 
498
  $found['posts_images_urls'] = is_array( $posts_images_urls ) ? array_unique( $posts_images_urls ) : array();
 
499
  $found['postmeta_images_urls'] = is_array( $postmeta_images_urls ) ? array_unique( $postmeta_images_urls ) : array();
 
500
  $found['postmeta_images_acf_urls'] = is_array( $postmeta_images_acf_urls ) ? array_unique( $postmeta_images_acf_urls ) : array();
501
+ $found['galleries_images_urls'] = is_array( $galleries_images_urls ) ? array_unique( $galleries_images_urls ) : array();
502
+
503
+ $found['theme_ids'] = is_array( $theme_ids ) ? array_unique( $theme_ids ) : array();
504
+ $found['widgets_ids'] = is_array( $widgets_ids ) ? array_unique( $widgets_ids ) : array();
505
+ $found['posts_images_ids'] = is_array( $posts_images_ids ) ? array_unique( $posts_images_ids ) : array();
506
+ $found['postmeta_images_ids'] = is_array( $postmeta_images_ids ) ? array_unique( $postmeta_images_ids ) : array();
507
  $found['postmeta_images_acf_ids'] = is_array( $postmeta_images_acf_ids ) ? array_unique( $postmeta_images_acf_ids ) : array();
508
  $found['posts_images_vc'] = is_array( $posts_images_vc ) ? array_unique( $posts_images_vc ) : array();
 
509
  $found['galleries_images_vc'] = is_array( $galleries_images_vc ) ? array_unique( $galleries_images_vc ) : array();
510
  $found['galleries_images_fb'] = is_array( $galleries_images_fb ) ? array_unique( $galleries_images_fb ) : array();
511
  $found['galleries_images_wc'] = is_array( $galleries_images_wc ) ? array_unique( $galleries_images_wc ) : array();
514
  // For safety, remove the resolutions...
515
  // That will match more files, especially the sizes created before, used before, but not part of the
516
  // media metadata anymore.
517
+
518
+ // ADD AN OPTION "CHECK SKIP RESOLUTION" (DEFAULT TRUE)
519
+ $method = get_option( 'wpmc_method', 'media' );
520
+ if ( $method == 'media' ) {
521
+ // All URLs should be without resolution to make sure it matches Media
522
+ array_walk( $found['theme_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
523
+ array_walk( $found['widgets_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
524
+ array_walk( $found['posts_images_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
525
+ array_walk( $found['postmeta_images_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
526
+ array_walk( $found['postmeta_images_acf_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
527
+ array_walk( $found['galleries_images_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
528
+ }
529
+ else {
530
+ // We need both filename without resolution and filename with resolution, it's important
531
+ // to make sure the original file is not deleted if a size exists for it
532
+ $clone = $found['theme_urls'];
533
+ array_walk( $found['theme_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
534
+ $found['theme_urls'] = array_merge( $clone, $found['theme_urls'] );
535
+ $clone = $found['widgets_urls'];
536
+ array_walk( $found['widgets_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
537
+ $found['widgets_urls'] = array_merge( $clone, $found['widgets_urls'] );
538
+ $clone = $found['posts_images_urls'];
539
+ array_walk( $found['posts_images_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
540
+ $found['posts_images_urls'] = array_merge( $clone, $found['posts_images_urls'] );
541
+ $clone = $found['postmeta_images_urls'];
542
+ array_walk( $found['postmeta_images_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
543
+ $found['postmeta_images_urls'] = array_merge( $clone, $found['postmeta_images_urls'] );
544
+ $clone = $found['postmeta_images_acf_urls'];
545
+ array_walk( $found['postmeta_images_acf_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
546
+ $found['postmeta_images_acf_urls'] = array_merge( $clone, $found['postmeta_images_acf_urls'] );
547
+ $clone = $found['galleries_images_urls'];
548
+ array_walk( $found['galleries_images_urls'], array( $this, 'clean_url_from_resolution_ref' ) );
549
+ $found['galleries_images_urls'] = array_merge( $clone, $found['galleries_images_urls'] );
550
+ }
551
+
552
+ set_transient( "wpmc_theme_urls", $found['theme_urls'], Meow_WPMC_Core::$transient_life );
553
+ set_transient( "wpmc_theme_ids", $found['theme_ids'], Meow_WPMC_Core::$transient_life );
554
+ set_transient( "wpmc_widgets_urls", $found['widgets_urls'], Meow_WPMC_Core::$transient_life );
555
+ set_transient( "wpmc_widgets_ids", $found['widgets_ids'], Meow_WPMC_Core::$transient_life );
556
+ set_transient( "wpmc_posts_images_urls", $found['posts_images_urls'], Meow_WPMC_Core::$transient_life );
557
+ set_transient( "wpmc_posts_images_ids", $found['posts_images_ids'], Meow_WPMC_Core::$transient_life );
558
+ set_transient( "wpmc_postmeta_images_urls", $found['postmeta_images_urls'], Meow_WPMC_Core::$transient_life );
559
+ set_transient( "wpmc_postmeta_images_ids", $found['postmeta_images_ids'], Meow_WPMC_Core::$transient_life );
560
+ set_transient( "wpmc_postmeta_images_acf_urls", $found['postmeta_images_acf_urls'], Meow_WPMC_Core::$transient_life );
561
+ set_transient( "wpmc_postmeta_images_acf_ids", $found['postmeta_images_acf_ids'], Meow_WPMC_Core::$transient_life );
562
+ set_transient( "wpmc_posts_images_visualcomposer", $found['posts_images_vc'], Meow_WPMC_Core::$transient_life );
563
+ set_transient( "wpmc_galleries_images_visualcomposer", $found['galleries_images_vc'], Meow_WPMC_Core::$transient_life );
564
+ set_transient( "wpmc_galleries_images_fusionbuilder", $found['galleries_images_fb'], Meow_WPMC_Core::$transient_life );
565
+ set_transient( "wpmc_galleries_images_woocommerce", $found['galleries_images_wc'], Meow_WPMC_Core::$transient_life );
566
+ set_transient( "wpmc_galleries_images_divi", $found['galleries_images_et'], Meow_WPMC_Core::$transient_life );
567
+ set_transient( "wpmc_galleries_images_urls", $found['galleries_images_urls'], Meow_WPMC_Core::$transient_life );
568
  }
569
  if ( $finished && get_option( 'wpmc_debuglogs', false ) ) {
570
  $this->log( print_r( $found, true ) );
597
  $method = 'media';
598
  $path = isset( $_POST['path'] ) ? $_POST['path'] : null;
599
  $limit = isset( $_POST['limit'] ) ? $_POST['limit'] : 0;
600
+ $limitsize = get_option( 'wpmc_medias_buffer', 100 );
601
 
602
  if ( $method == 'files' ) {
603
  $output = apply_filters( 'wpmc_list_uploaded_files', array(
800
  $table_name = $wpdb->prefix . "wpmcleaner";
801
  $issue = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d", $id ), OBJECT );
802
  $regex = "^(.*)(\\s\\(\\+.*)$";
803
+ $issue->path = preg_replace( '/' . $regex . '/i', '$1', $issue->path ); // remove " (+ 6 files)" from path
804
 
805
  // Make sure there isn't a media DB entry
806
  if ( $issue->type == 0 ) {
899
  return ($count > 0);
900
  }
901
 
902
+ function wpmc_find_attachment_id_by_file( $file ) {
903
  global $wpdb;
904
  $postmeta_table_name = $wpdb->prefix . 'postmeta';
905
  $file = $this->wpmc_clean_uploaded_filename( $file );
936
  return $sizes;
937
  }
938
 
939
+ function clean_url_from_resolution( $url ) {
940
  $pattern = '/[_-]\d+x\d+(?=\.[a-z]{3,4}$)/';
941
  $url = preg_replace( $pattern, '', $url );
942
  return $url;
943
  }
944
 
945
+ function clean_url_from_resolution_ref( &$url ) {
946
+ $url = $this->clean_url_from_resolution( $url );
947
+ }
948
+
949
  // From a url to the shortened and cleaned url (for example '2013/02/file.png')
950
  function wpmc_clean_url( $url ) {
951
  $upload_folder = wp_upload_dir();
987
  $countfiles = 0;
988
  $issue = 'NO_CONTENT';
989
  if ( file_exists( $fullpath ) ) {
990
+
991
+ // Special scan: Broken only!
992
+ $check_postmeta = get_option( 'wpmc_postmeta', false );
993
+ $check_posts = get_option( 'wpmc_posts', false );
994
+ $check_widgets = get_option( 'wpmc_widgets', false );
995
+ if ( !$check_postmeta && !$check_posts && !$check_widgets )
996
+ return true;
997
+
998
  $size = filesize( $fullpath );
999
 
1000
  // ANALYSIS
1090
  delete_transient( "wpmc_galleries_images_fusionbuilder" );
1091
  delete_transient( "wpmc_galleries_images_woocommerce" );
1092
  delete_transient( "wpmc_galleries_images_divi" );
1093
+ delete_transient( "wpmc_galleries_images_urls" );
1094
  }
1095
 
1096
  /**
1103
  echo "<script type='text/javascript'>\n";
1104
  echo 'var wpmc_cfg = {
1105
  delay: ' . get_option( 'wpmc_delay', 100 ) . ',
1106
+ analysisBuffer: ' . get_option( 'wpmc_analysis_buffer', 50 ) . ',
1107
  isPro: ' . ( $this->admin->is_registered() ? '1' : '0') . ',
1108
  scanFiles: ' . ( ( get_option( 'wpmc_method', 'media' ) == 'files' && $this->admin->is_registered() ) ? '1' : '0' ) . ',
1109
  scanMedia: ' . ( get_option( 'wpmc_method', 'media' ) == 'media' ? '1' : '0' ) . ' };';
1295
 
1296
  if ( !$this->admin->is_registered() ) {
1297
  echo "<div class='notice notice-info'><p>";
1298
+ _e( "<b>This version is not Pro.</b> This plugin is a lot of work so please consider <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a> in order to receive support and to contribute in the evolution of it. Also, <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a> version will also give you the option <b>to scan the physical files in your /uploads folder</b> and extra checks for the common Page Builders.", 'media-cleaner' );
1299
  echo "</p></div>";
1300
+
1301
+ if ( function_exists( '_et_core_find_latest' ) ) {
1302
+ echo "<div class='notice notice-warning'><p>";
1303
+ _e( "<b>Divi has been detected</b>. The free version might detect the files used by Divi correctly, but its full support is only available in <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a>.", 'media-cleaner' );
1304
+ echo "</p></div>";
1305
+ }
1306
+
1307
+ if ( class_exists( 'Vc_Manager' ) ) {
1308
+ echo "<div class='notice notice-warning'><p>";
1309
+ _e( "<b>Visual Composer has been detected</b>. The free version might detect the files used by Visual Composer correctly, but its full support is only available in <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a>.", 'media-cleaner' );
1310
+ echo "</p></div>";
1311
+ }
1312
+
1313
+ if ( function_exists( 'fusion_builder_map' ) ) {
1314
+ echo "<div class='notice notice-warning'><p>";
1315
+ _e( "<b>Fusion Builder has been detected</b>. The free version might detect the files used by Fusion Builder correctly, but its full support is only available in <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a>.", 'media-cleaner' );
1316
+ echo "</p></div>";
1317
+ }
1318
+
1319
+ if ( class_exists( 'FLBuilderModel' ) ) {
1320
+ echo "<div class='notice notice-warning'><p>";
1321
+ _e( "<b>Beaver Builder has been detected</b>. The free version might detect the files used by Beaver Builder correctly, but its full support is only available in <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a>.", 'media-cleaner' );
1322
+ echo "</p></div>";
1323
+ }
1324
+
1325
+ if ( function_exists( 'elementor_load_plugin_textdomain' ) ) {
1326
+ echo "<div class='notice notice-warning'><p>";
1327
+ _e( "<b>Elementor has been detected</b>. The free version might detect the files used by Elementor correctly, but its full support is only available in <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a>.", 'media-cleaner' );
1328
+ echo "</p></div>";
1329
+ }
1330
+
1331
+ if ( class_exists( 'SiteOrigin_Panels' ) ) {
1332
+ echo "<div class='notice notice-warning'><p>";
1333
+ _e( "<b>SiteOrigin Page Builder has been detected</b>. The free version might detect the files used by SiteOrigin Page Builder correctly, but its full support is only available in <a target='_blank' href='//meowapps.com/media-cleaner'>Media Cleaner Pro</a>.", 'media-cleaner' );
1334
+ echo "</p></div>";
1335
+ }
1336
+
1337
  }
1338
 
1339
+ $anychecks = get_option( 'wpmc_posts', false ) || get_option( 'wpmc_postmeta', false ) || get_option( 'wpmc_widgets', false );
1340
+ $check_library = get_option(' wpmc_media_library', true );
 
1341
 
1342
  if ( $method == 'media' ) {
1343
  if ( !$anychecks )
1344
+ _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. Media Cleaner will therefore run a special scan: <b>only the broken medias will be detected as issues.</b></p></div>", 'media-cleaner' );
1345
  else
1346
  _e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Media Library.</p></div>", 'media-cleaner' );
1347
  }
1348
  else if ( $method == 'files' ) {
1349
  if ( !$anychecks && !$check_library )
1350
+ _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, all the files will be detected as <b>NOT USED</b>.</p></div>", 'media-cleaner' );
1351
  else
1352
  _e( "<div class='notice notice-success'><p>Media Cleaner will analyze your Filesystem.</p></div>", 'media-cleaner' );
1353
  }
1416
  }
1417
  else {
1418
  // MEDIA
1419
+ $file = get_attached_file( $issue->postId );
1420
+ if ( file_exists( $file ) ) {
1421
+ $attachmentsrc = wp_get_attachment_image_src( $issue->postId, 'thumbnail' );
1422
+ if ( empty( $attachmentsrc ) )
1423
+ echo '<span class="dashicons dashicons-no-alt"></span>';
1424
+ else {
1425
+ $attachmentsrc_clean = htmlspecialchars( $attachmentsrc[0], ENT_QUOTES );
1426
+ echo "<a target='_blank' href='" . $attachmentsrc_clean .
1427
+ "'><img style='max-width: 48px; max-height: 48px;' src='" .
1428
+ $attachmentsrc_clean . "' />";
1429
+ }
1430
+ }
1431
+ else {
1432
+ echo '<span class="dashicons dashicons-no-alt"></span>';
1433
+ }
1434
  }
1435
  }
1436
  if ( $issue->deleted == 1 ) {
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.5.0
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.5.0';
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.5.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.5.4';
31
 
32
  // Admin
33
  require( 'wpmc_admin.php' );
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Media Cleaner ===
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.5.0
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
 
@@ -13,19 +13,17 @@ Clean your Media Library from the media which aren't used in any of your posts,
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 ACF, Divi, Fusion Builder (Avada), WooCommerce, Visual Composer (WPBakery), Elementor, Beaver Builder, and Gutenberg.
19
 
20
  **SPECIAL PLUGIN**. Such a plugin is difficult to create and to maintain. If you understand WordPress, you probably know why. This plugin does its best to help you. Learn how to use it and you will get awesome results.
21
 
22
  **DASHBOARD**. The files detected as not used will be listed in a specific dashboard. At this point, it will be up to you to delete them. They will be then moved to a trash internal to the plugin. After more testing, you can trash them permanently.
23
 
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
-
28
- It has been tested with WP Retina 2x and WPML.
29
 
30
  == Installation ==
31
 
@@ -52,6 +50,12 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
 
55
  = 4.5.0 =
56
  * Add: Support for WooCommerce Short Description.
57
  * Add: Support for Divi Background.
1
  === Media Cleaner ===
2
  Contributors: TigrouMeow
3
+ Tags: clean, delete, file, files, images, image, media, library, upload, clean, acf
4
  Requires at least: 4.2
5
  Tested up to: 4.9
6
+ Stable tag: 4.5.4
7
 
8
+ Clean your WordPress (broken media, unused media, files). It has its own trash and recovery features. Please read the description.
9
 
10
  == Description ==
11
 
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. Do not 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 specific plugins little by little. Currently, I have been working with ACF, Gutenberg, Divi, Fusion Builder (Avada), WooCommerce, Visual Composer (WPBakery), Elementor, and Beaver Builder. **Specific checks for Page Builders are being added to the Pro version** (as it requires meticulous work and updates).
19
 
20
  **SPECIAL PLUGIN**. Such a plugin is difficult to create and to maintain. If you understand WordPress, you probably know why. This plugin does its best to help you. Learn how to use it and you will get awesome results.
21
 
22
  **DASHBOARD**. The files detected as not used will be listed in a specific dashboard. At this point, it will be up to you to delete them. They will be then moved to a trash internal to the plugin. After more testing, you can trash them permanently.
23
 
24
+ **PRO**. [Media Cleaner Pro](https://meowapps.com/media-cleaner) can scan your physical /uploads directory, and match it against the Media Library. It also has extra support for Page Builders.
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.
 
 
27
 
28
  == Installation ==
29
 
50
 
51
  == Changelog ==
52
 
53
+ = 4.5.4 =
54
+ * Update: Streamlined the plugin, tutorial has also been rewritten.
55
+ * Update: Simplified the Settings. Removed the Gallery option, as it is part of the Posts or Post Meta.
56
+ * Update: Support for UTF8, Background CSS, and Shortcodes have been moved to the Free version, and are now always enabled. Easier for everyone.
57
+ * Add: Extra support for Page Builders is being added into the Pro version.
58
+
59
  = 4.5.0 =
60
  * Add: Support for WooCommerce Short Description.
61
  * Add: Support for Divi Background.
wpmc_admin.php CHANGED
@@ -12,17 +12,17 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
12
 
13
  function admin_notices() {
14
 
15
- $mediasBuffer = get_option( 'wpmc_medias_buffer', 50 );
16
- $postsBuffer = get_option( 'wpmc_posts_buffer', 5 );
17
- $analysisBuffer = get_option( 'wpmc_analysis_buffer', 10 );
18
- $delay = get_option( 'wpmc_delay', 100 );
19
 
20
  if ( !is_numeric( $mediasBuffer ) || $mediasBuffer < 1 )
21
- update_option( 'wpmc_medias_buffer', 50 );
22
  if ( !is_numeric( $postsBuffer ) || $postsBuffer < 1 )
23
  update_option( 'wpmc_posts_buffer', 5 );
24
  if ( !is_numeric( $analysisBuffer ) || $analysisBuffer < 1 )
25
- update_option( 'wpmc_analysis_buffer', 10 );
26
  if ( !is_numeric( $delay ) )
27
  update_option( 'wpmc_delay', 100 );
28
 
@@ -46,29 +46,26 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
46
  add_settings_field( 'wpmc_method', "Method",
47
  array( $this, 'admin_method_callback' ),
48
  'wpmc_settings-menu', 'wpmc_settings' );
49
- if ( get_option( 'wpmc_method', 'media' ) == 'files' ) {
50
- add_settings_field( 'wpmc_media_library', "Media Library",
51
  array( $this, 'admin_media_library_callback' ),
52
  'wpmc_settings-menu', 'wpmc_settings' );
53
- }
54
  add_settings_field( 'wpmc_posts', "Posts",
55
  array( $this, 'admin_posts_callback' ),
56
  'wpmc_settings-menu', 'wpmc_settings' );
57
  add_settings_field( 'wpmc_postmeta', "Post Meta",
58
  array( $this, 'admin_postmeta_callback' ),
59
  'wpmc_settings-menu', 'wpmc_settings' );
60
- add_settings_field( 'wpmc_galleries', "Galleries",
61
- array( $this, 'admin_galleries_callback' ),
62
- 'wpmc_settings-menu', 'wpmc_settings' );
63
  add_settings_field( 'wpmc_widgets', "Widgets",
64
  array( $this, 'admin_widgets_callback' ),
65
  'wpmc_settings-menu', 'wpmc_settings' );
66
- add_settings_field( 'wpmc_shortcode', "Shortcodes<br />(Pro)",
67
- array( $this, 'admin_shortcode_callback' ),
68
- 'wpmc_settings-menu', 'wpmc_settings' );
69
- add_settings_field( 'wpmc_background', "Background CSS<br />(Pro)",
70
- array( $this, 'admin_background_callback' ),
71
- 'wpmc_settings-menu', 'wpmc_settings' );
72
  add_settings_field( 'wpmc_debuglogs', "Logs",
73
  array( $this, 'admin_debuglogs_callback' ),
74
  'wpmc_settings-menu', 'wpmc_settings', array( "Enable" ) );
@@ -78,7 +75,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
78
  add_settings_field( 'wpmc_hide_thumbnails', "Thumbnails",
79
  array( $this, 'admin_hide_thumbnails_callback' ),
80
  'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
81
- add_settings_field( 'wpmc_hide_warning', "Warning Message (Pro)",
82
  array( $this, 'admin_hide_warning_callback' ),
83
  'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
84
 
@@ -100,9 +97,8 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
100
  // SETTINGS
101
  register_setting( 'wpmc_settings', 'wpmc_method' );
102
  register_setting( 'wpmc_settings', 'wpmc_posts' );
103
- register_setting( 'wpmc_settings', 'wpmc_shortcode' );
104
- register_setting( 'wpmc_settings', 'wpmc_background' );
105
- register_setting( 'wpmc_settings', 'wpmc_galleries' );
106
  register_setting( 'wpmc_settings', 'wpmc_widgets' );
107
  register_setting( 'wpmc_settings', 'wpmc_media_library' );
108
  register_setting( 'wpmc_settings', 'wpmc_postmeta' );
@@ -118,7 +114,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
118
  }
119
 
120
  function admin_medias_buffer_callback( $args ) {
121
- $value = get_option( 'wpmc_medias_buffer', 50 );
122
  $html = '<input type="number" style="width: 100%;" id="wpmc_medias_buffer" name="wpmc_medias_buffer" value="' . $value . '" />';
123
  $html .= '<br /><span class="description">The number of medias to read in one time during the preparation phase. This is fast, so the value should be between 50 and 1000.</label>';
124
  echo $html;
@@ -127,14 +123,14 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
127
  function admin_posts_buffer_callback( $args ) {
128
  $value = get_option( 'wpmc_posts_buffer', 5 );
129
  $html = '<input type="number" style="width: 100%;" id="wpmc_posts_buffer" name="wpmc_posts_buffer" value="' . $value . '" />';
130
- $html .= '<br /><span class="description">The number of posts to read in one time during the preparation phase. This takes a bit of time in case galleries are being used. Recommended value is between 5 and 20.</label>';
131
  echo $html;
132
  }
133
 
134
  function admin_analysis_buffer_callback( $args ) {
135
- $value = get_option( 'wpmc_analysis_buffer', 10 );
136
  $html = '<input type="number" style="width: 100%;" id="wpmc_analysis_buffer" name="wpmc_analysis_buffer" value="' . $value . '" />';
137
- $html .= '<br /><span class="description">The number of medias or files to analyse in one time. It is the main part of the process and it depends on the scanning options. Recommended value is 5 but can be more on a powerful server, or 1 if your server is not powerful or your WordPress very bloated.</label>';
138
  echo $html;
139
  }
140
 
@@ -203,10 +199,11 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
203
  </div>
204
  </div>
205
 
 
206
  <?php if ( get_option( 'wpmc_shortcode', false ) ): ?>
207
  <div class="meow-box">
208
  <h3>Shortcodes</h3>
209
- <div class="inside">
210
  <p>Here are the shortcodes registered in your WordPress by your theme and other plugins.</p>
211
  <?php
212
  global $shortcode_tags;
@@ -218,7 +215,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
218
  if ( is_string( $sc ) )
219
  array_push( $my_shortcodes, str_replace( '_shortcode', '', (string)$sc ) );
220
  }
221
- $my_shortcodes = implode( '<br />', $my_shortcodes );
222
  }
223
  }
224
  catch (Exception $e) {
@@ -226,9 +223,10 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
226
  }
227
  echo $my_shortcodes;
228
  ?>
229
- </div>
230
  </div>
231
  <?php endif; ?>
 
232
 
233
  </div>
234
 
@@ -248,26 +246,26 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
248
  $html = '<select id="wpmc_method" name="wpmc_method">
249
  <option ' . selected( 'media', $value, false ) . 'value="media">Media Library</option>
250
  <option ' . disabled( $this->is_registered(), false, false ) . ' ' . selected( 'files', $value, false ) . 'value="files">Filesystem (Pro)</option>
251
- </select><small><br /><br />' . __( '<b>Media Library</b>: The medias from Media Library which seem not being used in your WordPress will be marked as to be deleted. <br /><br /><b>Filesystem</b>: The files in your /uploads directory that don\'t seem being used in your WordPress will be marked as to be deleted. If the files are registered as a media in your Media Library, they will be considered as fine (even if they are not used in the content of your website).', 'media-cleaner' ) . '</small>';
252
  echo $html;
253
  }
254
 
255
 
256
- function admin_shortcode_callback( $args ) {
257
- $value = get_option( 'wpmc_shortcode', null );
258
- $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_shortcode" name="wpmc_shortcode" value="1" ' .
259
- checked( 1, get_option( 'wpmc_shortcode' ), false ) . '/>';
260
- $html .= '<label>Resolve</label><br /><small>The shortcodes you are using in your <b>posts</b> and/or <b>widgets</b> (depending on your options) will be resolved and analyzed. You don\'t need to have this option enabled for the WP Gallery (as it is covered by the Galleries option).</small>';
261
- echo $html;
262
- }
263
 
264
- function admin_background_callback( $args ) {
265
- $value = get_option( 'wpmc_background', null );
266
- $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_background" name="wpmc_background" value="1" ' .
267
- checked( 1, get_option( 'wpmc_background' ), false ) . '/>';
268
- $html .= '<label>Analyze</label><br /><small>When parsing HTML, the CSS inline background will also be analyzed. A few page builders are using this.</small>';
269
- echo $html;
270
- }
271
 
272
  function admin_debuglogs_callback( $args ) {
273
  $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
@@ -277,27 +275,20 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
277
  $html = '<input type="checkbox" id="wpmc_debuglogs" name="wpmc_debuglogs" value="1" ' .
278
  checked( 1, get_option( 'wpmc_debuglogs' ), false ) . '/>';
279
  $html .= '<label for="wpmc_debuglogs"> ' . $args[0] . '</label><br>';
280
- $html .= '<span class="description">' . __( 'Create an internal log file. For advanced users only.', 'media-cleaner' );
281
  if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
282
  $html .= sprintf( __( '<br />The <a target="_blank" href="%smedia-cleaner.log">log file</a> is available. You can also <a href="?page=wpmc_settings-menu&clearlogs=true">clear</a> it.', 'media-cleaner' ), plugin_dir_url( __FILE__ ) );
283
  }
284
- $html .= '</span>';
285
  echo $html;
286
  }
287
 
288
  function admin_media_library_callback( $args ) {
289
- $value = get_option( 'wpmc_media_library', null );
290
  $html = '<input type="checkbox" id="wpmc_media_library" name="wpmc_media_library" value="1" ' .
 
291
  checked( 1, get_option( 'wpmc_media_library' ), false ) . '/>';
292
- $html .= '<label>Check</label><br /><small>Checks if the file is part of a Media (as a full-size or alternative size). This option is of course only available for the Filesystem method.</small>';
293
- echo $html;
294
- }
295
-
296
- function admin_galleries_callback( $args ) {
297
- $value = get_option( 'wpmc_galleries', null );
298
- $html = '<input type="checkbox" id="wpmc_galleries" name="wpmc_galleries" value="1" ' .
299
- checked( 1, get_option( 'wpmc_galleries' ), false ) . '/>';
300
- $html .= '<label>Analyze</label><br /><small>Checks if the file is used in a <b>WP Gallery</b> (in any post type) or in a <b>WooCommerce Gallery</b>.</small>';
301
  echo $html;
302
  }
303
 
@@ -305,7 +296,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
305
  $value = get_option( 'wpmc_posts', true );
306
  $html = '<input type="checkbox" id="wpmc_posts" name="wpmc_posts" value="1" ' .
307
  checked( 1, get_option( 'wpmc_posts' ), false ) . '/>';
308
- $html .= '<label>Analyze</label><br /><small>Check if the file is used in posts (that includes any post-type: pages, products and others) and, in addition, in case of the Media, check if it used in the IMG\'s class.</small>';
309
  echo $html;
310
  }
311
 
@@ -313,7 +304,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
313
  $value = get_option( 'wpmc_postmeta', true );
314
  $html = '<input type="checkbox" id="wpmc_postmeta" name="wpmc_postmeta" value="1" ' .
315
  checked( 1, get_option( 'wpmc_postmeta' ), false ) . '/>';
316
- $html .= '<label>Analyze</label><br /><small>Checks if the file is used in the Post Meta. One basic usage of the Post Meta is to store information about the <b>Featured Image</b>. But it also used by certain gallery plugins.</small>';
317
  echo $html;
318
  }
319
 
@@ -321,7 +312,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
321
  $value = get_option( 'wpmc_widgets', false );
322
  $html = '<input type="checkbox" id="wpmc_widgets" name="wpmc_widgets" value="1" ' .
323
  checked( 1, get_option( 'wpmc_widgets' ), false ) . '/>';
324
- $html .= '<label>Analyze</label><br /><small>Checks if the file is used in widgets.</small>';
325
  echo $html;
326
  }
327
 
@@ -335,7 +326,7 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
335
 
336
  function admin_hide_warning_callback( $args ) {
337
  $value = get_option( 'wpmc_hide_warning', null );
338
- $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_hide_warning" name="wpmc_hide_warning" value="1" ' .
339
  checked( 1, get_option( 'wpmc_hide_warning' ), false ) . '/>';
340
  $html .= '<label>Hide</label><br /><small>Have you read it twice? If yes, hide it :)</small>';
341
  echo $html;
12
 
13
  function admin_notices() {
14
 
15
+ $mediasBuffer = get_option( 'wpmc_medias_buffer', null );
16
+ $postsBuffer = get_option( 'wpmc_posts_buffer', null );
17
+ $analysisBuffer = get_option( 'wpmc_analysis_buffer', null );
18
+ $delay = get_option( 'wpmc_delay', null );
19
 
20
  if ( !is_numeric( $mediasBuffer ) || $mediasBuffer < 1 )
21
+ update_option( 'wpmc_medias_buffer', 100 );
22
  if ( !is_numeric( $postsBuffer ) || $postsBuffer < 1 )
23
  update_option( 'wpmc_posts_buffer', 5 );
24
  if ( !is_numeric( $analysisBuffer ) || $analysisBuffer < 1 )
25
+ update_option( 'wpmc_analysis_buffer', 50 );
26
  if ( !is_numeric( $delay ) )
27
  update_option( 'wpmc_delay', 100 );
28
 
46
  add_settings_field( 'wpmc_method', "Method",
47
  array( $this, 'admin_method_callback' ),
48
  'wpmc_settings-menu', 'wpmc_settings' );
49
+ //if ( get_option( 'wpmc_method', 'media' ) == 'files' ) {
50
+ add_settings_field( 'wpmc_media_library', "Media",
51
  array( $this, 'admin_media_library_callback' ),
52
  'wpmc_settings-menu', 'wpmc_settings' );
53
+ //}
54
  add_settings_field( 'wpmc_posts', "Posts",
55
  array( $this, 'admin_posts_callback' ),
56
  'wpmc_settings-menu', 'wpmc_settings' );
57
  add_settings_field( 'wpmc_postmeta', "Post Meta",
58
  array( $this, 'admin_postmeta_callback' ),
59
  'wpmc_settings-menu', 'wpmc_settings' );
 
 
 
60
  add_settings_field( 'wpmc_widgets', "Widgets",
61
  array( $this, 'admin_widgets_callback' ),
62
  'wpmc_settings-menu', 'wpmc_settings' );
63
+ // add_settings_field( 'wpmc_shortcode', "Shortcodes<br />(Pro)",
64
+ // array( $this, 'admin_shortcode_callback' ),
65
+ // 'wpmc_settings-menu', 'wpmc_settings' );
66
+ // add_settings_field( 'wpmc_background', "Background CSS<br />(Pro)",
67
+ // array( $this, 'admin_background_callback' ),
68
+ // 'wpmc_settings-menu', 'wpmc_settings' );
69
  add_settings_field( 'wpmc_debuglogs', "Logs",
70
  array( $this, 'admin_debuglogs_callback' ),
71
  'wpmc_settings-menu', 'wpmc_settings', array( "Enable" ) );
75
  add_settings_field( 'wpmc_hide_thumbnails', "Thumbnails",
76
  array( $this, 'admin_hide_thumbnails_callback' ),
77
  'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
78
+ add_settings_field( 'wpmc_hide_warning', "Warning Message",
79
  array( $this, 'admin_hide_warning_callback' ),
80
  'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
81
 
97
  // SETTINGS
98
  register_setting( 'wpmc_settings', 'wpmc_method' );
99
  register_setting( 'wpmc_settings', 'wpmc_posts' );
100
+ // register_setting( 'wpmc_settings', 'wpmc_shortcode' );
101
+ // register_setting( 'wpmc_settings', 'wpmc_background' );
 
102
  register_setting( 'wpmc_settings', 'wpmc_widgets' );
103
  register_setting( 'wpmc_settings', 'wpmc_media_library' );
104
  register_setting( 'wpmc_settings', 'wpmc_postmeta' );
114
  }
115
 
116
  function admin_medias_buffer_callback( $args ) {
117
+ $value = get_option( 'wpmc_medias_buffer', 100 );
118
  $html = '<input type="number" style="width: 100%;" id="wpmc_medias_buffer" name="wpmc_medias_buffer" value="' . $value . '" />';
119
  $html .= '<br /><span class="description">The number of medias to read in one time during the preparation phase. This is fast, so the value should be between 50 and 1000.</label>';
120
  echo $html;
123
  function admin_posts_buffer_callback( $args ) {
124
  $value = get_option( 'wpmc_posts_buffer', 5 );
125
  $html = '<input type="number" style="width: 100%;" id="wpmc_posts_buffer" name="wpmc_posts_buffer" value="' . $value . '" />';
126
+ $html .= '<br /><span class="description">The number of posts to read in one time during the preparation phase. This takes a bit of time in case galleries are being used. Recommended value is between 1 and 20.</label>';
127
  echo $html;
128
  }
129
 
130
  function admin_analysis_buffer_callback( $args ) {
131
+ $value = get_option( 'wpmc_analysis_buffer', 50 );
132
  $html = '<input type="number" style="width: 100%;" id="wpmc_analysis_buffer" name="wpmc_analysis_buffer" value="' . $value . '" />';
133
+ $html .= '<br /><span class="description">The number of medias or files to analyse in one time. It is the main part of the process and it depends on the scanning options. Recommended value is between 10 and 500.</label>';
134
  echo $html;
135
  }
136
 
199
  </div>
200
  </div>
201
 
202
+ <!--
203
  <?php if ( get_option( 'wpmc_shortcode', false ) ): ?>
204
  <div class="meow-box">
205
  <h3>Shortcodes</h3>
206
+ <div class="inside"><small>
207
  <p>Here are the shortcodes registered in your WordPress by your theme and other plugins.</p>
208
  <?php
209
  global $shortcode_tags;
215
  if ( is_string( $sc ) )
216
  array_push( $my_shortcodes, str_replace( '_shortcode', '', (string)$sc ) );
217
  }
218
+ $my_shortcodes = implode( ', ', $my_shortcodes );
219
  }
220
  }
221
  catch (Exception $e) {
223
  }
224
  echo $my_shortcodes;
225
  ?>
226
+ </small></div>
227
  </div>
228
  <?php endif; ?>
229
+ -->
230
 
231
  </div>
232
 
246
  $html = '<select id="wpmc_method" name="wpmc_method">
247
  <option ' . selected( 'media', $value, false ) . 'value="media">Media Library</option>
248
  <option ' . disabled( $this->is_registered(), false, false ) . ' ' . selected( 'files', $value, false ) . 'value="files">Filesystem (Pro)</option>
249
+ </select><small><br />' . __( 'Check the <a target="_blank" href="//meowapps.com/media-cleaner/tutorial/">tutorial</a> for more information.', 'media-cleaner' ) . '</small>';
250
  echo $html;
251
  }
252
 
253
 
254
+ // function admin_shortcode_callback( $args ) {
255
+ // $value = get_option( 'wpmc_shortcode', null );
256
+ // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_shortcode" name="wpmc_shortcode" value="1" ' .
257
+ // checked( 1, get_option( 'wpmc_shortcode' ), false ) . '/>';
258
+ // $html .= '<label>Resolve</label><br /><small>The shortcodes you are using in your <b>posts</b> and/or <b>widgets</b> (depending on your options) will be resolved and analyzed. You don\'t need to have this option enabled for the WP Gallery (as it is covered by the Galleries option).</small>';
259
+ // echo $html;
260
+ // }
261
 
262
+ // function admin_background_callback( $args ) {
263
+ // $value = get_option( 'wpmc_background', null );
264
+ // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_background" name="wpmc_background" value="1" ' .
265
+ // checked( 1, get_option( 'wpmc_background' ), false ) . '/>';
266
+ // $html .= '<label>Analyze</label><br /><small>When parsing HTML, the CSS inline background will also be analyzed. A few page builders are using this.</small>';
267
+ // echo $html;
268
+ // }
269
 
270
  function admin_debuglogs_callback( $args ) {
271
  $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
275
  $html = '<input type="checkbox" id="wpmc_debuglogs" name="wpmc_debuglogs" value="1" ' .
276
  checked( 1, get_option( 'wpmc_debuglogs' ), false ) . '/>';
277
  $html .= '<label for="wpmc_debuglogs"> ' . $args[0] . '</label><br>';
278
+ $html .= '<small>' . __( 'Creates an internal log file, for debugging purposes.', 'media-cleaner' );
279
  if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
280
  $html .= sprintf( __( '<br />The <a target="_blank" href="%smedia-cleaner.log">log file</a> is available. You can also <a href="?page=wpmc_settings-menu&clearlogs=true">clear</a> it.', 'media-cleaner' ), plugin_dir_url( __FILE__ ) );
281
  }
282
+ $html .= '</small>';
283
  echo $html;
284
  }
285
 
286
  function admin_media_library_callback( $args ) {
287
+ $value = get_option( 'wpmc_media_library', true );
288
  $html = '<input type="checkbox" id="wpmc_media_library" name="wpmc_media_library" value="1" ' .
289
+ disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' .
290
  checked( 1, get_option( 'wpmc_media_library' ), false ) . '/>';
291
+ $html .= '<label>Check (Filesystem only)</label><br /><small>Checks if the file is linked to a media.</small>';
 
 
 
 
 
 
 
 
292
  echo $html;
293
  }
294
 
296
  $value = get_option( 'wpmc_posts', true );
297
  $html = '<input type="checkbox" id="wpmc_posts" name="wpmc_posts" value="1" ' .
298
  checked( 1, get_option( 'wpmc_posts' ), false ) . '/>';
299
+ $html .= '<label>Analyze</label><br /><small>Check if the media/file is used by any post types.</small>';
300
  echo $html;
301
  }
302
 
304
  $value = get_option( 'wpmc_postmeta', true );
305
  $html = '<input type="checkbox" id="wpmc_postmeta" name="wpmc_postmeta" value="1" ' .
306
  checked( 1, get_option( 'wpmc_postmeta' ), false ) . '/>';
307
+ $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used in the meta.</small>';
308
  echo $html;
309
  }
310
 
312
  $value = get_option( 'wpmc_widgets', false );
313
  $html = '<input type="checkbox" id="wpmc_widgets" name="wpmc_widgets" value="1" ' .
314
  checked( 1, get_option( 'wpmc_widgets' ), false ) . '/>';
315
+ $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used by any widget.</small>';
316
  echo $html;
317
  }
318
 
326
 
327
  function admin_hide_warning_callback( $args ) {
328
  $value = get_option( 'wpmc_hide_warning', null );
329
+ $html = '<input type="checkbox" id="wpmc_hide_warning" name="wpmc_hide_warning" value="1" ' .
330
  checked( 1, get_option( 'wpmc_hide_warning' ), false ) . '/>';
331
  $html .= '<label>Hide</label><br /><small>Have you read it twice? If yes, hide it :)</small>';
332
  echo $html;
wpmc_checkers.php CHANGED
@@ -31,9 +31,6 @@ class Meow_WPMC_Checkers {
31
 
32
  function check_in_gallery( $file, $mediaId = 0 ) {
33
 
34
- if ( !get_option( 'wpmc_galleries', false ) )
35
- return false;
36
-
37
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
38
  $pinfo = pathinfo( $file );
39
  $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
@@ -92,8 +89,8 @@ class Meow_WPMC_Checkers {
92
  ***************************************************************************/
93
 
94
  // Check in standard WP Galleries (URLS)
95
- $galleries_images = get_transient( "wpmc_galleries_images" );
96
- if ( is_array( $galleries_images ) && in_array( $file, $galleries_images ) ) {
97
  $this->core->log( "URL {$file} found in a standard WP Gallery" );
98
  $this->core->last_analysis = "GALLERY";
99
  return true;
@@ -154,11 +151,6 @@ class Meow_WPMC_Checkers {
154
  $this->core->last_analysis_ids = null;
155
  $shortcode_support = get_option( 'wpmc_shortcode', false );
156
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
157
-
158
- // I think that was making sense before, but now now.
159
- // $pinfo = pathinfo( $file );
160
- // $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
161
- // ( isset( $pinfo['extension'] ) ? ( '.' . $pinfo['extension'] ) : '' );
162
  $url = $file;
163
 
164
  // Check in Posts Content
@@ -178,7 +170,7 @@ class Meow_WPMC_Checkers {
178
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
179
  if ( is_array( $posts_images_vc ) && in_array( $mediaId, $posts_images_vc ) ) {
180
  $this->core->log( "Media {$mediaId} found in content (Visual Composer)" );
181
- $this->core->last_analysis = "VISUAL COMPOSER";
182
  return true;
183
  }
184
  }
31
 
32
  function check_in_gallery( $file, $mediaId = 0 ) {
33
 
 
 
 
34
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
35
  $pinfo = pathinfo( $file );
36
  $url = $pinfo['dirname'] . '/' . $pinfo['filename'] .
89
  ***************************************************************************/
90
 
91
  // Check in standard WP Galleries (URLS)
92
+ $galleries_images_urls = get_transient( "wpmc_galleries_images_urls" );
93
+ if ( is_array( $galleries_images_urls ) && in_array( $file, $galleries_images_urls ) ) {
94
  $this->core->log( "URL {$file} found in a standard WP Gallery" );
95
  $this->core->last_analysis = "GALLERY";
96
  return true;
151
  $this->core->last_analysis_ids = null;
152
  $shortcode_support = get_option( 'wpmc_shortcode', false );
153
  $file = $this->core->wpmc_clean_uploaded_filename( $file );
 
 
 
 
 
154
  $url = $file;
155
 
156
  // Check in Posts Content
170
  $posts_images_vc = get_transient( "wpmc_posts_images_visualcomposer" );
171
  if ( is_array( $posts_images_vc ) && in_array( $mediaId, $posts_images_vc ) ) {
172
  $this->core->log( "Media {$mediaId} found in content (Visual Composer)" );
173
+ $this->core->last_analysis = "PAGE BUILDER";
174
  return true;
175
  }
176
  }
wpmc_scan.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MeowApps_WPMC_Scan {
4
+
5
+ private $core = null;
6
+ private $likes = "";
7
+ private $metakeys = array( '%gallery%', '%ids%' );
8
+
9
+ public function __construct( $core ) {
10
+ $this->core = $core;
11
+
12
+ // Prepare likes for SQL
13
+ foreach ( $this->metakeys as $metakey )
14
+ $this->likes .= "OR meta_key LIKE '$metakey' ";
15
+
16
+ // Detect values in the general (known, based on %like%) Meta Keys
17
+ add_action( 'wpmc_scan_postmeta', array( $this, 'scan_postmeta' ) );
18
+
19
+ if ( class_exists( 'WooCommerce' ) )
20
+ add_action( 'wpmc_scan_postmeta', array( $this, 'scan_postmeta_woocommerce' ) );
21
+
22
+ // Check URLs, IDs, WP Gallery, WooCommerce
23
+ add_action( 'wpmc_scan_post', array( $this, 'scan_post' ), 10, 2 );
24
+
25
+ // Advanced Custom Fields
26
+ if ( class_exists( 'acf' ) )
27
+ add_action( 'wpmc_scan_postmeta', array( $this, 'scan_postmeta_acf' ) );
28
+
29
+ }
30
+
31
+ public function scan_post( $html, $id ) {
32
+ $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
33
+ if ( empty( $posts_images_urls ) )
34
+ $posts_images_urls = array();
35
+ $posts_images_ids = get_transient( "wpmc_posts_images_ids" );
36
+ if ( empty( $posts_images_ids ) )
37
+ $posts_images_ids = array();
38
+ $galleries_images = get_transient( "wpmc_galleries_images_urls" );
39
+ if ( empty( $galleries_images ) )
40
+ $galleries_images = array();
41
+
42
+ // Check URLs in HTML
43
+ $new_urls = $this->core->get_urls_from_html( $html );
44
+ $posts_images_urls = array_merge( $posts_images_urls, $new_urls );
45
+
46
+ // Check Excerpt for WooCommerce (= Product Short Description)
47
+ if ( class_exists( 'WooCommerce' ) ) {
48
+ $excerpt = get_post_field( 'post_excerpt', $id );
49
+ if ( !empty( $excerpt ) ) {
50
+ $new_urls = $this->core->get_urls_from_html( $excerpt );
51
+ $posts_images_urls = array_merge( $posts_images_urls, $new_urls );
52
+ }
53
+ }
54
+
55
+ // Check for images IDs through classes in in posts
56
+ preg_match_all( "/wp-image-([0-9]+)/", $html, $res );
57
+ if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
58
+ $posts_images_ids = array_merge( $posts_images_ids, $res[1] );
59
+
60
+
61
+ // Standard WP Gallery
62
+ $galleries = get_post_galleries_images( $id );
63
+ foreach ( $galleries as $gallery ) {
64
+ foreach ( $gallery as $image ) {
65
+ array_push( $galleries_images, $this->core->wpmc_clean_url( $image ) );
66
+ }
67
+ }
68
+
69
+ set_transient( "wpmc_posts_images_urls", $posts_images_urls, Meow_WPMC_Core::$transient_life );
70
+ set_transient( "wpmc_posts_images_ids", $posts_images_ids, Meow_WPMC_Core::$transient_life );
71
+ set_transient( "wpmc_galleries_images_urls", $galleries_images, Meow_WPMC_Core::$transient_life );
72
+ }
73
+
74
+ public function scan_postmeta( $id ) {
75
+ global $wpdb;
76
+ $query = $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta
77
+ WHERE post_id = %d
78
+ AND meta_key = '_thumbnail_id' ", $id ) . $this->likes;
79
+ $metas = $wpdb->get_col( $query );
80
+ if ( count( $metas ) > 0 ) {
81
+ $postmeta_images_ids = get_transient( "wpmc_postmeta_images_ids" );
82
+ if ( empty( $postmeta_images_ids ) )
83
+ $postmeta_images_ids = array();
84
+ $postmeta_images_urls = get_transient( "wpmc_postmeta_images_urls" );
85
+ if ( empty( $postmeta_images_urls ) )
86
+ $postmeta_images_urls = array();
87
+
88
+ foreach ( $metas as $meta ) {
89
+ // Just a number, let's assume it's a Media ID
90
+ if ( is_numeric( $meta ) ) {
91
+ //error_log( "META NUMERIC: " . $meta );
92
+ if ( $meta > 0 )
93
+ array_push( $postmeta_images_ids, $meta );
94
+ continue;
95
+ }
96
+ $decoded = @unserialize( $meta );
97
+ if ( is_array( $decoded ) ) {
98
+ // error_log( "META DECODED" );
99
+ // error_log( print_r( $decoded, 1 ) );
100
+ $this->core->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
101
+ continue;
102
+ }
103
+ $exploded = explode( ',', $meta );
104
+ if ( is_array( $exploded ) ) {
105
+ // error_log( "META EXPLODED" );
106
+ // error_log( print_r( $exploded, 1 ) );
107
+ $this->core->array_to_ids_or_urls( $exploded, $postmeta_images_ids, $postmeta_images_urls );
108
+ continue;
109
+ }
110
+ }
111
+ set_transient( "wpmc_postmeta_images_ids", $postmeta_images_ids, Meow_WPMC_Core::$transient_life );
112
+ set_transient( "wpmc_postmeta_images_urls", $postmeta_images_urls, Meow_WPMC_Core::$transient_life );
113
+ }
114
+ }
115
+
116
+ function scan_postmeta_woocommerce( $id ) {
117
+ global $wpdb;
118
+ $galleries_images_wc = get_transient( "wpmc_galleries_images_woocommerce" );
119
+ if ( empty( $galleries_images_wc ) )
120
+ $galleries_images_wc = array();
121
+ $res = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $id
122
+ AND meta_key = '_product_image_gallery'" );
123
+ foreach ( $res as $values ) {
124
+ $ids = explode( ',', $values );
125
+ $galleries_images_wc = array_merge( $galleries_images_wc, $ids );
126
+ }
127
+ set_transient( "wpmc_galleries_images_woocommerce", $galleries_images_wc, Meow_WPMC_Core::$transient_life );
128
+ }
129
+
130
+ public function scan_postmeta_acf( $id ) {
131
+ $postmeta_images_acf_ids = get_transient( "wpmc_postmeta_images_acf_ids" );
132
+ if ( empty( $postmeta_images_acf_ids ) )
133
+ $postmeta_images_acf_ids = array();
134
+ $postmeta_images_acf_urls = get_transient( "wpmc_postmeta_images_acf_urls" );
135
+ if ( empty( $postmeta_images_acf_urls ) )
136
+ $postmeta_images_acf_urls = array();
137
+ $fields = get_field_objects( $id );
138
+ if ( is_array( $fields ) ) {
139
+ foreach ( $fields as $field ) {
140
+ $format = "";
141
+ if ( isset( $field['return_format'] ) )
142
+ $format = $field['return_format'];
143
+ else if ( isset( $field['save_format'] ) )
144
+ $format = $field['save_format'];
145
+ if ( $field['type'] == 'image' && ( $format == 'array' || $format == 'object' ) ) {
146
+ if ( !empty( $field['value']['id'] ) )
147
+ array_push( $postmeta_images_acf_ids, $field['value']['id'] );
148
+ if ( !empty( $field['value']['url'] ) )
149
+ array_push( $postmeta_images_acf_urls, $this->core->wpmc_clean_url( $field['value']['url'] ) );
150
+ }
151
+ else if ( $field['type'] == 'image' && $format == 'id' && !empty( $field['value'] ) ) {
152
+ array_push( $postmeta_images_acf_ids, $field['value'] );
153
+ }
154
+ else if ( $field['type'] == 'image' && $format == 'url' && !empty( $field['value'] ) ) {
155
+ array_push( $postmeta_images_acf_urls, $this->core->wpmc_clean_url( $field['value'] ) );
156
+ }
157
+ else if ( $field['type'] == 'gallery' && !empty( $field['value'] ) ) {
158
+ foreach ( $field['value'] as $media ) {
159
+ if ( !empty( $media['id'] ) )
160
+ array_push( $postmeta_images_acf_ids, $media['id'] );
161
+ }
162
+ }
163
+ }
164
+ set_transient( "wpmc_postmeta_images_acf_ids", $postmeta_images_acf_ids, Meow_WPMC_Core::$transient_life );
165
+ set_transient( "wpmc_postmeta_images_acf_urls", $postmeta_images_acf_urls, Meow_WPMC_Core::$transient_life );
166
+ }
167
+ }
168
+
169
+ }