Skip to content

Commit

Permalink
Merge pull request #1192 from wp-media/branch-3.1.4
Browse files Browse the repository at this point in the history
3.1.4
  • Loading branch information
remyperona authored Sep 17, 2018
2 parents 04c6085 + 3bfd667 commit 33578f0
Show file tree
Hide file tree
Showing 29 changed files with 2,170 additions and 757 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"a5hleyrich/wp-background-processing": "1.1 as 1.0",
"composer/installers": "~1.0",
"jamesryanbell/cloudflare": "^1.11",
"matthiasmullie/minify": "1.3.*"
"matthiasmullie/minify": "1.3.*",
"monolog/monolog": "^1.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
Expand Down
137 changes: 131 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions inc/admin/options.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use WP_Rocket\Logger;

defined( 'ABSPATH' ) || die( 'Cheatin&#8217; uh?' );

/**
Expand Down
4 changes: 4 additions & 0 deletions inc/admin/upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,9 @@ function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
if ( version_compare( $actual_version, '3.1.1', '<' ) ) {
rocket_generate_config_file();
}

if ( version_compare( $actual_version, '3.1.4', '<' ) ) {
rocket_generate_advanced_cache_file();
}
}
add_action( 'wp_rocket_upgrade', 'rocket_new_upgrade', 10, 2 );
184 changes: 184 additions & 0 deletions inc/classes/admin/class-logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php
namespace WP_Rocket\Admin;

use WP_Rocket\Logger;
use WP_Rocket\Event_Management\Subscriber_Interface;

defined( 'ABSPATH' ) || die( 'Cheatin&#8217; uh?' );

/**
* Class that handles few things about the logs.
*
* @since 3.1.4
* @author Grégory Viguier
*/
class Logs implements Subscriber_Interface {

/**
* Returns an array of events that this subscriber wants to listen to.
*
* @since 3.1.4
* @access public
* @author Grégory Viguier
*
* @return array
*/
public static function get_subscribed_events() {
return [
'pre_update_option_' . WP_ROCKET_SLUG => [ 'enable_debug', 10, 2 ],
'admin_post_rocket_download_debug_file' => 'download_debug_file',
'admin_post_rocket_delete_debug_file' => 'delete_debug_file',
];
}

/** ----------------------------------------------------------------------------------------- */
/** DEBUG ACTIVATION ======================================================================== */
/** ----------------------------------------------------------------------------------------- */

/**
* Enable or disable the debug mode when settings are saved.
*
* @since 3.1.4
* @access public
* @author Grégory Viguier
*
* @param array $newvalue An array of submitted options values.
* @param array $oldvalue An array of previous options values.
* @return array Updated submitted options values.
*/
public function enable_debug( $newvalue, $oldvalue ) {
if ( empty( $_POST ) ) {
return $newvalue;
}

if ( ! empty( $newvalue['debug_enabled'] ) ) {
Logger::enable_debug();
} else {
Logger::disable_debug();
}

unset( $newvalue['debug_enabled'] );

return $newvalue;
}

/** ----------------------------------------------------------------------------------------- */
/** ADMIN POST CALLBACKS ==================================================================== */
/** ----------------------------------------------------------------------------------------- */

/**
* Download the log file.
*
* @since 3.1.4
* @access public
* @author Grégory Viguier
*/
public function download_debug_file() {
if ( ! $this->verify_nonce( 'download_debug_file' ) ) {
wp_nonce_ays( '' );
}

if ( ! $this->current_user_can() ) {
$this->redirect();
}

$contents = Logger::get_log_file_contents();

if ( is_wp_error( $contents ) ) {
add_settings_error( 'general', $contents->get_error_code(), $contents->get_error_message(), 'error' );
set_transient( 'settings_errors', get_settings_errors(), 30 );

$this->redirect( add_query_arg( 'settings-updated', 1, wp_get_referer() ) );
}

$file_name = Logger::get_log_file_path();
$file_name = basename( $file_name, '.log' ) . Logger::get_log_file_extension();

nocache_headers();
@header( 'Content-Type: text/x-log' );
@header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
@header( 'Content-Transfer-Encoding: binary' );
@header( 'Content-Length: ' . strlen( $contents ) );
@header( 'Connection: close' );
echo $contents;
exit();
}

/**
* Delete the log file.
*
* @since 3.1.4
* @access public
* @author Grégory Viguier
*/
public function delete_debug_file() {
if ( ! $this->verify_nonce( 'delete_debug_file' ) ) {
wp_nonce_ays( '' );
}

if ( ! $this->current_user_can() ) {
$this->redirect();
}

if ( ! Logger::delete_log_file() ) {
add_settings_error( 'general', 'debug_file_not_deleted', __( 'The debug file could not be deleted.', 'rocket' ), 'error' );
set_transient( 'settings_errors', get_settings_errors(), 30 );

$this->redirect( add_query_arg( 'settings-updated', 1, wp_get_referer() ) );
}

// Done.
$this->redirect();
}


/** ----------------------------------------------------------------------------------------- */
/** TOOLS =================================================================================== */
/** ----------------------------------------------------------------------------------------- */

/**
* Verify the nonce sent in $_GET['_wpnonce'].
*
* @since 3.1.4
* @access protected
* @author Grégory Viguier
*
* @param string $nonce_name The nonce name.
* @return bool
*/
protected function verify_nonce( $nonce_name ) {
return isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], $nonce_name );
}

/**
* Tell if the current user can operate.
*
* @since 3.1.4
* @access protected
* @author Grégory Viguier
*
* @return bool
*/
protected function current_user_can() {
/** This filter is documented in inc/admin-bar.php */
return current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) );
}

/**
* Redirect the user.
*
* @since 3.1.4
* @access protected
* @author Grégory Viguier
*
* @param string $redirect URL to redirect the user to.
*/
protected function redirect( $redirect = null ) {
if ( empty( $redirect ) ) {
$redirect = wp_get_referer();
}

wp_safe_redirect( esc_url_raw( $redirect ) );
die();
}
}
3 changes: 2 additions & 1 deletion inc/classes/admin/settings/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public function toggle_option() {
$whitelist = [
'do_beta' => 1,
'analytics_enabled' => 1,
'debug_enabled' => 1,
'varnish_auto_purge' => 1,
'do_cloudflare' => 1,
'cloudflare_devmode' => 1,
Expand Down Expand Up @@ -947,7 +948,7 @@ private function assets_section() {
'label' => __( 'Excluded JavaScript Files', 'rocket' ),
'description' => __( 'Specify URLs of JavaScript files to be excluded from minification and concatenation (one per line).', 'rocket' ),
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
'helper' => __( '<strong>Internal:</strong> The domain part of the URL will be stripped automatically. Use (.*).js wildcards to exclude all JS files located at a specific path.', 'rocket' ) . '<br>' .
'helper' => __( '<strong>Internal:</strong> The domain part of the URL will be stripped automatically. Use (.*).js wildcards to exclude all JS files located at a specific path.', 'rocket' ) . '<br>' .
sprintf( __( '<strong>3rd Party:</strong> Use URL full path, including domain name, to exclude external JS. %1$sMore info%2$s', 'rocket' ), '<a href="' . esc_url( $exclude_js_beacon['url'] ) . '" data-beacon-article="' . esc_attr( $exclude_js_beacon['id'] ) . '" rel="noopener noreferrer" target="_blank">', '</a>' ),
'container_class' => [
'wpr-field--children',
Expand Down
Loading

0 comments on commit 33578f0

Please sign in to comment.