', 'w3-total-cache' ), $dir );
+ $chmods .= sprintf(
+ // Translators: 1 opening HTML li tag followed by opening HTML strong tag, 2 directory name
+ // Translators: 3 closing HTML strong tag followed by closing HTML li tag.
+ __(
+ '%1$schmod 777 %2$s%3$s',
+ 'w3-total-cache'
+ ),
+ '
',
+ $dir,
+ '
'
+ );
}
} else {
- $chmods = sprintf( 'chmod 777 %s',
- ( file_exists( $path ) ? $path : dirname( $path ) ) );
+ $chmods = sprintf(
+ 'chmod 777 %s',
+ file_exists( $path ) ? $path : dirname( $path )
+ );
}
if ( Util_File::check_open_basedir( $path ) ) {
$error = sprintf(
- __( '%s could not be created, please run following command: %s',
- 'w3-total-cache' ),
- $path, $chmods );
+ // Translators: 1 opening HTML strong tag, 2 file path, 3 closing HTML strong tag
+ // Translators: 4 HTML line break, 5 chmod values.
+ __(
+ '%1$s%2$s%3$s could not be created, please run following command:%4$s%5$s',
+ 'w3-total-cache'
+ ),
+ '',
+ $path,
+ '',
+ ' ',
+ $chmods
+ );
} else {
$error = sprintf(
- __( '%s could not be created, open_basedir restriction in effect, please check your php.ini settings: open_basedir = "%s"',
- 'w3-total-cache' ),
- $path, ini_get( 'open_basedir' ) );
+ // Translators: 1 opening HTML strong tag, 2 file path, 3 closing HTML strong tag
+ // Translators: 4 HTML line break followed by opening HTML strong tag, 5 open basedir value.
+ __(
+ '%1$s%2$s%3$s could not be created, %1$sopen_basedir%3$s restriction in effect, please check your php.ini settings:%4$sopen_basedir = "%5$s"%3$s',
+ 'w3-total-cache'
+ ),
+ '',
+ $path,
+ '',
+ ' ',
+ ini_get( 'open_basedir' )
+ );
}
throw new \Exception( $error );
@@ -93,153 +155,154 @@ static public function throw_on_write_error( $path, $chmod_dirs = array() ) {
/**
* Creates maintenance mode file
*
- * @param unknown $time
+ * @param unknown $time Time.
+ *
+ * @return void
*/
- static public function enable_maintenance_mode( $time = null ) {
- if ( is_null( $time ) )
+ public static function enable_maintenance_mode( $time = null ) {
+ if ( is_null( $time ) ) {
$time = 'time()';
+ }
+
Util_WpFile::write_to_file( Util_Environment::site_path() . '/.maintenance', "" );
}
/**
* Deletes maintenance mode file
+ *
+ * @return void
*/
- static public function disable_maintenance_mode() {
+ public static function disable_maintenance_mode() {
Util_WpFile::delete_file( Util_Environment::site_path() . '/.maintenance' );
}
/**
* Used to display Util_Environment_Exceptions in UI
*
- * @param Util_Environment_Exceptions $exs
+ * @param Util_Environment_Exceptions $exs Environment exceptions.
+ *
* @return array(before_errors = [], required_changes =>, later_errors => [])
*/
- static public function parse_environment_exceptions( $exs ) {
+ public static function parse_environment_exceptions( $exs ) {
$exceptions = $exs->exceptions();
- $commands = '';
- $required_changes = '';
- $before_errors = array();
- $later_errors = array();
+ $commands = '';
+ $required_changes = '';
+ $before_errors = array();
+ $later_errors = array();
$operation_error_already_shown = false;
foreach ( $exceptions as $ex ) {
if ( $ex instanceof Util_WpFile_FilesystemOperationException ) {
- if ( !$operation_error_already_shown ) {
+ if ( ! $operation_error_already_shown ) {
$m = $ex->getMessage();
if ( strlen( $m ) > 0 ) {
$before_errors[] = $m;
- // if multiple operations failed when
- // they tried to fix environment - show only first
- // otherwise can duplication information about
- // absense of permissions
+ // if multiple operations failed when they tried to fix environment - show only first
+ // otherwise can duplication information about absense of permissions.
$operation_error_already_shown = true;
}
if ( $ex instanceof Util_WpFile_FilesystemWriteException ) {
$required_changes .= sprintf(
- __( 'Create the %s file and paste the following text into it: ',
- 'w3-total-cache' ),
- $ex->filename(), esc_textarea( $ex->file_contents() ) );
- } else if ( $ex instanceof Util_WpFile_FilesystemModifyException ) {
- $modification_content = $ex->file_contents();
- if ( strlen( $modification_content ) > 0 )
- $modification_content =
- '';
- $required_changes .=
- $ex->modification_description() .
- $modification_content .
- ' ';
- } else if ( $ex instanceof Util_WpFile_FilesystemCopyException ) {
- $commands .= 'cp ' . $ex->source_filename() . ' ' .
- $ex->destination_filename() . ' ';
- } else if ( $ex instanceof Util_WpFile_FilesystemMkdirException ) {
- $commands .= 'mkdir ' . $ex->folder() . ' ';
- $commands .= 'chmod 777 ' . $ex->folder() . ' ';
- } else if ( $ex instanceof Util_WpFile_FilesystemRmException ) {
- $commands .= 'rm ' . $ex->filename() . ' ';
- } else if ( $ex instanceof Util_WpFile_FilesystemRmdirException ) {
- $commands .= 'rm -rf ' . $ex->folder() . ' ';
- } else if ( $ex instanceof Util_WpFile_FilesystemChmodException ) {
- $commands .= 'chmod 777 ' . $ex->filename() . ' ';
+ // Translators: 1 opening HTML strong tag, 2 file path, 3 closing HTML strong tag
+ // Translators: 4 opening HTML textarea tag, 5 textarea content, 6 closing HTML textarea tag followed by line break.
+ __(
+ 'Create the %1$s%2$s%3$s file and paste the following text into it: %4$s%5$s%6$s',
+ 'w3-total-cache'
+ ),
+ '',
+ $ex->filename(),
+ '',
+ ' '
+ );
+ } elseif ( $ex instanceof Util_WpFile_FilesystemModifyException ) {
+ $modification_content = $ex->file_contents();
+ if ( strlen( $modification_content ) > 0 ) {
+ $modification_content = '';
}
- }
- } else if ( $ex instanceof Util_Environment_Exception ) {
- $t = $ex->technical_message();
- if ( strlen( $t ) > 0 ) {
- $t = ' ' .
- '' .
- __( 'Technical info', 'w3-total-cache' ).'' .
- '
',
- __( 'W3 Total Cache Error: Files and directories could not be automatically deleted.' , 'w3-total-cache' ),
- __( 'Please execute commands manually' , 'w3-total-cache' ),
- __( 'or use FTP form to allow W3 Total Cache make it automatically.' ,
- 'w3-total-cache' ),
+
+
%s
+
%s
+
+
+
%s
+
%s
+
+ ',
+ __( 'W3 Total Cache Error: Files and directories could not be automatically deleted.', 'w3-total-cache' ),
+ __( 'Please execute commands manually', 'w3-total-cache' ),
+ __( 'or use FTP form to allow W3 Total Cache make it automatically.', 'w3-total-cache' ),
Util_Ui::button(
__( 'View required changes', 'w3-total-cache' ),
'',
@@ -250,13 +313,12 @@ static public function deactivate_plugin() {
'',
'w3tc-show-ftp-form'
)
- ) . '
' . $r['required_changes'] . '
' .
- '
' .
- $ftp_form . '
';
+ ) . '
' . $r['required_changes'] . '
' .
+ '
' . $ftp_form . '
';
$errors[] = $error;
}
+
return $errors;
}
}
diff --git a/Util_Admin.php b/Util_Admin.php
index eb349c3ea..8ec5a187e 100644
--- a/Util_Admin.php
+++ b/Util_Admin.php
@@ -9,6 +9,9 @@
/**
* Class: Util_Admin
+ *
+ * phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
*/
class Util_Admin {
/**
@@ -149,7 +152,7 @@ public static function single_system_item( $a ) {
$first_key = array_keys( $a );
$first_key = $first_key[0];
- $pos = strpos( $a[ $first_key ], ' ' );
+ $pos = strpos( $a[ $first_key ], ' ' );
if ( false === $pos ) {
return true;
@@ -178,15 +181,15 @@ public static function single_system_item( $a ) {
public static function config_save( $current_config, $new_config ) {
$master_config = ( $new_config->is_master() ? $new_config : Dispatcher::config_master() );
- if ( $master_config->get_integer( 'common.instance_id', 0 ) == 0 ) {
- $master_config->set( 'common.instance_id', mt_rand() );
+ if ( $master_config->get_integer( 'common.instance_id', 0 ) === 0 ) {
+ $master_config->set( 'common.instance_id', wp_rand() );
if ( ! $new_config->is_master() ) {
$master_config->save();
}
}
- $old_config = new Config();
+ $old_config = new Config();
$browsercache_dependencies = array();
if ( $new_config->get_boolean( 'browsercache.enabled' ) ) {
@@ -253,7 +256,7 @@ public static function config_save( $current_config, $new_config ) {
$new_bc_dependencies_values[] = $new_config->get( $key );
}
- if ( serialize( $old_bc_dependencies_values ) != serialize( $new_bc_dependencies_values ) ) {
+ if ( serialize( $old_bc_dependencies_values ) !== serialize( $new_bc_dependencies_values ) ) {
$state_note = Dispatcher::config_state_note();
$state_note->set( 'common.show_note.flush_statics_needed', true );
}
@@ -367,7 +370,7 @@ public static function config_save( $current_config, $new_config ) {
'cdn.azure.cname',
'cdn.azure.ssl',
'cdn.azuremi.cname',
- 'cdn.azuremi.ssl',
+ 'cdn.azuremi.ssl',
'cdn.mirror.domain',
'cdn.mirror.ssl',
'cdn.cotendo.domain',
@@ -413,7 +416,7 @@ public static function config_save( $current_config, $new_config ) {
$new_pgcache_dependencies_values[] = $new_config->get( $pgcache_dependency );
}
- if ( serialize( $old_pgcache_dependencies_values ) != serialize( $new_pgcache_dependencies_values ) ) {
+ if ( serialize( $old_pgcache_dependencies_values ) !== serialize( $new_pgcache_dependencies_values ) ) {
$state_note = Dispatcher::config_state_note();
$state_note->set( 'common.show_note.flush_posts_needed', true );
}
@@ -510,7 +513,7 @@ public static function config_save( $current_config, $new_config ) {
$new_minify_dependencies_values[] = $new_config->get( $minify_dependency );
}
- if ( serialize( $old_minify_dependencies_values ) != serialize( $new_minify_dependencies_values ) ) {
+ if ( serialize( $old_minify_dependencies_values ) !== serialize( $new_minify_dependencies_values ) ) {
$state_note = Dispatcher::config_state_note();
$state_note->set( 'minify.show_note.need_flush', true );
}
@@ -589,7 +592,7 @@ public static function config_save( $current_config, $new_config ) {
$new_objectcache_dependencies_values[] = $new_config->get( $objectcache_dependency );
}
- if ( serialize( $old_objectcache_dependencies_values ) != serialize( $new_objectcache_dependencies_values ) ) {
+ if ( serialize( $old_objectcache_dependencies_values ) !== serialize( $new_objectcache_dependencies_values ) ) {
$state_note = Dispatcher::config_state_note();
$state_note->set( 'objectcache.show_note.flush_needed', true );
}
@@ -626,31 +629,28 @@ public static function config_save( $current_config, $new_config ) {
/**
* Empty caches on engine change or cache enable/disable
*/
- if ( $old_config->get_string( 'pgcache.engine' ) !=
- $new_config->get_string( 'pgcache.engine' ) ||
- $old_config->get_string( 'pgcache.enabled' ) !=
- $new_config->get_string( 'pgcache.enabled' ) ) {
+ if ( $old_config->get_string( 'pgcache.engine' ) !== $new_config->get_string( 'pgcache.engine' ) || $old_config->get_string( 'pgcache.enabled' ) !== $new_config->get_string( 'pgcache.enabled' ) ) {
$pgcacheflush = Dispatcher::component( 'PgCache_Flush' );
- $v = $pgcacheflush->flush();
+ $v = $pgcacheflush->flush();
}
- if ( $old_config->get_string( 'dbcache.engine' ) != $new_config->get_string( 'dbcache.engine' ) || $old_config->get_string( 'dbcache.enabled' ) != $new_config->get_string( 'dbcache.enabled' ) ) {
+ if ( $old_config->get_string( 'dbcache.engine' ) !== $new_config->get_string( 'dbcache.engine' ) || $old_config->get_string( 'dbcache.enabled' ) !== $new_config->get_string( 'dbcache.enabled' ) ) {
w3tc_dbcache_flush();
}
- if ( $old_config->get_string( 'objectcache.engine' ) != $new_config->get_string( 'objectcache.engine' ) || $old_config->getf_boolean( 'objectcache.enabled' ) !== $new_config->getf_boolean( 'objectcache.enabled' ) ) {
+ if ( $old_config->get_string( 'objectcache.engine' ) !== $new_config->get_string( 'objectcache.engine' ) || $old_config->getf_boolean( 'objectcache.enabled' ) !== $new_config->getf_boolean( 'objectcache.enabled' ) ) {
w3tc_objectcache_flush();
}
- if ( $old_config->get_string( 'minify.engine' ) != $new_config->get_string( 'minify.engine' ) || $old_config->get_string( 'minify.enabled' ) != $new_config->get_string( 'minify.enabled' ) ) {
+ if ( $old_config->get_string( 'minify.engine' ) !== $new_config->get_string( 'minify.engine' ) || $old_config->get_string( 'minify.enabled' ) !== $new_config->get_string( 'minify.enabled' ) ) {
w3tc_minify_flush();
}
/**
* Update CloudFront CNAMEs
*/
- if ( $new_config->get_boolean( 'cdn.enabled' ) && in_array( $new_config->get_string( 'cdn.engine' ), array( 'cf', 'cf2' ) ) ) {
- if ( $new_config->get_string( 'cdn.engine' ) == 'cf' ) {
+ if ( $new_config->get_boolean( 'cdn.enabled' ) && in_array( $new_config->get_string( 'cdn.engine' ), array( 'cf', 'cf2' ), true ) ) {
+ if ( 'cf' === $new_config->get_string( 'cdn.engine' ) ) {
$old_cnames = $old_config->get_array( 'cdn.cf.cname' );
$new_cnames = $new_config->get_array( 'cdn.cf.cname' );
} else {
@@ -673,7 +673,7 @@ public static function config_save( $current_config, $new_config ) {
/**
* Auto upload browsercache files to CDN
*/
- if ( $new_config->get_boolean( 'cdn.enabled' ) && $new_config->get_string( 'cdn.engine' ) == 'ftp' ) {
+ if ( $new_config->get_boolean( 'cdn.enabled' ) && 'ftp' === $new_config->get_string( 'cdn.engine' ) ) {
self::cdn_delete_browsercache( $current_config );
self::cdn_upload_browsercache( $current_config );
}
@@ -692,11 +692,11 @@ public static function config_save( $current_config, $new_config ) {
*/
public static function cdn_upload_minify() {
$w3_plugin_cdn = Dispatcher::component( 'Cdn_Plugin' );
- $common = Dispatcher::component( 'Cdn_Core' );
+ $common = Dispatcher::component( 'Cdn_Core' );
$files = $w3_plugin_cdn->get_files_minify();
- $upload = array();
+ $upload = array();
$results = array();
foreach ( $files as $file ) {
@@ -722,20 +722,20 @@ public static function cdn_upload_browsercache( $config ) {
Dispatcher::component( 'Cdn_Core_Admin' );
- $ce = Dispatcher::component( 'Cdn_Environment' );
+ $ce = Dispatcher::component( 'Cdn_Environment' );
$rules = $ce->rules_generate_for_ftp( $config );
if ( $config->get_boolean( 'browsercache.enabled' ) ) {
- $be = Dispatcher::component( 'BrowserCache_Environment' );
+ $be = Dispatcher::component( 'BrowserCache_Environment' );
$rules .= $be->rules_cache_generate_for_ftp( $config );
}
$cdn_path = Util_Rule::get_cdn_rules_path();
$tmp_path = W3TC_CACHE_TMP_DIR . '/' . $cdn_path;
- if ( @file_put_contents( $tmp_path, $rules ) ) {
+ if ( @file_put_contents( $tmp_path, $rules ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
$results = array();
- $upload = array( $common->build_file_descriptor( $tmp_path, $cdn_path ) );
+ $upload = array( $common->build_file_descriptor( $tmp_path, $cdn_path ) );
$common->upload( $upload, true, $results );
}
@@ -767,8 +767,8 @@ public static function cdn_delete_browsercache() {
* @return string
*/
public static function get_cookie_domain() {
- $site_url = get_option( 'siteurl' );
- $parse_url = @parse_url( $site_url );
+ $site_url = get_option( 'siteurl' );
+ $parse_url = @wp_parse_url( $site_url );
if ( $parse_url && ! empty( $parse_url['host'] ) ) {
return $parse_url['host'];
diff --git a/Util_AttachToActions.php b/Util_AttachToActions.php
index 4e5352310..0e8a95a07 100644
--- a/Util_AttachToActions.php
+++ b/Util_AttachToActions.php
@@ -8,8 +8,9 @@
namespace W3TC;
/**
- * Attaches to wp actions related to content change, which should fire
- * flushes of html content
+ * Class Util_AttachToActions
+ *
+ * Attaches to wp actions related to content change, which should fire flushes of html content
*/
class Util_AttachToActions {
/**
diff --git a/Util_Bus.php b/Util_Bus.php
index 0aa2dfabe..2eb08fa57 100644
--- a/Util_Bus.php
+++ b/Util_Bus.php
@@ -1,27 +1,46 @@
1000 ) {
$content = substr( $content, 0, 1000 );
}
@@ -37,38 +54,44 @@ static private function _is_html_prepare( $content ) {
}
$content = ltrim( $content, "\x00\x09\x0A\x0D\x20\xBB\xBF\xEF" );
+
return $content;
}
/**
* If content can handle HTML comments, can disable printout per request using filter 'w3tc_can_print_comment'
*
- * @param unknown $buffer
+ * @param unknown $buffer Buffer.
+ *
* @return bool
*/
- static public function can_print_comment( $buffer ) {
- if ( function_exists( 'apply_filters' ) )
- return apply_filters( 'w3tc_can_print_comment', Util_Content::is_html_xml( $buffer ) && !defined( 'DOING_AJAX' ) );
- return Util_Content::is_html_xml( $buffer ) && !defined( 'DOING_AJAX' );
+ public static function can_print_comment( $buffer ) {
+ if ( function_exists( 'apply_filters' ) ) {
+ return apply_filters( 'w3tc_can_print_comment', self::is_html_xml( $buffer ) && ! defined( 'DOING_AJAX' ) );
+ }
+
+ return self::is_html_xml( $buffer ) && ! defined( 'DOING_AJAX' );
}
/**
* Returns GMT date
*
- * @param integer $time
+ * @param integer $time Time.
+ *
* @return string
*/
- static public function http_date( $time ) {
+ public static function http_date( $time ) {
return gmdate( 'D, d M Y H:i:s \G\M\T', $time );
}
/**
* Escapes HTML comment
*
- * @param string $comment
+ * @param string $comment Comment.
+ *
* @return mixed
*/
- static public function escape_comment( $comment ) {
+ public static function escape_comment( $comment ) {
while ( strstr( $comment, '--' ) !== false ) {
$comment = str_replace( '--', '- -', $comment );
}
@@ -76,18 +99,16 @@ static public function escape_comment( $comment ) {
return $comment;
}
-
-
/**
* Deprecated. Added to prevent loading-order errors during upgrades
* from older w3tc plugin versions
- **/
- static public function is_database_error() {
+ *
+ * @return bool
+ */
+ public static function is_database_error() {
return false;
}
-
-
/**
* Converts
* 127.0.0.1:1234 to ( '123.0.0.1', 1234 )
@@ -96,15 +117,21 @@ static public function is_database_error() {
*
* Doesnt fit to that class perfectly but selected due to common usage
* of loaded classes
+ *
+ * @param string $server Server.
+ * @param int $port_default Port default.
+ *
+ * @return array
*/
- static public function endpoint_to_host_port( $server, $port_default = 0 ) {
+ public static function endpoint_to_host_port( $server, $port_default = 0 ) {
$p = strrpos( $server, ':' );
- if ( substr( $server, 0, 5 ) == 'unix:' || $p === false ) {
+ if ( 'unix:' === substr( $server, 0, 5 ) || false === $p ) {
return array( trim( $server ), $port_default );
}
return array(
trim( substr( $server, 0, $p ) ),
- (int)substr( $server, $p + 1 ) );
+ (int) substr( $server, $p + 1 ),
+ );
}
}
diff --git a/Util_Debug.php b/Util_Debug.php
index a9790d4d8..526933351 100644
--- a/Util_Debug.php
+++ b/Util_Debug.php
@@ -1,16 +1,27 @@
', '..' );
+ $filename = self::log_filename( $module );
-
- static public function log( $module, $message ) {
- $message = strtr( $message, '<>', '..' );
- $filename = Util_Debug::log_filename( $module );
-
- return @file_put_contents( $filename, '[' . date( 'r' ) . '] ' .
- $message . "\n", FILE_APPEND );
+ return @file_put_contents( $filename, '[' . gmdate( 'r' ) . '] ' . $message . "\n", FILE_APPEND ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
}
-
-
/**
* Log cache purge event
+ *
+ * @param unknown $module Module.
+ * @param string $message Message.
+ * @param array $parameters Parameters.
+ * @param array $explicit_postfix Explicit postfix.
+ *
+ * @return bool
*/
- static public function log_purge( $module, $message, $parameters = null,
- $explicit_postfix = null ) {
- $backtrace = debug_backtrace( 0 );
+ public static function log_purge( $module, $message, $parameters = null, $explicit_postfix = null ) {
+ $backtrace = debug_backtrace( 0 ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
+ $backtrace_count = count( $backtrace );
$backtrace_lines = array();
- $pos = 0;
- for ( $n = 2; $n < count( $backtrace ); $n++ ) {
- if ( !Util_Debug::log_purge_should_print_item( $backtrace, $n ) ) {
+ $pos = 0;
+
+ for ( $n = 2; $n < $backtrace_count; $n++ ) {
+ if ( ! self::log_purge_should_print_item( $backtrace, $n ) ) {
continue;
}
- $i = $backtrace[$n];
+ $i = $backtrace[ $n ];
$filename = isset( $i['file'] ) ? $i['file'] : '';
$filename = str_replace( ABSPATH, '', $filename );
$line = isset( $i['line'] ) ? $i['line'] : '';
- $method = ( !empty( $i['class'] ) ? $i['class'] . '--' : '' ) .
- $i['function'];
- $args = ' ' . Util_Debug::encode_params( $i['args'] );
- $backtrace_lines[] = "\t#" . ( $pos ) . ' ' .
- $filename . '(' . $line . '): ' . $method . $args;
+ $method = ( ! empty( $i['class'] ) ? $i['class'] . '--' : '' ) . $i['function'];
+ $args = ' ' . self::encode_params( $i['args'] );
+ $backtrace_lines[] = "\t#" . ( $pos ) . ' ' . $filename . '(' . $line . '): ' . $method . $args;
$pos++;
}
$message = $message;
- if ( !is_null( $parameters ) ) {
- $message .= Util_Debug::encode_params( $parameters );
+ if ( ! is_null( $parameters ) ) {
+ $message .= self::encode_params( $parameters );
}
- $user = function_exists( 'wp_get_current_user' ) ? wp_get_current_user() : null;
+ $user = function_exists( 'wp_get_current_user' ) ? wp_get_current_user() : null;
$username = ( empty( $user ) ? 'anonymous' : $user->user_login );
$message .= "\n\tusername:$username";
@@ -105,36 +130,45 @@ static public function log_purge( $module, $message, $parameters = null,
$message .= "\n" . implode( "\n", $backtrace_lines );
- return Util_Debug::log( $module . '-purge', $message );
+ return self::log( $module . '-purge', $message );
}
-
-
- static private function log_purge_should_print_item( $backtrace, $n ) {
- if ( !empty( $backtrace[$n]['class']) &&
- $backtrace[$n]['class'] == 'W3TC\\CacheFlush_Locally' ) {
+ /**
+ * Log purge should print item
+ *
+ * @param array $backtrace Backtrace.
+ * @param string $n Key.
+ *
+ * @return bool
+ */
+ private static function log_purge_should_print_item( $backtrace, $n ) {
+ if ( ! empty( $backtrace[ $n ]['class'] ) && 'W3TC\\CacheFlush_Locally' === $backtrace[ $n ]['class'] ) {
return false;
}
- if ( !empty( $backtrace[$n]['class']) &&
- $backtrace[$n]['class'] == 'WP_Hook' &&
- !empty( $backtrace[$n + 1]['function'] ) ) {
- $f = $backtrace[$n + 1]['function'];
- if ( $f == 'do_action' || $f == 'apply_filters' ) {
+
+ if ( ! empty( $backtrace[ $n ]['class'] ) && 'WP_Hook' === $backtrace[ $n ]['class'] && ! empty( $backtrace[ $n + 1 ]['function'] ) ) {
+ $f = $backtrace[ $n + 1 ]['function'];
+ if ( 'do_action' === $f || 'apply_filters' === $f ) {
return false;
}
- return Util_Debug::log_purge_should_print_item( $backtrace, $n + 1 );
+ return self::log_purge_should_print_item( $backtrace, $n + 1 );
}
return true;
}
-
-
- static private function encode_params( $args ) {
+ /**
+ * Encode parameters
+ *
+ * @param array $args Arguments.
+ *
+ * @return string
+ */
+ private static function encode_params( $args ) {
$args_strings = array();
- if ( !is_array( $args ) ) {
- $s = (string)$args;
+ if ( ! is_array( $args ) ) {
+ $s = (string) $args;
if ( strlen( $s ) > 100 ) {
$s = substr( $s, 0, 98 ) . '..';
@@ -143,8 +177,7 @@ static private function encode_params( $args ) {
$args_strings[] = $s;
} else {
foreach ( $args as $arg ) {
- $s = json_encode( $arg,
- JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
+ $s = json_encode( $arg, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
if ( strlen( $s ) > 100 ) {
$s = substr( $s, 0, 98 ) . '..';
}
@@ -158,8 +191,14 @@ static private function encode_params( $args ) {
/**
* Clean debug output with label headers.
+ *
+ * @param string $label Label.
+ * @param array $data Data.
+ *
+ * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log
+ * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r
*/
- static public function debug( $label, $data ) {
+ public static function debug( $label, $data ) {
error_log(
"\n\n" . '===============Debug ' . $label . ' Start===============' . "\n" .
'Microtime: ' . microtime( true ) . "\n" .
diff --git a/Util_DebugPurgeLog_Reader.php b/Util_DebugPurgeLog_Reader.php
index a5569862e..78e01c34f 100644
--- a/Util_DebugPurgeLog_Reader.php
+++ b/Util_DebugPurgeLog_Reader.php
@@ -1,53 +1,91 @@
_read( $module );
}
-
-
+ /**
+ * Read log
+ *
+ * @param string $module Module.
+ *
+ * @throws \Exception Exception.
+ *
+ * @return array
+ */
private function _read( $module ) {
$log_filename = Util_Debug::log_filename( $module . '-purge' );
- if ( !file_exists( $log_filename) ) {
+ if ( ! file_exists( $log_filename ) ) {
return array();
}
$h = @fopen( $log_filename, 'rb' );
- if ( !$h ) {
+ if ( ! $h ) {
throw new \Exception( 'Failed to open log file' . $log_filename );
}
fseek( $h, 0, SEEK_END );
- $pos = ftell( $h );
+ $pos = ftell( $h );
$unparsed_head = '';
$more_log_needed = true;
while ( $pos >= 0 ) {
$to_read = 26;
- $pos -= $to_read;
+ $pos -= $to_read;
+
if ( $pos <= 0 ) {
$to_read = $to_read + $pos;
- $pos = 0;
+ $pos = 0;
}
+
fseek( $h, $pos );
$s = fread( $h, $to_read );
@@ -56,6 +94,7 @@ private function _read( $module ) {
if ( count( $this->lines ) > 100 ) {
break;
}
+
if ( $pos <= 0 ) {
$this->push_line( $unparsed_head );
break;
@@ -65,15 +104,20 @@ private function _read( $module ) {
return $this->lines;
}
-
-
+ /**
+ * Parse string
+ *
+ * @param string $s String.
+ *
+ * @return string
+ */
private function parse_string( $s ) {
$first_unparsed = strlen( $s );
- $pos = $first_unparsed;
+ $pos = $first_unparsed;
for ( ; $pos >= 0; $pos-- ) {
$c = substr( $s, $pos, 1 );
- if ( $c == "\r" || $c == "\n" ) {
+ if ( "\r" === $c || "\n" === $c ) {
$this->push_line( substr( $s, $pos + 1, $first_unparsed - $pos - 1 ) );
$first_unparsed = $pos;
}
@@ -82,29 +126,34 @@ private function parse_string( $s ) {
return substr( $s, 0, $first_unparsed );
}
-
-
+ /**
+ * Push line
+ *
+ * @param string $line Line.
+ *
+ * @return string
+ */
private function push_line( $line ) {
if ( empty( $line ) ) {
return;
}
- if ( substr( $line, 0, 1) == "\t" ) {
+ if ( "\t" === substr( $line, 0, 1 ) ) {
array_unshift( $this->current_item, $line );
return;
}
- // split secondary lines to urls and backtrace
- $postfix = array();
+ // split secondary lines to urls and backtrace.
+ $postfix = array();
$backtrace = array();
- $username = '';
+ $username = '';
foreach ( $this->current_item as $item ) {
$item = trim( $item );
if ( preg_match( '~^(#[^ ]+) ([^:]+): (.*)~', $item, $m ) ) {
$backtrace[] = array(
- 'number' => $m[1],
+ 'number' => $m[1],
'filename' => $m[2],
- 'function' => $m[3]
+ 'function' => $m[3],
);
} elseif ( preg_match( '~^username:(.*)~', $item, $m ) ) {
$username = $m[1];
@@ -116,11 +165,11 @@ private function push_line( $line ) {
$m = null;
if ( preg_match( '~\\[([^\\]]+)\\] (.*)~', $line, $m ) ) {
$this->lines[] = array(
- 'date' => $m[1],
- 'message' => $m[2],
- 'username' => $username,
- 'postfix' => $postfix,
- 'backtrace' => $backtrace
+ 'date' => $m[1],
+ 'message' => $m[2],
+ 'username' => $username,
+ 'postfix' => $postfix,
+ 'backtrace' => $backtrace,
);
}
diff --git a/Util_Environment.php b/Util_Environment.php
index 3ffd65290..e1b792de5 100644
--- a/Util_Environment.php
+++ b/Util_Environment.php
@@ -9,12 +9,15 @@
/**
* Class: Util_Environment
+ *
+ * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
*/
class Util_Environment {
/**
* Is using ,aster config.
*
* @var bool
+ *
* @static
*/
private static $is_using_master_config = null;
@@ -28,6 +31,7 @@ class Util_Environment {
* @param array $params Parameters.
* @param bool $skip_empty Skip empty.
* @param string $separator Separate.
+ *
* @return string
*/
public static function url_format( $url = '', $params = array(), $skip_empty = false, $separator = '&' ) {
@@ -50,7 +54,7 @@ public static function url_format( $url = '', $params = array(), $skip_empty = f
$url .= $parse_url['host'];
}
- if ( ! empty( $parse_url['port'] ) && $parse_url['port'] != 80 ) {
+ if ( ! empty( $parse_url['port'] ) && 80 !== $parse_url['port'] ) {
$url .= ':' . (int) $parse_url['port'];
}
}
@@ -94,6 +98,7 @@ public static function url_format( $url = '', $params = array(), $skip_empty = f
* @param array $params Parameters.
* @param bool $skip_empty Skip empty.
* @param string $separator Separator.
+ *
* @return string
*/
public static function url_query( $params = array(), $skip_empty = false, $separator = '&' ) {
@@ -134,6 +139,7 @@ public static function url_query( $params = array(), $skip_empty = false, $separ
*
* @param string $filename Filename.
* @param bool $use_site_url Use siteurl.
+ *
* @return string
*/
public static function filename_to_url( $filename, $use_site_url = false ) {
@@ -144,10 +150,10 @@ public static function filename_to_url( $filename, $use_site_url = false ) {
if ( substr( $filename, 0, strlen( WP_CONTENT_DIR ) ) === WP_CONTENT_DIR ) {
// This is the default location of the wp-content/cache directory.
$location = WP_CONTENT_DIR;
- } else if ( substr( $filename, 0, strlen( W3TC_CACHE_DIR ) ) === W3TC_CACHE_DIR ) {
+ } elseif ( substr( $filename, 0, strlen( W3TC_CACHE_DIR ) ) === W3TC_CACHE_DIR ) {
// This is needed in the event the cache directory is moved outside of wp-content and replace with a symbolic link.
$location = substr( W3TC_CACHE_DIR, 0, -strlen( '/cache' ) );
- } else if ( substr( $filename, 0, strlen( W3TC_CONFIG_DIR ) ) === W3TC_CONFIG_DIR ) {
+ } elseif ( substr( $filename, 0, strlen( W3TC_CONFIG_DIR ) ) === W3TC_CONFIG_DIR ) {
// This is needed in the event the cache directory is moved outside of wp-content and replace with a symbolic link.
$location = substr( W3TC_CONFIG_DIR, 0, -strlen( '/w3tc-config' ) );
} else {
@@ -156,7 +162,7 @@ public static function filename_to_url( $filename, $use_site_url = false ) {
$uri_from_location = substr( $filename, strlen( $location ) );
- if ( DIRECTORY_SEPARATOR != '/' ) {
+ if ( '/' !== DIRECTORY_SEPARATOR ) {
$uri_from_location = str_replace( DIRECTORY_SEPARATOR, '/', $uri_from_location );
}
@@ -171,15 +177,17 @@ public static function filename_to_url( $filename, $use_site_url = false ) {
*
* @static
*
+ * @param Config $config Config.
+ *
* @return bool
*/
public static function is_dbcluster( $config = null ) {
if ( is_null( $config ) ) {
- // fallback for compatibility with older wp-content/db.php
+ // fallback for compatibility with older wp-content/db.php.
$config = \W3TC\Dispatcher::config();
}
- if ( !self::is_w3tc_pro( $config ) ) {
+ if ( ! self::is_w3tc_pro( $config ) ) {
return false;
}
@@ -271,6 +279,7 @@ public static function w3tc_header() {
* @static
*
* @param string $url URL.
+ *
* @return bool
*/
public static function is_url( $url ) {
@@ -305,6 +314,8 @@ public static function is_https() {
/**
* Moves user to preview-mode or opposite.
*
+ * @param bool $is_enabled Is enabled.
+ *
* @static
*/
public static function set_preview( $is_enabled ) {
@@ -382,6 +393,7 @@ public static function is_iis() {
* @static
*
* @param string $url URL.
+ *
* @return string
*/
public static function url_to_host( $url ) {
@@ -402,7 +414,7 @@ public static function url_to_host( $url ) {
* @param string $url URL.
*/
public static function url_to_uri( $url ) {
- $uri = @parse_url( $url, PHP_URL_PATH );
+ $uri = @wp_parse_url( $url, PHP_URL_PATH );
// Convert FALSE and other return values to string.
if ( empty( $uri ) ) {
@@ -455,8 +467,9 @@ public static function wp_upload_dir() {
$blog_id = self::blog_id();
- if ( ! isset( $values_by_blog[ $blog_id ] ) )
+ if ( ! isset( $values_by_blog[ $blog_id ] ) ) {
$values_by_blog[ $blog_id ] = wp_upload_dir();
+ }
return $values_by_blog[ $blog_id ];
}
@@ -467,6 +480,7 @@ public static function wp_upload_dir() {
* @static
*
* @param string $section Section.
+ *
* @return string
*/
public static function cache_dir( $section ) {
@@ -480,6 +494,7 @@ public static function cache_dir( $section ) {
*
* @param string $section Section.
* @param int $blog_id Blog id.
+ *
* @return string
*/
public static function cache_blog_dir( $section, $blog_id = null ) {
@@ -514,7 +529,7 @@ public static function cache_blog_dir( $section, $blog_id = null ) {
public static function cache_blog_minify_dir() {
// when minify manual used with a shared config - shared
// minify urls has to be used too, since CDN upload is possible
- // only from network admin
+ // only from network admin.
if ( self::is_wpmu() && self::is_using_master_config() && ! Dispatcher::config()->get_boolean( 'minify.auto' ) ) {
$path = self::cache_blog_dir( 'minify', 0 );
} else {
@@ -530,6 +545,7 @@ public static function cache_blog_minify_dir() {
* @static
*
* @param string $url URL.
+ *
* @return string
*/
public static function get_url_regexp( $url ) {
@@ -547,6 +563,7 @@ public static function get_url_regexp( $url ) {
* @static
*
* @param string $url URL.
+ *
* @return string
*/
public static function url_to_maybe_https( $url ) {
@@ -564,7 +581,6 @@ public static function url_to_maybe_https( $url ) {
*
* @return string
*/
-
public static function home_domain_root_url() {
$home_url = get_home_url();
$parse_url = @parse_url( $home_url ); // phpcs:ignore
@@ -604,7 +620,7 @@ public static function home_domain_root_url_regexp() {
*/
public static function home_url_maybe_https() {
$home_url = get_home_url();
- $ssl = self::url_to_maybe_https( $home_url );
+ $ssl = self::url_to_maybe_https( $home_url );
return $ssl;
}
@@ -618,7 +634,7 @@ public static function home_url_maybe_https() {
*/
public static function home_url_regexp() {
$home_url = get_home_url();
- $regexp = self::get_url_regexp( $home_url );
+ $regexp = self::get_url_regexp( $home_url );
return $regexp;
}
@@ -652,13 +668,13 @@ public static function site_path() {
if ( false !== $pos ) {
$home_path = substr( $script_filename, 0, $pos );
$home_path = trailingslashit( $home_path );
- } else if ( defined( 'WP_CLI' ) ) {
+ } elseif ( defined( 'WP_CLI' ) ) {
$pos = strripos(
str_replace( '\\', '/', ABSPATH ),
trailingslashit( $wp_path_rel_to_home )
);
- if ( $pos !== false ) {
+ if ( false !== $pos ) {
$home_path = substr( ABSPATH, 0, $pos );
$home_path = trailingslashit( $home_path );
}
@@ -698,7 +714,7 @@ public static function document_root() {
$php_self = self::normalize_path(
htmlspecialchars( stripslashes( $_SERVER['PHP_SELF'] ) ) // phpcs:ignore
);
- if ( substr( $script_filename, -strlen( $php_self ) ) == $php_self ) {
+ if ( substr( $script_filename, -strlen( $php_self ) ) === $php_self ) {
$document_root = substr( $script_filename, 0, -strlen( $php_self ) );
$document_root = realpath( $document_root );
return $document_root;
@@ -814,7 +830,7 @@ public static function network_home_url_uri() {
* a non-relative URI even though scheme is set to relative.
*/
if ( self::is_url( $uri ) ) {
- $uri = parse_url( $uri, PHP_URL_PATH );
+ $uri = wp_parse_url( $uri, PHP_URL_PATH );
}
if ( empty( $uri ) ) {
@@ -858,7 +874,7 @@ public static function host() {
$pos = strpos( $host_port, ':' );
- if ( $pos === false ) {
+ if ( false === $pos ) {
return $host_port;
}
@@ -893,6 +909,7 @@ public static function wp_config_path() {
* @static
*
* @param string $path Path.
+ *
* @return mixed
*/
public static function parse_path( $path ) {
@@ -924,13 +941,14 @@ public static function parse_path( $path ) {
* @static
*
* @param string $file File path.
+ *
* @return string
*/
public static function normalize_file( $file ) {
if ( self::is_url( $file ) ) {
if ( strstr( $file, '?' ) === false ) {
$home_url_regexp = '~' . self::home_url_regexp() . '~i';
- $file = preg_replace( $home_url_regexp, '', $file );
+ $file = preg_replace( $home_url_regexp, '', $file );
}
}
@@ -950,14 +968,15 @@ public static function normalize_file( $file ) {
*
* @static
*
- * @param string $file
+ * @param string $file File.
+ *
* @return string
*/
public static function normalize_file_minify( $file ) {
if ( self::is_url( $file ) ) {
if ( strstr( $file, '?' ) === false ) {
$domain_url_regexp = '~' . self::home_domain_root_url_regexp() . '~i';
- $file = preg_replace( $domain_url_regexp, '', $file );
+ $file = preg_replace( $domain_url_regexp, '', $file );
}
}
@@ -976,13 +995,14 @@ public static function normalize_file_minify( $file ) {
*
* @static
*
- * @param string $file File path.
+ * @param string $url URL.
+ *
* @return string
*/
public static function url_to_docroot_filename( $url ) {
$data = array(
'home_url' => get_home_url(),
- 'url' => $url,
+ 'url' => $url,
);
$data = apply_filters( 'w3tc_url_to_docroot_filename', $data );
@@ -1003,15 +1023,14 @@ public static function url_to_docroot_filename( $url ) {
$path_relative_to_home = str_replace( $home_url, '', $normalized_url );
$home = set_url_scheme( get_option( 'home' ), 'http' );
$siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
- $home_path = rtrim( Util_Environment::site_path(), '/' );
+ $home_path = rtrim( self::site_path(), '/' );
// Adjust home_path if site is not is home.
if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
// $siteurl - $home/
$wp_path_rel_to_home = rtrim( str_ireplace( $home, '', $siteurl ), '/' );
- if ( substr( $home_path, -strlen( $wp_path_rel_to_home ) ) ==
- $wp_path_rel_to_home ) {
+ if ( substr( $home_path, -strlen( $wp_path_rel_to_home ) ) === $wp_path_rel_to_home ) {
$home_path = substr( $home_path, 0, -strlen( $wp_path_rel_to_home ) );
}
}
@@ -1024,7 +1043,7 @@ public static function url_to_docroot_filename( $url ) {
$docroot = self::document_root();
- if ( substr( $full_filename, 0, strlen( $docroot ) ) == $docroot ) {
+ if ( substr( $full_filename, 0, strlen( $docroot ) ) === $docroot ) {
$docroot_filename = substr( $full_filename, strlen( $docroot ) );
} else {
$docroot_filename = $path_relative_to_home;
@@ -1046,10 +1065,11 @@ public static function url_to_docroot_filename( $url ) {
* @static
*
* @param string $docroot_filename Document filename.
- * @return strin
+ *
+ * @return string
*/
public static function docroot_to_full_filename( $docroot_filename ) {
- return rtrim( Util_Environment::document_root(), DIRECTORY_SEPARATOR ) .
+ return rtrim( self::document_root(), DIRECTORY_SEPARATOR ) .
DIRECTORY_SEPARATOR . $docroot_filename;
}
@@ -1057,6 +1077,10 @@ public static function docroot_to_full_filename( $docroot_filename ) {
* Removes WP query string from URL.
*
* @static
+ *
+ * @param string $url URL.
+ *
+ * @return string
*/
public static function remove_query( $url ) {
$url = preg_replace( '~(\?|&|&|&)+ver=[a-z0-9-_\.]+~i', '', $url );
@@ -1070,11 +1094,12 @@ public static function remove_query( $url ) {
* @static
*
* @param string $url URL.
+ *
* @return string
*/
public static function remove_query_all( $url ) {
$pos = strpos( $url, '?' );
- if ( $pos === false ) {
+ if ( false === $pos ) {
return $url;
}
@@ -1087,6 +1112,7 @@ public static function remove_query_all( $url ) {
* @static
*
* @param string $path Path.
+ *
* @return string
*/
public static function normalize_path( $path ) {
@@ -1102,6 +1128,7 @@ public static function normalize_path( $path ) {
* @static
*
* @param string $path Path.
+ *
* @return string
*/
public static function realpath( $path ) {
@@ -1110,11 +1137,11 @@ public static function realpath( $path ) {
$absolutes = array();
foreach ( $parts as $part ) {
- if ( '.' == $part ) {
+ if ( '.' === $part ) {
continue;
}
- if ( '..' == $part ) {
+ if ( '..' === $part ) {
array_pop( $absolutes );
} else {
$absolutes[] = $part;
@@ -1130,17 +1157,18 @@ public static function realpath( $path ) {
* @static
*
* @param string $path Path.
+ *
* @return string
*/
public static function path_remove_dots( $path ) {
- $parts = explode( '/', $path );
+ $parts = explode( '/', $path );
$absolutes = array();
foreach ( $parts as $part ) {
- if ( '.' == $part ) {
+ if ( '.' === $part ) {
continue;
}
- if ( '..' == $part ) {
+ if ( '..' === $part ) {
array_pop( $absolutes );
} else {
$absolutes[] = $part;
@@ -1156,24 +1184,26 @@ public static function path_remove_dots( $path ) {
* @static
*
* @param string $relative_url Relative URL.
+ *
* @return string
*/
public static function url_relative_to_full( $relative_url ) {
$relative_url = self::path_remove_dots( $relative_url );
if ( version_compare( PHP_VERSION, '5.4.7' ) < 0 ) {
- if ( substr( $relative_url, 0, 2 ) === '//' ) {
+ if ( substr( $relative_url, 0, 2 ) === '//' ) {
$relative_url = ( self::is_https() ? 'https' : 'http' ) . ':' . $relative_url;
}
}
- $rel = parse_url( $relative_url );
- // it's full url already
- if ( isset( $rel['scheme'] ) || isset( $rel['host'] ) )
+ $rel = wp_parse_url( $relative_url );
+ // it's full url already.
+ if ( isset( $rel['scheme'] ) || isset( $rel['host'] ) ) {
return $relative_url;
+ }
- if ( !isset( $rel['host'] ) ) {
- $home_parsed = parse_url( get_home_url() );
+ if ( ! isset( $rel['host'] ) ) {
+ $home_parsed = wp_parse_url( get_home_url() );
$rel['host'] = $home_parsed['host'];
if ( isset( $home_parsed['port'] ) ) {
$rel['port'] = $home_parsed['port'];
@@ -1181,10 +1211,10 @@ public static function url_relative_to_full( $relative_url ) {
}
$scheme = isset( $rel['scheme'] ) ? $rel['scheme'] . '://' : '//';
- $host = isset( $rel['host'] ) ? $rel['host'] : '';
- $port = isset( $rel['port'] ) ? ':' . $rel['port'] : '';
- $path = isset( $rel['path'] ) ? $rel['path'] : '';
- $query = isset( $rel['query'] ) ? '?' . $rel['query'] : '';
+ $host = isset( $rel['host'] ) ? $rel['host'] : '';
+ $port = isset( $rel['port'] ) ? ':' . $rel['port'] : '';
+ $path = isset( $rel['path'] ) ? $rel['path'] : '';
+ $query = isset( $rel['query'] ) ? '?' . $rel['query'] : '';
return "$scheme$host$port$path$query";
}
@@ -1195,6 +1225,8 @@ public static function url_relative_to_full( $relative_url ) {
*
* @param string $url URL.
* @param array $params Parameters.
+ *
+ * @return void
*/
public static function redirect( $url = '', $params = array() ) {
$url = self::url_format( $url, $params );
@@ -1214,6 +1246,8 @@ public static function redirect( $url = '', $params = array() ) {
* @param string $url URL.
* @param array $params Parameters.
* @param bool $safe_redirect Safe redirect or not.
+ *
+ * @return void
*/
public static function safe_redirect_temp( $url = '', $params = array(), $safe_redirect = false ) {
$url = self::url_format( $url, $params );
@@ -1253,6 +1287,7 @@ public static function safe_redirect_temp( $url = '', $params = array(), $safe_r
* @static
*
* @param string $url URL.
+ *
* @return string
*/
public static function wp_safe_redirect_fallback( $url ) {
@@ -1314,6 +1349,7 @@ public static function instance_id() {
* @static
*
* @param Config $config Config.
+ *
* @return string
*/
public static function w3tc_edition( $config = null ) {
@@ -1334,17 +1370,10 @@ public static function w3tc_edition( $config = null ) {
* @static
*
* @param Config $config Config.
+ *
* @return bool
*/
public static function is_w3tc_pro( $config = null ) {
- if ( defined( 'W3TC_PRO' ) && W3TC_PRO ) {
- return true;
- }
-
- if ( defined( 'W3TC_ENTERPRISE' ) && W3TC_ENTERPRISE ) {
- return true;
- }
-
if ( is_object( $config ) ) {
$plugin_type = $config->get_string( 'plugin.type' );
@@ -1374,6 +1403,7 @@ public static function is_w3tc_pro_dev() {
*
* @param string $string String.
* @param string $delimiter Delimeter.
+ *
* @return string
*/
public static function preg_quote( $string, $delimiter = '~' ) {
@@ -1403,6 +1433,7 @@ public static function is_zlib_enabled() {
* @static
*
* @param mixed $var Value.
+ *
* @return mixed
*/
public static function stripslashes( $var ) {
@@ -1423,6 +1454,7 @@ public static function stripslashes( $var ) {
* @param object $post Post object.
* @param string $module Which cache module to check against (pgcache, varnish, dbcache or objectcache).
* @param Config $config Config.
+ *
* @return bool
*/
public static function is_flushable_post( $post, $module, $config ) {
@@ -1461,9 +1493,11 @@ public static function is_flushable_post( $post, $module, $config ) {
* Checks if post belongs to a custom post type.
*
* @since 2.1.7
+ *
* @static
*
* @param object $post Post object.
+ *
* @return bool
*/
public static function is_custom_post_type( $post ) {
@@ -1488,32 +1522,33 @@ public static function is_custom_post_type( $post ) {
* @static
*
* @param mixed $value Value.
+ *
* @return bool
*/
public static function to_boolean( $value ) {
if ( is_string( $value ) ) {
switch ( strtolower( $value ) ) {
- case '+':
- case '1':
- case 'y':
- case 'on':
- case 'yes':
- case 'true':
- case 'enabled':
- return true;
+ case '+':
+ case '1':
+ case 'y':
+ case 'on':
+ case 'yes':
+ case 'true':
+ case 'enabled':
+ return true;
- case '-':
- case '0':
- case 'n':
- case 'no':
- case 'off':
- case 'false':
- case 'disabled':
- return false;
+ case '-':
+ case '0':
+ case 'n':
+ case 'no':
+ case 'off':
+ case 'false':
+ case 'disabled':
+ return false;
}
}
- return (boolean) $value;
+ return (bool) $value;
}
/**
@@ -1539,13 +1574,18 @@ public static function get_server_version() {
* Checks if current request is REST REQUEST.
*
* @static
+ *
+ * @param string $url URL.
+ *
+ * @return string
*/
public static function is_rest_request( $url ) {
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST )
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return true;
+ }
// in case when called before constant is set
- // wp filters are not available in that case
+ // wp filters are not available in that case.
return preg_match( '~' . W3TC_WP_JSON_URI . '~', $url );
}
@@ -1553,6 +1593,8 @@ public static function is_rest_request( $url ) {
* Reset microcache.
*
* @static
+ *
+ * @return void
*/
public static function reset_microcache() {
global $w3_current_blog_id;
@@ -1619,10 +1661,12 @@ public static function textarea_to_array( $value ) {
* Returns true if any entries between the tewo arrays match string endings or in whole.
*
* @since 2.7.4
+ *
* @static
*
* @param array $array1 Array 1.
* @param array $array2 Array 2.
+ *
* @return bool
*/
public static function array_intersect_partial( array $array1, array $array2 ): bool {
@@ -1677,7 +1721,7 @@ public static function array_intersect_partial( array $array1, array $array2 ):
*
* @return int
*/
- public static function get_cron_schedule_time(int $cron_time = 0): int {
+ public static function get_cron_schedule_time( int $cron_time = 0 ): int {
// Get the current time in WordPress timezone.
$current_time_wp = new \DateTime( 'now', wp_timezone() );
@@ -1686,12 +1730,12 @@ public static function get_cron_schedule_time(int $cron_time = 0): int {
$minute = $cron_time % 60;
// Create a DateTime for today at the specified hour and minute in the user's timezone.
- $scheduled_time_user = new \DateTime( "today", wp_timezone() );
+ $scheduled_time_user = new \DateTime( 'today', wp_timezone() );
$scheduled_time_user->setTime( $hour, $minute );
// Convert the user's scheduled time to UTC for WordPress.
$scheduled_time_utc = clone $scheduled_time_user;
- $scheduled_time_utc->setTimezone( new \DateTimeZone('UTC') );
+ $scheduled_time_utc->setTimezone( new \DateTimeZone( 'UTC' ) );
// If the selected time has already passed today in UTC, schedule for tomorrow.
if ( $scheduled_time_utc <= $current_time_wp ) {
@@ -1713,6 +1757,7 @@ public static function get_cron_schedule_time(int $cron_time = 0): int {
* returned.
*
* @since 2.8.0
+ *
* @link https://github.com/wp-cli/cron-command/blob/v2.3.1/src/Cron_Command.php#L14-L55
*
* @return bool
@@ -1755,6 +1800,7 @@ public static function is_wpcron_working(): bool {
* request.
*
* @since 2.8.0
+ *
* @link https://github.com/wp-cli/cron-command/blob/v2.3.1/src/Cron_Command.php#L57-L91
*
* @global $wp_version WordPress version string.
diff --git a/Util_Environment_Exception.php b/Util_Environment_Exception.php
index ea2581329..c2b6c525e 100644
--- a/Util_Environment_Exception.php
+++ b/Util_Environment_Exception.php
@@ -1,14 +1,41 @@
technical_message = $technical_message;
}
+ /**
+ * Get technical message
+ *
+ * @return string
+ */
public function technical_message() {
return $this->technical_message;
}
diff --git a/Util_Environment_Exceptions.php b/Util_Environment_Exceptions.php
index ee1d8ebd4..d0095254c 100644
--- a/Util_Environment_Exceptions.php
+++ b/Util_Environment_Exceptions.php
@@ -1,31 +1,68 @@
exceptions = array();
}
+ /**
+ * Push
+ *
+ * @param object $ex Exception.
+ *
+ * @return void
+ */
public function push( $ex ) {
if ( $ex instanceof Util_Environment_Exceptions ) {
- foreach ( $ex->exceptions() as $ex2 )
+ foreach ( $ex->exceptions() as $ex2 ) {
$this->push( $ex2 );
+ }
} else {
- if ( $this->credentials_form == null &&
+ if (
+ null === $this->credentials_form &&
$ex instanceof Util_WpFile_FilesystemOperationException &&
- $ex->credentials_form() != null )
+ null !== $ex->credentials_form()
+ ) {
$this->credentials_form = $ex->credentials_form();
+ }
+
$this->exceptions[] = $ex;
}
}
/**
- *
+ * Get exceptions
*
* @return Exception[]
*/
@@ -33,10 +70,20 @@ public function exceptions() {
return $this->exceptions;
}
+ /**
+ * Get credentials form
+ *
+ * @return string
+ */
public function credentials_form() {
return $this->credentials_form;
}
+ /**
+ * Get combined message
+ *
+ * @return string
+ */
public function getCombinedMessage() {
$s = '';
foreach ( $this->exceptions as $m ) {
diff --git a/pub/js/setup-guide.js b/pub/js/setup-guide.js
index c3c3d8b47..5a0ecb31b 100644
--- a/pub/js/setup-guide.js
+++ b/pub/js/setup-guide.js
@@ -73,8 +73,6 @@ jQuery(function() {
if (window.w3tc_ga) {
w3tc_enable_ga = true;
- w3tc_ga( 'js', new Date() );
-
w3tc_ga( 'config', W3TC_SetupGuide.ga_profile, {
'user_properties': {
'plugin': 'w3-total-cache',
@@ -87,7 +85,8 @@ jQuery(function() {
'w3tc_install_version': W3TC_SetupGuide.install_version,
'w3tc_edition': W3TC_SetupGuide.w3tc_edition,
'w3tc_widgets': W3TC_SetupGuide.list_widgets,
- 'page': W3TC_SetupGuide.page
+ 'page': W3TC_SetupGuide.page,
+ 'w3tc_install_date': W3TC_SetupGuide.w3tc_install_date,
}
});
}