Skip to content

Commit

Permalink
Merge pull request #357 from wp-media/branch-2.9.7
Browse files Browse the repository at this point in the history
2.9.7
  • Loading branch information
JulioPotier authored Feb 27, 2017
2 parents 192661a + abbd78e commit 514d6a4
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 143 deletions.
122 changes: 60 additions & 62 deletions inc/admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function rocket_field( $args ) {
$readonly = isset( $args['readonly'] ) && $args['readonly'] ? ' readonly="readonly" disabled="disabled"' : '';
$cols = isset( $args['cols'] ) ? (int) $args['cols'] : 50;
$rows = isset( $args['rows'] ) ? (int) $args['rows'] : 5;

if( ! isset( $args['fieldset'] ) || 'start' == $args['fieldset'] ){
echo '<fieldset class="fieldname-'.sanitize_html_class( $args['name'] ).' fieldtype-'.sanitize_html_class( $args['type'] ).'">';
}
Expand All @@ -68,7 +68,7 @@ function rocket_field( $args ) {
if ( $value === false ) {
$value = $default;
}

$value = esc_attr( $value );
$number_options = $args['type']=='number' ? ' min="0" class="small-text"' : '';
$autocomplete = in_array( $args['name'], array( 'consumer_key', 'consumer_email' ) ) ? ' autocomplete="off"' : '';
Expand All @@ -83,19 +83,19 @@ function rocket_field( $args ) {

case 'cloudflare_api_key' :
$value = get_rocket_option( $args['name'] );

if ( 'cloudflare_api_key' == $args['name'] && defined( 'WP_ROCKET_CF_API_KEY' ) ) {
$value = WP_ROCKET_CF_API_KEY;
}
}

$value = esc_attr( $value );
$disabled = ( 'cloudflare_api_key' == $args['name'] && defined( 'WP_ROCKET_CF_API_KEY' ) ) ? ' disabled="disabled"' : $readonly;
$cf_valid_credentials = false;
if ( function_exists( 'rocket_cloudflare_valid_auth' ) ) {
$cf_valid_credentials = ( is_wp_error( rocket_cloudflare_valid_auth() ) ) ? false : true;
}
?>

<legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
<label>
<input<?php echo $disabled; ?> type="text" id="<?php echo $args['label_for']; ?>" name="wp_rocket_settings[<?php echo $args['name']; ?>]" value="<?php echo $value; ?>" <?php echo $placeholder; ?><?php echo $readonly; ?>/> <?php echo $label; ?>
Expand All @@ -116,7 +116,7 @@ function rocket_field( $args ) {

<?php
break;


case 'textarea' :

Expand All @@ -134,7 +134,7 @@ function rocket_field( $args ) {
<?php
break;

case 'checkbox' :
case 'checkbox' :
if ( isset( $args['label_screen'] ) ) { ?>
<legend class="screen-reader-text"><span><?php echo $args['label_screen']; ?></span></legend>
<?php } ?>
Expand Down Expand Up @@ -428,7 +428,7 @@ function rocket_button( $args ) {
echo '<button id="' . $id . '" class="' . $button_style . ' rocketicon rocketicon-'. $class . '">' . wp_kses_post( $button['button_label'] ) . '</button>';
}
?>


<?php echo apply_filters( 'rocket_help', $desc, sanitize_key( strip_tags( $button['button_label'] ) ), 'description' ); ?>
<?php echo apply_filters( 'rocket_help', $help, sanitize_key( strip_tags( $button['button_label'] ) ), 'help' ); ?>
Expand Down Expand Up @@ -483,37 +483,37 @@ function rocket_display_options() {
'faq',
'support'
);

foreach( $modules as $module ) {
require( WP_ROCKET_ADMIN_UI_MODULES_PATH . $module . '.php' );
}

$heading_tag = version_compare( $GLOBALS['wp_version'], '4.3' ) >= 0 ? 'h1' : 'h2';
?>

<div class="wrap">

<<?php echo $heading_tag; ?>><?php echo WP_ROCKET_PLUGIN_NAME; ?> <small><sup><?php echo WP_ROCKET_VERSION; ?></sup></small></<?php echo $heading_tag; ?>>
<form action="options.php" id="rocket_options" method="post" enctype="multipart/form-data">
<?php
<?php
settings_fields( 'wp_rocket' );
rocket_hidden_fields(
array(
'consumer_key',
'consumer_email',
'secret_key',
'license',

rocket_hidden_fields(
array(
'consumer_key',
'consumer_email',
'secret_key',
'license',
'secret_cache_key',
'minify_css_key',
'minify_js_key',
'version',
'minify_css_key',
'minify_js_key',
'version',
'cloudflare_old_settings',
'cloudflare_zone_id'
)
);
submit_button();
);

submit_button();
?>
<h2 class="nav-tab-wrapper hide-if-no-js">
<?php if( rocket_valid_key() ) { ?>
Expand All @@ -525,8 +525,8 @@ function rocket_display_options() {
<a href="#tab_cloudflare" class="nav-tab">CloudFlare</a>
<?php } ?>
<a href="#tab_cdn" class="nav-tab"><?php _e( 'CDN', 'rocket' ); ?></a>
<?php
/** This filter is documented in inc/admin/ui/modules/vanrish.php */
<?php
/** This filter is documented in inc/admin/ui/modules/vanrish.php */
if ( apply_filters( 'rocket_display_varnish_options_tab', true ) ) { ?>
<a href="#tab_varnish" class="nav-tab">Varnish</a>
<?php } ?>
Expand Down Expand Up @@ -562,8 +562,8 @@ function rocket_display_options() {
<div class="rkt-tab" id="tab_preload"><?php do_settings_sections( 'rocket_preload' ); ?></div>
<div class="rkt-tab" id="tab_cloudflare" <?php echo get_rocket_option( 'do_cloudflare' ) ? '' : 'style="display:none"'; ?>><?php do_settings_sections( 'rocket_cloudflare' ); ?></div>
<div class="rkt-tab" id="tab_cdn"><?php do_settings_sections( 'rocket_cdn' ); ?></div>
<?php
/** This filter is documented in inc/admin/ui/modules/vanrish.php */
<?php
/** This filter is documented in inc/admin/ui/modules/vanrish.php */
if ( apply_filters( 'rocket_display_varnish_options_tab', true ) ) { ?>
<div class="rkt-tab" id="tab_varnish">
<p class="description varnish_description"><?php _e( 'The following options are for hosting with Varnish cache system.', 'rocket' ); ?><br/>
Expand Down Expand Up @@ -814,7 +814,7 @@ function rocket_settings_callback( $inputs ) {
if ( $inputs['schedule_automatic_cleanup'] != 1 && ( 'daily' != $inputs['automatic_cleanup_frequency'] || 'weekly' != $inputs['automatic_cleanup_frequency'] || 'monthly' != $inputs['automatic_cleanup_frequency'] ) ) {
unset( $inputs['automatic_cleanup_frequency'] );
}

/**
* Options: Activate bot preload
*/
Expand Down Expand Up @@ -859,15 +859,15 @@ function rocket_settings_callback( $inputs ) {
$inputs['wl_author_URI'] = isset( $inputs['wl_author_URI'] ) ? esc_url( $inputs['wl_author_URI'] ) : get_rocket_option( 'wl_author_URI' );
$inputs['wl_description'] = isset( $inputs['wl_description'] ) ? (array)$inputs['wl_description'] : get_rocket_option( 'wl_description' );
$inputs['wl_plugin_slug'] = sanitize_key( $inputs['wl_plugin_name'] );

/*
* Option : CloudFlare
*/

if ( defined( 'WP_ROCKET_CF_API_KEY' ) ) {
$inputs['cloudflare_api_key'] = get_rocket_option( 'cloudflare_api_key' );
}

/*
* Option : CDN
*/
Expand Down Expand Up @@ -904,24 +904,24 @@ function rocket_settings_callback( $inputs ) {
} else {
$inputs['cdn_reject_files'] = array();
}

/*
* Option: Support
*/
$fake_options = array(
$fake_options = array(
'support_summary',
'support_description',
'support_documentation_validation'
);

foreach ( $fake_options as $option ) {
if( isset( $inputs[$option] ) ) {
unset($inputs[$option]);
}
}

$filename_prefix = rocket_is_white_label() ? sanitize_title( get_rocket_option( 'wl_plugin_name' ) ) : 'wp-rocket';

if ( isset( $_FILES['import'] )
&& preg_match( '/'. $filename_prefix . '-settings-20\d{2}-\d{2}-\d{2}-[a-f0-9]{13}\.txt/', $_FILES['import']['name'] )
&& 'text/plain' == $_FILES['import']['type'] ) {
Expand Down Expand Up @@ -951,15 +951,13 @@ function rocket_settings_callback( $inputs ) {
}

if ( ! rocket_valid_key() ) {
$checked = rocket_check_key( 'live' );
} else {
$checked = rocket_check_key( 'transient_1' );
$checked = rocket_check_key();
}

if ( is_array( $checked ) ) {
$inputs['consumer_key'] = $checked['consumer_key'];
$inputs['consumer_key'] = $checked['consumer_key'];
$inputs['consumer_email'] = $checked['consumer_email'];
$inputs['secret_key'] = $checked['secret_key'];
$inputs['secret_key'] = $checked['secret_key'];
}

if ( rocket_valid_key() && ! empty( $inputs['secret_key'] ) && ! isset( $inputs['ignore'] ) ) {
Expand All @@ -986,17 +984,17 @@ function rocket_after_save_options( $oldvalue, $value ) {
if ( ! ( is_array( $oldvalue ) && is_array( $value ) ) ) {
return;
}

// This values do not need to clean the cache domain
$removed = array(
'purge_cron_interval' => true,
'purge_cron_unit' => true,
'wl_plugin_name' => true,
'wl_plugin_URI' => true,
'wl_author' => true,
'wl_author_URI' => true,
'wl_description' => true,
'wl_plugin_slug' => true
$removed = array(
'purge_cron_interval' => true,
'purge_cron_unit' => true,
'wl_plugin_name' => true,
'wl_plugin_URI' => true,
'wl_author' => true,
'wl_author_URI' => true,
'wl_description' => true,
'wl_plugin_slug' => true
);

// Create 2 arrays to compare
Expand Down Expand Up @@ -1038,7 +1036,7 @@ function rocket_after_save_options( $oldvalue, $value ) {
if ( ! empty( $_POST ) && isset( $_POST['wp_rocket_settings']['submit_optimize'] ) ) {
do_rocket_database_optimization();
}

// Update CloudFlare Development Mode
$cloudflare_update_result = array();

Expand All @@ -1051,11 +1049,11 @@ function rocket_after_save_options( $oldvalue, $value ) {
$cloudflare_update_result[] = array( 'result' => 'success', 'message' => sprintf( __( 'CloudFlare development mode %s', 'rocket' ), $cloudflare_dev_mode_return ) );
}
}

// Update CloudFlare settings
if ( ! empty( $_POST ) && isset( $oldvalue['cloudflare_auto_settings'], $value['cloudflare_auto_settings'] ) && $oldvalue['cloudflare_auto_settings'] != $value['cloudflare_auto_settings'] ) {
$cf_old_settings = explode( ',', $value['cloudflare_old_settings'] );
// Set Cache Level to Aggressive
// Set Cache Level to Aggressive
$cf_cache_level = ( isset( $cf_old_settings[0] ) && $value['cloudflare_auto_settings'] == 0 ) ? $cf_old_settings[0] : 'aggressive';
$cf_cache_level_return = set_rocket_cloudflare_cache_level( $cf_cache_level );

Expand Down Expand Up @@ -1099,12 +1097,12 @@ function rocket_after_save_options( $oldvalue, $value ) {
if ( ( bool ) $cloudflare_update_result ) {
set_transient( $GLOBALS['current_user']->ID . '_cloudflare_update_settings', $cloudflare_update_result );
}

// Regenerate advanced-cache.php file
if ( ! empty( $_POST ) && ( ( isset( $oldvalue['do_caching_mobile_files'] ) && ! isset( $value['do_caching_mobile_files'] ) ) || ( ! isset( $oldvalue['do_caching_mobile_files'] ) && isset( $value['do_caching_mobile_files'] ) ) || ( isset( $oldvalue['do_caching_mobile_files'], $value['do_caching_mobile_files'] ) ) && $oldvalue['do_caching_mobile_files'] != $value['do_caching_mobile_files'] ) ) {
rocket_generate_advanced_cache_file();
}

// Update .htaccess file rules
flush_rocket_htaccess( ! rocket_valid_key() );

Expand All @@ -1115,7 +1113,7 @@ function rocket_after_save_options( $oldvalue, $value ) {
if ( ! defined( 'WP_CACHE' ) || ! WP_CACHE ) {
set_rocket_wp_cache_define( true );
}

// Redirect on the correct page slug name to avoid false negative error message
if ( ! empty( $_POST ) && $oldvalue['wl_plugin_name'] != $value['wl_plugin_name'] &&
isset( $_POST['option_page'], $_POST['action'] ) && 'wp_rocket' == $_POST['option_page'] && 'update' == $_POST['action'] )
Expand Down Expand Up @@ -1187,12 +1185,12 @@ function rocket_pre_main_option( $newvalue, $oldvalue ) {
$cf_settings = get_rocket_cloudflare_settings();
$newvalue['cloudflare_old_settings'] = ( ! is_wp_error( $cf_settings ) ) ? implode( ',', array_filter( $cf_settings ) ) : '';
}

// Checked the SSL option if the whole website is on SSL
if( rocket_is_ssl_website() ) {
$newvalue['cache_ssl'] = 1;
}

if ( ! defined( 'WP_ROCKET_ADVANCED_CACHE' ) ) {
rocket_generate_advanced_cache_file();
}
Expand Down
27 changes: 15 additions & 12 deletions inc/admin/upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function rocket_upgrader() {
$options = get_option( WP_ROCKET_SLUG ); // do not use get_rocket_option() here
$options['version'] = WP_ROCKET_VERSION;

$keys = rocket_check_key( 'live' );
$keys = rocket_check_key();
if ( is_array( $keys ) ) {
$options = array_merge( $keys, $options );
}
Expand All @@ -40,11 +40,8 @@ function rocket_upgrader() {
if ( function_exists( 'opcache_reset' ) ) {
@opcache_reset();
}
} else {
if ( empty( $_POST ) && rocket_valid_key() ) {
rocket_check_key( 'transient_30' );
}
}

/** This filter is documented in inc/admin-bar.php */
if ( ! rocket_valid_key() && current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) &&
( ! isset( $_GET['page'] ) || 'wprocket' != $_GET['page'] ) ) {
Expand Down Expand Up @@ -263,21 +260,21 @@ function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
$options['minify_html_inline_css'] = 1;
$options['minify_html_inline_js'] = 1;
}

update_option( WP_ROCKET_SLUG, $options );

// Regenerate advanced-cache.php file
rocket_generate_advanced_cache_file();
}

if ( version_compare( $actual_version, '2.7', '<' ) ) {
// Regenerate advanced-cache.php file
rocket_generate_advanced_cache_file();

// Regenerate config file
rocket_generate_config_file();
}

if ( version_compare( $actual_version, '2.7.1', '<' ) ) {
// Regenerate advanced-cache.php file
rocket_generate_advanced_cache_file();
Expand All @@ -288,7 +285,7 @@ function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
$options['manual_preload'] = 1;
$options['automatic_preload'] = 1;
$options['sitemap_preload_url_crawl'] = '500000';

update_option( WP_ROCKET_SLUG, $options );
}

Expand Down Expand Up @@ -323,14 +320,20 @@ function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
update_rocket_option( 'minify_html_inline_css', 0 );
update_rocket_option( 'minify_html_inline_js', 0 );
}

if ( 'on' === get_option( 'autoptimize_css') ) {
update_rocket_option( 'minify_css', 0 );
}

if ( 'on' === get_option( 'autoptimize_js') ) {
update_rocket_option( 'minify_js', 0 );
}
}
}

// Delete old transients.
if ( version_compare( $actual_version, '2.9.7', '<' ) ) {
delete_transient( 'rocket_check_licence_30' );
delete_transient( 'rocket_check_licence_1' );
}
}
Loading

0 comments on commit 514d6a4

Please sign in to comment.