Media Cleaner - Version 4.5.6

Version Description

  • Update: Improve the code.
Download this release

Release Info

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

Code changes from version 4.5.4 to 4.5.6

Files changed (5) hide show
  1. common/admin.php +3 -2
  2. core.php +9 -3
  3. media-cleaner.php +4 -4
  4. readme.txt +5 -2
  5. wpmc_admin.php +10 -2
common/admin.php CHANGED
@@ -245,9 +245,10 @@ if ( !class_exists( 'MeowApps_Admin' ) ) {
245
 
246
  function check_install( $plugin ) {
247
  $pro = false;
248
- $pluginpath = get_home_path() . 'wp-content/plugins/' . $plugin . '-pro';
 
249
  if ( !file_exists( $pluginpath ) ) {
250
- $pluginpath = get_home_path() . 'wp-content/plugins/' . $plugin;
251
  if ( !file_exists( $pluginpath ) ) {
252
  $url = wp_nonce_url( "update.php?action=install-plugin&plugin=$plugin", "install-plugin_$plugin" );
253
  return "<a href='$url'><small><span class='' style='float: right;'>install</span></small></a>";
245
 
246
  function check_install( $plugin ) {
247
  $pro = false;
248
+
249
+ $pluginpath = trailingslashit( plugin_dir_path( __FILE__ ) ) . '../../' . $plugin . '-pro';
250
  if ( !file_exists( $pluginpath ) ) {
251
+ $pluginpath = trailingslashit( plugin_dir_path( __FILE__ ) ) . '../../' . $plugin;
252
  if ( !file_exists( $pluginpath ) ) {
253
  $url = wp_nonce_url( "update.php?action=install-plugin&plugin=$plugin", "install-plugin_$plugin" );
254
  return "<a href='$url'><small><span class='' style='float: right;'>install</span></small></a>";
core.php CHANGED
@@ -47,7 +47,7 @@ class Meow_WPMC_Core {
47
  function display_metabox( $post ) {
48
  $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
49
  if ( !is_array( $posts_images_urls ) ) {
50
- echo "You need to run a scan first.";
51
  return;
52
  }
53
  $this->log( "Media Edit > Checking Media #{$post->ID}" );
@@ -583,10 +583,13 @@ class Meow_WPMC_Core {
583
  function log( $data, $force = false ) {
584
  if ( !get_option( 'wpmc_debuglogs', false ) && !$force )
585
  return;
586
- $fh = fopen( trailingslashit( dirname(__FILE__) ) . '/media-cleaner.log', 'a' );
 
 
587
  $date = date( "Y-m-d H:i:s" );
588
  fwrite( $fh, "$date: {$data}\n" );
589
  fclose( $fh );
 
590
  }
591
 
592
  function wp_ajax_wpmc_scan() {
@@ -740,6 +743,8 @@ class Meow_WPMC_Core {
740
 
741
  try {
742
  if ( !file_exists( $path_parts['dirname'] ) && !wp_mkdir_p( $path_parts['dirname'] ) ) {
 
 
743
  return false;
744
  }
745
  // Rename the file (move). 'is_dir' is just there for security (no way we should move a whole directory)
@@ -752,7 +757,7 @@ class Meow_WPMC_Core {
752
  $this->log( "The file $originalPath actually does not exist." );
753
  return true;
754
  }
755
- if ( !rename( $originalPath, $trashPath ) ) {
756
  return false;
757
  }
758
  }
@@ -843,6 +848,7 @@ class Meow_WPMC_Core {
843
  if ( !$this->wpmc_trash_file( $file ) ) {
844
  $this->log( "Could not trash $file." );
845
  error_log( "Media Cleaner: Could not trash $file." );
 
846
  }
847
 
848
  // If images, check the other files as well
47
  function display_metabox( $post ) {
48
  $posts_images_urls = get_transient( "wpmc_posts_images_urls" );
49
  if ( !is_array( $posts_images_urls ) ) {
50
+ echo "You need to run a Media Library scan first.";
51
  return;
52
  }
53
  $this->log( "Media Edit > Checking Media #{$post->ID}" );
583
  function log( $data, $force = false ) {
584
  if ( !get_option( 'wpmc_debuglogs', false ) && !$force )
585
  return;
586
+ $fh = @fopen( trailingslashit( dirname(__FILE__) ) . '/media-cleaner.log', 'a' );
587
+ if ( !$fh )
588
+ return false;
589
  $date = date( "Y-m-d H:i:s" );
590
  fwrite( $fh, "$date: {$data}\n" );
591
  fclose( $fh );
592
+ return true;
593
  }
594
 
595
  function wp_ajax_wpmc_scan() {
743
 
744
  try {
745
  if ( !file_exists( $path_parts['dirname'] ) && !wp_mkdir_p( $path_parts['dirname'] ) ) {
746
+ $this->log( "Could not create the trash directory for Media Cleaner." );
747
+ error_log( "Media Cleaner: Could not create the trash directory." );
748
  return false;
749
  }
750
  // Rename the file (move). 'is_dir' is just there for security (no way we should move a whole directory)
757
  $this->log( "The file $originalPath actually does not exist." );
758
  return true;
759
  }
760
+ if ( !@rename( $originalPath, $trashPath ) ) {
761
  return false;
762
  }
763
  }
848
  if ( !$this->wpmc_trash_file( $file ) ) {
849
  $this->log( "Could not trash $file." );
850
  error_log( "Media Cleaner: Could not trash $file." );
851
+ return false;
852
  }
853
 
854
  // If images, check the other files as well
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.4
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-cleaner
@@ -17,17 +17,17 @@ Originally developed for two of my websites:
17
  */
18
 
19
  if ( class_exists( 'Meow_WPMC_Core' ) ) {
20
- function mfrh_admin_notices() {
21
  echo '<div class="error"><p>Thanks for installing the Pro version of Media Cleaner :) However, the free version is still enabled. Please disable or uninstall it.</p></div>';
22
  }
23
- add_action( 'admin_notices', 'mfrh_admin_notices' );
24
  return;
25
  }
26
 
27
  if ( is_admin() ) {
28
 
29
  global $wpmc_version;
30
- $wpmc_version = '4.5.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.5.6
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-cleaner
17
  */
18
 
19
  if ( class_exists( 'Meow_WPMC_Core' ) ) {
20
+ function wpmc_pro_admin_notices() {
21
  echo '<div class="error"><p>Thanks for installing the Pro version of Media Cleaner :) However, the free version is still enabled. Please disable or uninstall it.</p></div>';
22
  }
23
+ add_action( 'admin_notices', 'wpmc_pro_admin_notices' );
24
  return;
25
  }
26
 
27
  if ( is_admin() ) {
28
 
29
  global $wpmc_version;
30
+ $wpmc_version = '4.5.6';
31
 
32
  // Admin
33
  require( 'wpmc_admin.php' );
readme.txt CHANGED
@@ -2,8 +2,8 @@
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
 
@@ -50,6 +50,9 @@ It re-creates the Media Cleaner table in the database. You will need to re-run t
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.
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.4
6
+ Stable tag: 4.5.6
7
 
8
  Clean your WordPress (broken media, unused media, files). It has its own trash and recovery features. Please read the description.
9
 
50
 
51
  == Changelog ==
52
 
53
+ = 4.5.6 =
54
+ * Update: Improve the code.
55
+
56
  = 4.5.4 =
57
  * Update: Streamlined the plugin, tutorial has also been rewritten.
58
  * Update: Simplified the Settings. Removed the Gallery option, as it is part of the Posts or Post Meta.
wpmc_admin.php CHANGED
@@ -4,6 +4,8 @@ include "common/admin.php";
4
 
5
  class Meow_WPMC_Admin extends MeowApps_Admin {
6
 
 
 
7
  public function __construct( $prefix, $mainfile, $domain ) {
8
  parent::__construct( $prefix, $mainfile, $domain );
9
  add_action( 'admin_menu', array( $this, 'app_menu' ) );
@@ -268,14 +270,20 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
268
  // }
269
 
270
  function admin_debuglogs_callback( $args ) {
 
271
  $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
272
  if ( $clearlogs && file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
273
- file_put_contents( plugin_dir_path( __FILE__ ) . '/media-cleaner.log', '' );
274
  }
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
  }
4
 
5
  class Meow_WPMC_Admin extends MeowApps_Admin {
6
 
7
+ public $core;
8
+
9
  public function __construct( $prefix, $mainfile, $domain ) {
10
  parent::__construct( $prefix, $mainfile, $domain );
11
  add_action( 'admin_menu', array( $this, 'app_menu' ) );
270
  // }
271
 
272
  function admin_debuglogs_callback( $args ) {
273
+ $debuglogs = get_option( 'wpmc_debuglogs' );
274
  $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
275
  if ( $clearlogs && file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
276
+ unlink( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' );
277
  }
278
  $html = '<input type="checkbox" id="wpmc_debuglogs" name="wpmc_debuglogs" value="1" ' .
279
+ checked( 1, $debuglogs, false ) . '/>';
280
  $html .= '<label for="wpmc_debuglogs"> ' . $args[0] . '</label><br>';
281
  $html .= '<small>' . __( 'Creates an internal log file, for debugging purposes.', 'media-cleaner' );
282
+ if ( $debuglogs && !file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
283
+ if ( !$this->core->log( "Testing the logging feature. It works!" ) ) {
284
+ $html .= sprintf( __( '<br /><b>Cannot create the logging file. Logging will not work. The plugin as a whole might not be able to work neither.</b>', 'media-cleaner' ), plugin_dir_url( __FILE__ ) );
285
+ }
286
+ }
287
  if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
288
  $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__ ) );
289
  }