コード例 #1
0
ファイル: command.php プロジェクト: xfifix/wp-rocket-cli
 /**
  * Set WP_CACHE constant in wp-config.php to false
  *
  * ## EXAMPLES
  *
  *     wp rocket deactivate
  *
  * @subcommand deactivate
  */
 public function deactivate()
 {
     if (defined('WP_CACHE') && WP_CACHE) {
         if (is_writable(rocket_find_wpconfig_path())) {
             set_rocket_wp_cache_define(false);
             WP_CLI::success('WP Rocket is disable, WP_CACHE is set to false.');
         } else {
             WP_CLI::error('It seems we don\'t have writing permissions on wp-config.php file.');
         }
     } else {
         WP_CLI::error('WP Rocket is already disable.');
     }
 }
コード例 #2
0
ファイル: wp-rocket.php プロジェクト: EliasGoldberg/troop-sim
function rocket_deactivation()
{
    if (!isset($_GET['rocket_nonce']) || !wp_verify_nonce($_GET['rocket_nonce'], 'force_deactivation')) {
        $causes = array();
        // .htaccess problem
        if ($GLOBALS['is_apache'] && !is_writable(get_home_path() . '.htaccess')) {
            $causes[] = 'htaccess';
        }
        // wp-config problem
        if (!is_writable(rocket_find_wpconfig_path())) {
            $causes[] = 'wpconfig';
        }
        if (count($causes)) {
            set_transient($GLOBALS['current_user']->ID . '_donotdeactivaterocket', $causes);
            wp_safe_redirect(wp_get_referer());
            die;
        }
    }
    // Delete config files
    rocket_delete_config_file();
    if (!count(glob(WP_ROCKET_CONFIG_PATH . '*.php'))) {
        // Delete All WP Rocket rules of the .htaccess file
        flush_rocket_htaccess(true);
        // Remove WP_CACHE constant in wp-config.php
        set_rocket_wp_cache_define(false);
        // Delete content of advanced-cache.php
        rocket_put_content(WP_CONTENT_DIR . '/advanced-cache.php', '');
    }
    // Update customer key & licence.
    wp_remote_get(WP_ROCKET_WEB_API . 'pause-licence.php', array('blocking' => false));
    delete_transient('rocket_check_licence_30');
    delete_transient('rocket_check_licence_1');
}
コード例 #3
0
ファイル: files.php プロジェクト: EliasGoldberg/troop-sim
/**
 * Added or set the value of the WP_CACHE constant
 *
 * @since 2.0
 *
 * @param bool $turn_it_on The value of WP_CACHE constant
 * @return void
 */
function set_rocket_wp_cache_define($turn_it_on)
{
    // If WP_CACHE is already define, return to get a coffee
    if (!rocket_valid_key() || $turn_it_on && defined('WP_CACHE') && WP_CACHE) {
        return;
    }
    // Get path of the config file
    $config_file_path = rocket_find_wpconfig_path();
    if (!$config_file_path) {
        return;
    }
    // Get content of the config file
    $config_file = file($config_file_path);
    // Get the value of WP_CACHE constant
    $turn_it_on = $turn_it_on ? 'true' : 'false';
    /**
     * Filter allow to change the value of WP_CACHE constant
     *
     * @since 2.1
     *
     * @param string $turn_it_on The value of WP_CACHE constant
     */
    apply_filters('set_rocket_wp_cache_define', $turn_it_on);
    // Lets find out if the constant WP_CACHE is defined or not
    $is_wp_cache_exist = false;
    // Get WP_CACHE constant define
    $constant = "define('WP_CACHE', {$turn_it_on}); // Added by WP Rocket" . "\r\n";
    foreach ($config_file as &$line) {
        if (!preg_match('/^define\\(\\s*\'([A-Z_]+)\',(.*)\\)/', $line, $match)) {
            continue;
        }
        if ($match[1] == 'WP_CACHE') {
            $is_wp_cache_exist = true;
            $line = $constant;
        }
    }
    unset($line);
    // If the constant does not exist, create it
    if (!$is_wp_cache_exist) {
        array_shift($config_file);
        array_unshift($config_file, "<?php\r\n", $constant);
    }
    // Insert the constant in wp-config.php file
    $handle = @fopen($config_file_path, 'w');
    foreach ($config_file as $line) {
        @fwrite($handle, $line);
    }
    @fclose($handle);
    // Update the writing permissions of wp-config.php file
    $chmod = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : 0644;
    @chmod($config_file_path, $chmod);
}
コード例 #4
0
ファイル: notices.php プロジェクト: EliasGoldberg/troop-sim
function rocket_warning_wp_config_permissions()
{
    $config_file = rocket_find_wpconfig_path();
    if (!('plugins.php' == $GLOBALS['pagenow'] && isset($_GET['activate'])) && current_user_can(apply_filters('rocket_capacity', 'manage_options')) && (!is_writable($config_file) && (!defined('WP_CACHE') || !WP_CACHE)) && rocket_valid_key()) {
        $boxes = get_user_meta($GLOBALS['current_user']->ID, 'rocket_boxes', true);
        if (!in_array(__FUNCTION__, (array) $boxes)) {
            ?>

			<div class="error">
				<a href="<?php 
            echo wp_nonce_url(admin_url('admin-post.php?action=rocket_ignore&box=' . __FUNCTION__), 'rocket_ignore_' . __FUNCTION__);
            ?>
" class="rkt-cross"><div class="dashicons dashicons-no"></div></a>
				<p>
				<?php 
            printf(__('<b>%s</b>: It seems we don\'t have <a href="%s" target="_blank">writing permissions</a> on <code>wp-config.php</code> file or the value of the constant <code>WP_CACHE</code> is set to <code>false</code>', 'rocket'), WP_ROCKET_PLUGIN_NAME, "http://codex.wordpress.org/Changing_File_Permissions");
            echo '<br>';
            _e('To fix this you have to set writing permissions for <code>wp-config.php</code> and then save the settings again.', 'rocket');
            echo '<br>';
            _e('If the message persists, you have to put the following code in your <code>wp-config.php</code> file so that it works correctly. Click on the field and press Ctrl-A to select all.', 'rocket');
            ?>
				</p>

				<?php 
            // Get the content of the WP_CACHE constant added by WP Rocket
            $define = "/** Enable Cache by WP Rocket */\r\ndefine( 'WP_CACHE', true );\r\n";
            ?>

				<p><textarea readonly="readonly" id="rules" name="rules" class="large-text readonly" rows="2"><?php 
            echo esc_textarea($define);
            ?>
</textarea></p>
			</div>

		<?php 
        }
    }
}