', number_format_i18n( $elapsed, 1 ) );
// Store the updated list of attachment IDs back in the 'bulk_attachments' option.
if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
- global $eio_debug;
$debug_button = esc_html__( 'Show Debug Output', 'ewww-image-optimizer' );
$debug_id = uniqid();
- $output['results'] .= "
$eio_debug
";
+ $output['results'] .= "
" . EWWW\Base::$debug_data . '
';
}
if ( ! empty( $next_image->file ) ) {
$next_file = esc_html( $next_image->file );
diff --git a/classes/class-background-process-image.php b/classes/class-background-process-image.php
index 17a6e74..9197b61 100644
--- a/classes/class-background-process-image.php
+++ b/classes/class-background-process-image.php
@@ -1,6 +1,6 @@
get_option( $this->prefix . 'debug' )
+ ) {
+ self::$temp_debug = true;
+ }
$this->debug_message( '' . __METHOD__ . '()' );
$this->debug_message( "plugin (resource) content_url: $this->content_url" );
$this->debug_message( "plugin (resource) content_dir: $this->content_dir" );
@@ -271,23 +298,34 @@ public function set_content_dir( $sub_folder ) {
}
/**
- * Saves the in-memory debug log to a logfile in the plugin folder.
+ * Get the path to the current debug log, if one exists. Otherwise, generate a new filename.
*
- * @global string $eio_debug The in-memory debug log.
+ * @return string The full path to the debug log.
+ */
+ public function debug_log_path() {
+ $potential_logs = \scandir( $this->content_dir );
+ if ( $this->is_iterable( $potential_logs ) ) {
+ foreach ( $potential_logs as $potential_log ) {
+ if ( $this->str_ends_with( $potential_log, '.log' ) && false !== strpos( $potential_log, strtolower( __NAMESPACE__ ) . '-debug-' ) && is_file( $this->content_dir . $potential_log ) ) {
+ return $this->content_dir . $potential_log;
+ }
+ }
+ }
+ return $this->content_dir . strtolower( __NAMESPACE__ ) . '-debug-' . uniqid() . '.log';
+ }
+
+ /**
+ * Saves the in-memory debug log to a logfile in the plugin folder.
*/
public function debug_log() {
- global $eio_debug;
- global $ewwwio_temp_debug;
- global $easyio_temp_debug;
- $debug_log = $this->content_dir . 'debug.log';
+ $debug_log = $this->debug_log_path();
if ( ! \is_dir( $this->content_dir ) && \is_writable( WP_CONTENT_DIR ) ) {
\wp_mkdir_p( $this->content_dir );
}
- $debug_enabled = $this->get_option( $this->prefix . 'debug' );
if (
- ! empty( $eio_debug ) &&
- empty( $easyio_temp_debug ) &&
- $debug_enabled &&
+ ! empty( self::$debug_data ) &&
+ empty( self::$temp_debug ) &&
+ $this->get_option( $this->prefix . 'debug' ) &&
\is_dir( $this->content_dir ) &&
\is_writable( $this->content_dir )
) {
@@ -299,24 +337,22 @@ public function debug_log() {
} else {
if ( \filesize( $debug_log ) + 4000000 + \memory_get_usage( true ) > $memory_limit ) {
\unlink( $debug_log );
+ \clearstatcache();
+ $debug_log = $this->debug_log_path();
\touch( $debug_log );
}
}
- if ( \filesize( $debug_log ) + \strlen( $eio_debug ) + 4000000 + \memory_get_usage( true ) <= $memory_limit && \is_writable( $debug_log ) ) {
- $eio_debug = \str_replace( ' ', "\n", $eio_debug );
- \file_put_contents( $debug_log, $timestamp . $eio_debug, FILE_APPEND );
+ if ( \filesize( $debug_log ) + \strlen( self::$debug_data ) + 4000000 + \memory_get_usage( true ) <= $memory_limit && \is_writable( $debug_log ) ) {
+ self::$debug_data = \str_replace( ' ', "\n", self::$debug_data );
+ \file_put_contents( $debug_log, $timestamp . self::$debug_data, FILE_APPEND );
}
}
- $eio_debug = '';
+ self::$debug_data = '';
}
/**
* Adds information to the in-memory debug log.
*
- * @global string $eio_debug The in-memory debug log.
- * @global bool $easyio_temp_debug Indicator that we are temporarily debugging on the wp-admin.
- * @global bool $ewwwio_temp_debug Indicator that we are temporarily debugging on the wp-admin.
- *
* @param string $message Debug information to add to the log.
*/
public function debug_message( $message ) {
@@ -339,23 +375,29 @@ public function debug_message( $message ) {
\WP_CLI::debug( $message );
return;
}
- global $ewwwio_temp_debug;
- global $easyio_temp_debug;
- if ( $easyio_temp_debug || $ewwwio_temp_debug || $this->get_option( $this->prefix . 'debug' ) ) {
+ if ( self::$temp_debug || $this->get_option( $this->prefix . 'debug' ) ) {
$memory_limit = $this->memory_limit();
if ( \strlen( $message ) + 4000000 + \memory_get_usage( true ) <= $memory_limit ) {
- global $eio_debug;
- $message = \str_replace( "\n\n\n", ' ', $message );
- $message = \str_replace( "\n\n", ' ', $message );
- $message = \str_replace( "\n", ' ', $message );
- $eio_debug .= "$message ";
+ $message = \str_replace( "\n\n\n", ' ', $message );
+ $message = \str_replace( "\n\n", ' ', $message );
+ $message = \str_replace( "\n", ' ', $message );
+ self::$debug_data .= "$message ";
} else {
- global $eio_debug;
- $eio_debug = "not logging message, memory limit is $memory_limit";
+ self::$debug_data = "not logging message, memory limit is $memory_limit";
}
}
}
+ /**
+ * Clears temp debugging mode and flushes the debug data if needed.
+ */
+ public function temp_debug_end() {
+ if ( ! $this->get_option( $this->prefix . 'debug' ) ) {
+ self::$debug_data = '';
+ }
+ self::$temp_debug = false;
+ }
+
/**
* Escape any spaces in the filename.
*
diff --git a/classes/class-ewww-nextgen.php b/classes/class-ewww-nextgen.php
index 5261ac2..72cfd96 100644
--- a/classes/class-ewww-nextgen.php
+++ b/classes/class-ewww-nextgen.php
@@ -628,8 +628,6 @@ public function ewww_manage_images_row_actions( $actions ) {
/**
* Output the html for the bulk optimize page.
- *
- * @global string $eio_debug In-memory debug log.
*/
public function ewww_ngg_bulk_preview() {
if ( ! empty( $_REQUEST['doaction'] ) ) {
@@ -738,9 +736,8 @@ public function ewww_ngg_bulk_preview() {
}
echo '';
if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
- global $eio_debug;
echo '';
- echo '