示例#1
1
function rocket_new_upgrade($wp_rocket_version, $actual_version)
{
    if (version_compare($actual_version, '1.0.1', '<')) {
        wp_clear_scheduled_hook('rocket_check_event');
    }
    if (version_compare($actual_version, '1.2.0', '<')) {
        // Delete old WP Rocket cache dir
        rocket_rrmdir(WP_ROCKET_PATH . 'cache');
        // Create new WP Rocket cache dir
        if (!is_dir(WP_ROCKET_CACHE_PATH)) {
            mkdir(WP_ROCKET_CACHE_PATH);
        }
    }
    if (version_compare($actual_version, '1.3.0', '<')) {
        rocket_dismiss_box('rocket_warning_plugin_modification');
    }
    if (version_compare($actual_version, '1.3.3', '<')) {
        // Clean cache
        rocket_clean_domain();
        // Create cache files
        run_rocket_bot('cache-preload');
    }
    if (version_compare($actual_version, '2.0', '<')) {
        // Add secret cache key
        $options = get_option(WP_ROCKET_SLUG);
        $options['secret_cache_key'] = create_rocket_uniqid();
        update_option(WP_ROCKET_SLUG, $options);
        global $wp_filesystem;
        if (!$wp_filesystem) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
            require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
            $wp_filesystem = new WP_Filesystem_Direct(new StdClass());
        }
        // Get chmod of old folder cache
        $chmod = is_dir(WP_CONTENT_DIR . '/wp-rocket-cache') ? substr(sprintf('%o', fileperms(WP_CONTENT_DIR . '/wp-rocket-cache')), -4) : CHMOD_WP_ROCKET_CACHE_DIRS;
        // Check and create cache folder in wp-content if not already exist
        if (!$wp_filesystem->is_dir(WP_CONTENT_DIR . '/cache')) {
            $wp_filesystem->mkdir(WP_CONTENT_DIR . '/cache', octdec($chmod));
        }
        $wp_filesystem->mkdir(WP_CONTENT_DIR . '/cache/wp-rocket', octdec($chmod));
        // Move old cache folder in new path
        @rename(WP_CONTENT_DIR . '/wp-rocket-cache', WP_CONTENT_DIR . '/cache/wp-rocket');
        // Add WP_CACHE constant in wp-config.php
        set_rocket_wp_cache_define(true);
        // Create advanced-cache.php file
        rocket_generate_advanced_cache_file();
        // Create config file
        rocket_generate_config_file();
    }
    if (version_compare($actual_version, '2.1', '<')) {
        rocket_reset_white_label_values(false);
        // Create minify cache folder if not exist
        if (!is_dir(WP_ROCKET_MINIFY_CACHE_PATH)) {
            rocket_mkdir_p(WP_ROCKET_MINIFY_CACHE_PATH);
        }
        // Create config domain folder if not exist
        if (!is_dir(WP_ROCKET_CONFIG_PATH)) {
            rocket_mkdir_p(WP_ROCKET_CONFIG_PATH);
        }
        // Create advanced-cache.php file
        rocket_generate_advanced_cache_file();
        // Create config file
        rocket_generate_config_file();
    }
    if (version_compare($actual_version, '2.3.3', '<')) {
        // Clean cache
        rocket_clean_domain();
        // Create cache files
        run_rocket_bot('cache-preload');
    }
    if (version_compare($actual_version, '2.3.9', '<')) {
        // Regenerate config file
        rocket_generate_config_file();
    }
    if (version_compare($actual_version, '2.4.1', '<')) {
        // Regenerate advanced-cache.php file
        rocket_generate_advanced_cache_file();
        delete_transient('rocket_ask_for_update');
    }
    if (version_compare($actual_version, '2.6', '<')) {
        // Activate Inline CSS & JS minification if HTML minification is activated
        $options = get_option(WP_ROCKET_SLUG);
        if (!empty($options['minify_html'])) {
            $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();
    }
}
示例#2
0
/**
 * Directory creation based on WordPress Filesystem
 *
 * @since 1.3.4
 *
 * @param string $dir The path of directory will be created
 * @return bool
 */
function rocket_mkdir($dir)
{
    require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
    $direct_filesystem = new WP_Filesystem_Direct(new StdClass());
    $chmod = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : fileperms(WP_CONTENT_DIR) & 0777 | 0755;
    return $direct_filesystem->mkdir($dir, $chmod);
}
示例#3
0
 static function MoveDir($from, $to)
 {
     require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
     require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
     $wp_filesystem = new WP_Filesystem_Direct(null);
     $dirlist = $wp_filesystem->dirlist($from);
     $from = trailingslashit($from);
     $to = trailingslashit($to);
     foreach ((array) $dirlist as $filename => $fileinfo) {
         if ('f' == $fileinfo['type']) {
             if (!$wp_filesystem->move($from . $filename, $to . $filename, true)) {
                 return false;
             }
             $wp_filesystem->chmod($to . $filename, octdec(WPFB_PERM_FILE));
         } elseif ('d' == $fileinfo['type']) {
             if (!$wp_filesystem->mkdir($to . $filename, octdec(WPFB_PERM_DIR))) {
                 return false;
             }
             if (!self::MoveDir($from . $filename, $to . $filename)) {
                 return false;
             }
         }
     }
     // finally delete the from dir
     @rmdir($from);
     return true;
 }
 /**
  * @access public
  *
  * @param string $path
  * @param mixed  $chmod
  * @param mixed  $chown
  * @param mixed  $chgrp
  * @return bool
  */
 public function mkdir($path, $chmod = false, $chown = false, $chgrp = false)
 {
     if ($this->authorized()) {
         return parent::mkdir($path, $chmod, $chown, $chgrp);
     } else {
         return false;
     }
 }