Skip to content

Commit

Permalink
Control automatic .htaccess update
Browse files Browse the repository at this point in the history
In some case, users might want to disable automatic configuration.
Henceforth, there is an option to control that. fixes #37
  • Loading branch information
mustafauysal committed Dec 19, 2017
1 parent c9342b2 commit 0198724
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions includes/admin/class-powered-cache-admin-actions.php
Expand Up @@ -13,7 +13,7 @@ class Powered_Cache_Admin_Actions {
* @since 1.0
*/
public static function update_settings() {
global $powered_cache_options, $powered_cache_fs;
global $powered_cache_options, $powered_cache_fs, $is_apache;;


if ( ! defined( 'POWERED_CACHE_SAVING_OPTIONS' ) ) {
Expand All @@ -33,13 +33,20 @@ public static function update_settings() {
case 'basic-options':
default:
$new_options['enable_page_caching'] = ( isset( $_post['enable_page_caching'] ) && 1 == $_post['enable_page_caching'] ? true : false );
$new_options['configure_htaccess'] = ( isset( $_post['configure_htaccess'] ) && 1 == $_post['configure_htaccess'] ? true : false );
$new_options['object_cache'] = ( isset( $_post['object_cache'] ) ? sanitize_text_field( $_post['object_cache'] ) : 'off' );
$new_options['cache_mobile'] = ( isset( $_post['cache_mobile'] ) && 1 == $_post['cache_mobile'] ? true : false );
$new_options['cache_mobile_separate_file'] = ( ( isset( $_post['cache_mobile'] ) && 1 == $_post['cache_mobile'] ) && ( isset( $_post['cache_mobile_separate_file'] ) && 1 == $_post['cache_mobile_separate_file'] ) ? true : false );
$new_options['cache_mobile_separate_file'] = ( true === $new_options['cache_mobile'] && ( isset( $_post['cache_mobile_separate_file'] ) && 1 == $_post['cache_mobile_separate_file'] ) ? true : false );
$new_options['loggedin_user_cache'] = ( isset( $_post['loggedin_user_cache'] ) && 1 == $_post['loggedin_user_cache'] ? true : false );
$new_options['ssl_cache'] = ( isset( $_post['ssl_cache'] ) && 1 == $_post['ssl_cache'] ? true : false );
$new_options['gzip_compression'] = ( isset( $_post['gzip_compression'] ) && 1 == $_post['gzip_compression'] ? true : false );


// this option only valid on apache
if ( ! $is_apache ) {
unset( $new_options['configure_htaccess'] );
}

/**
* Calculate timeout with given interval, saving as minutes.
*
Expand Down
6 changes: 6 additions & 0 deletions includes/admin/settings/basic-options.php
Expand Up @@ -27,6 +27,12 @@
<?php _e( 'Enable page caching that will reduce the response time of your site.', 'powered-cache' ); ?>
(<a target="_blank" href="http://docs.poweredcache.com/article/4-page-cache">?</a>)
</label>
<?php global $is_apache;
if ( $is_apache && ( ( is_multisite() && current_user_can( 'manage_network' ) ) || current_user_can( 'activate_plugins' ) ) ): ?>
<div id="configure-htaccess-option">
<label><input type="checkbox" id="cache_configure_htaccess" name="powered_cache_settings[configure_htaccess]" <?php checked( powered_cache_get_option( 'configure_htaccess' ), 1 ); ?> value="1"><?php _e( 'Configure <code>.htaccess</code> file automatically.', 'powered-cache' ); ?></label>
</div>
<?php endif; ?>
</td>
</tr>

Expand Down
12 changes: 12 additions & 0 deletions includes/class-powered-cache-config.php
Expand Up @@ -58,6 +58,7 @@ public function default_settings() {
$settings = array(
// basic options
'enable_page_caching' => false,
'configure_htaccess' => true,
'object_cache' => 'off',
'cache_mobile' => true,
'cache_mobile_separate_file' => false,
Expand Down Expand Up @@ -412,6 +413,17 @@ public function configure_htaccess( $enable = true ) {
return false;
}

/**
* Apache users can control automatic configuration
*
* @since 1.2
*/
$automatic_configuration = powered_cache_get_option( 'configure_htaccess' );

if ( ! $automatic_configuration ) {
return false;
}

if ( $powered_cache_fs->is_writable( $htaccess_file ) ) {
$contents = $powered_cache_fs->get_contents( $htaccess_file );

Expand Down

0 comments on commit 0198724

Please sign in to comment.