Пример #1
0
/**
 * Used to flush the .htaccess file
 *
 * @since 1.1.0 Remove empty spacings when .htaccess is generated
 * @since 1.0
 *
 * @param bool $force (default: false)
 * @return void
 */
function flush_rocket_htaccess($force = false)
{
    if (!$GLOBALS['is_apache']) {
        return;
    }
    $rules = '';
    $htaccess_file = get_home_path() . '.htaccess';
    if (is_writable($htaccess_file)) {
        // Get content of .htaccess file
        $ftmp = file_get_contents($htaccess_file);
        // Remove the WP Rocket marker
        $ftmp = preg_replace('/# BEGIN WP Rocket(.*)# END WP Rocket/isU', '', $ftmp);
        // Remove empty spacings
        $ftmp = str_replace("\n\n", "\n", $ftmp);
        if ($force === false) {
            $rules = get_rocket_htaccess_marker();
        }
        // Update the .htacces file
        rocket_put_content($htaccess_file, $rules . $ftmp);
    }
}
Пример #2
0
function rocket_warning_htaccess_permissions()
{
    $htaccess_file = get_home_path() . '.htaccess';
    /** This filter is documented in inc/admin-bar.php */
    if (current_user_can(apply_filters('rocket_capacity', 'manage_options')) && !is_writable($htaccess_file) && $GLOBALS['is_apache'] && 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><b><?php 
            echo WP_ROCKET_PLUGIN_NAME;
            ?>
</b>: <?php 
            printf(__('If you had <a href="%1$s" target="_blank">writing permissions</a> on <code>.htaccess</code> file, <b>%2$s</b> could do this automatically. This is not the case, so here are the rewrite rules you have to put in your <code>.htaccess</code> file for <b>%2$s</b> to work correctly. Click on the field and press Ctrl-A to select all.', 'rocket'), 'http://codex.wordpress.org/Changing_File_Permissions', WP_ROCKET_PLUGIN_NAME) . '<br>' . __('<strong>Warning:</strong> This message will popup again and its content may be updated when saving the options', 'rocket');
            ?>
</p>
				<p><textarea readonly="readonly" id="rules" name="rules" class="large-text readonly" rows="6"><?php 
            echo esc_textarea(get_rocket_htaccess_marker());
            ?>
</textarea></p>
			</div>

		<?php 
        }
    }
}