From 0d2c7f0864d2c87db4357effe3ec4c74b29fdea9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 25 Mar 2017 21:00:20 -0400 Subject: [PATCH] *Version bump to 0.5.0 --- README.txt | 9 ++ lib/class-wp-criticalcss.php | 236 +++++++++++++++++------------------ wp-criticalcss.php | 2 +- 3 files changed, 128 insertions(+), 119 deletions(-) diff --git a/README.txt b/README.txt index 0b31969..a583848 100644 --- a/README.txt +++ b/README.txt @@ -67,6 +67,15 @@ This is used as a special version of the web page that forcibly disables support == Changelog == +### 0.5.0 ### + +* Bug: Replace purge lock with disable_external_integration method due to the order that the actions run +* Bug: Disable external integration when purging cache from web check queue +* Enhancement: Improve redirect_canonical logic +* Enhancement: Rebuild cache system without using SQL +* Cleanup: Clean up code and fix typo with cache + + ### 0.4.5 ### * Change: Generalize fix_woocommerce_rewrite to fix_rewrites diff --git a/lib/class-wp-criticalcss.php b/lib/class-wp-criticalcss.php index c0ae9c4..a41842f 100644 --- a/lib/class-wp-criticalcss.php +++ b/lib/class-wp-criticalcss.php @@ -7,7 +7,7 @@ class WP_CriticalCSS { /** * */ - const VERSION = '0.4.5'; + const VERSION = '0.5.0'; /** * @@ -238,13 +238,6 @@ public static function update_settings( array $settings ) { } } - /** - * - */ - public static function reset_web_check_transients() { - self::delete_cache_branch(); - } - /** * */ @@ -607,6 +600,87 @@ public static function get_item_hash( $item ) { return md5( serialize( $type ) ); } + protected function get_cache_fragment( $path ) { + if ( ! in_array( 'cache', $path ) ) { + array_unshift( $path, 'cache' ); + } + + return get_transient( self::TRANSIENT_PREFIX . implode( '_', $path ) ); + } + + protected static function update_cache_fragment( $path, $value ) { + if ( ! in_array( 'cache', $path ) ) { + array_unshift( $path, 'cache' ); + } + self::build_cache_tree( array_slice( $path, 0, count( $path ) - 1 ) ); + self::update_tree_branch( $path, $value ); + } + + protected static function build_cache_tree( $path ) { + $levels = count( $path ); + $expire = get_rocket_purge_cron_interval(); + for ( $i = 0; $i < $levels; $i ++ ) { + $transient_id = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 1 ) ); + $transient_cache_id = $transient_id; + if ( 'cache' != $path[ $i ] ) { + $transient_cache_id .= '_cache'; + } + $transient_cache_id .= '_1'; + $cache = get_transient( $transient_cache_id ); + $transient_value = array(); + if ( $i + 1 < $levels ) { + $transient_value[] = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 2 ) ); + } + if ( ! is_null( $cache ) && false !== $cache ) { + $transient_value = array_unique( array_merge( $cache, $transient_value ) ); + } + set_transient( $transient_cache_id, $transient_value, $expire ); + $transient_counter_id = $transient_id; + if ( 'cache' != $path[ $i ] ) { + $transient_counter_id .= '_cache'; + } + $transient_counter_id .= '_count'; + $transient_counter = get_transient( $transient_counter_id ); + if ( is_null( $transient_counter ) || false === $transient_counter ) { + set_transient( $transient_counter_id, 1, $expire ); + } + } + } + + protected static function update_tree_branch( $path, $value ) { + $branch = self::TRANSIENT_PREFIX . implode( '_', $path ); + $parent_path = array_slice( $path, 0, count( $path ) - 1 ); + $parent = self::TRANSIENT_PREFIX . implode( '_', $parent_path ); + $counter_transient = $parent; + $cache_transient = $parent; + if ( 'cache' != end( $parent_path ) ) { + $counter_transient .= '_cache'; + $cache_transient .= '_cache'; + } + $counter_transient .= '_count'; + $counter = (int) get_transient( $counter_transient ); + $cache_transient .= "_{$counter}"; + $cache = get_transient( $cache_transient ); + $count = count( $cache ); + $cache_keys = array_flip( $cache ); + $expire = get_rocket_purge_cron_interval(); + if ( ! isset( $cache_keys[ $branch ] ) ) { + if ( $count >= apply_filters( 'rocket_async_css_max_branch_length', 50 ) ) { + $counter ++; + set_transient( $counter_transient, $counter, $expire ); + $cache_transient = $parent; + if ( 'cache' != end( $parent_path ) ) { + $cache_transient .= '_cache'; + } + $cache_transient .= "_{$counter}"; + $cache = array(); + } + $cache[] = $branch; + set_transient( $cache_transient, $cache, $expire ); + } + set_transient( $branch, $value, $expire ); + } + /** * @return int */ @@ -816,6 +890,42 @@ public static function sync_options( $value, $old_value ) { return $value; } + /** + * + */ + public static function reset_web_check_transients() { + self::delete_cache_branch(); + } + + protected static function delete_cache_branch( $path = array() ) { + if ( is_array( $path ) ) { + if ( ! empty( $path ) ) { + $path = self::TRANSIENT_PREFIX . implode( '_', $path ) . '_'; + } else { + $path = self::TRANSIENT_PREFIX; + } + } + $counter_transient = "{$path}cache_count"; + $counter = get_transient( $counter_transient ); + + if ( is_null( $counter ) || false === $counter ) { + delete_transient( rtrim( $path, '_' ) ); + + return; + } + for ( $i = 1; $i <= $counter; $i ++ ) { + $transient_name = "{$path}cache_{$i}"; + $cache = get_transient( "{$path}cache_{$i}" ); + if ( ! empty( $cache ) ) { + foreach ( $cache as $sub_branch ) { + self::delete_cache_branch( "{$sub_branch}_" ); + } + delete_transient( $transient_name ); + } + } + delete_transient( $counter_transient ); + } + public static function reset_web_check_post_transient( $post ) { $post = get_post( $post ); $hash = self::get_item_hash( array( 'object_id' => $post->ID, 'type' => 'post' ) ); @@ -886,114 +996,4 @@ public static function admin_menu( WP_Admin_Bar $wp_admin_bar ) { ), admin_url( 'admin-post.php' ) ), $action ), ) ); } - - protected function get_cache_fragment( $path ) { - if ( ! in_array( 'cache', $path ) ) { - array_unshift( $path, 'cache' ); - } - - return get_transient( self::TRANSIENT_PREFIX . implode( '_', $path ) ); - } - - protected static function update_cache_fragment( $path, $value ) { - if ( ! in_array( 'cache', $path ) ) { - array_unshift( $path, 'cache' ); - } - self::build_cache_tree( array_slice( $path, 0, count( $path ) - 1 ) ); - self::update_tree_branch( $path, $value ); - } - - protected static function build_cache_tree( $path ) { - $levels = count( $path ); - $expire = get_rocket_purge_cron_interval(); - for ( $i = 0; $i < $levels; $i ++ ) { - $transient_id = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 1 ) ); - $transient_cache_id = $transient_id; - if ( 'cache' != $path[ $i ] ) { - $transient_cache_id .= '_cache'; - } - $transient_cache_id .= '_1'; - $cache = get_transient( $transient_cache_id ); - $transient_value = array(); - if ( $i + 1 < $levels ) { - $transient_value[] = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 2 ) ); - } - if ( ! is_null( $cache ) && false !== $cache ) { - $transient_value = array_unique( array_merge( $cache, $transient_value ) ); - } - set_transient( $transient_cache_id, $transient_value, $expire ); - $transient_counter_id = $transient_id; - if ( 'cache' != $path[ $i ] ) { - $transient_counter_id .= '_cache'; - } - $transient_counter_id .= '_count'; - $transient_counter = get_transient( $transient_counter_id ); - if ( is_null( $transient_counter ) || false === $transient_counter ) { - set_transient( $transient_counter_id, 1, $expire ); - } - } - } - - protected static function update_tree_branch( $path, $value ) { - $branch = self::TRANSIENT_PREFIX . implode( '_', $path ); - $parent_path = array_slice( $path, 0, count( $path ) - 1 ); - $parent = self::TRANSIENT_PREFIX . implode( '_', $parent_path ); - $counter_transient = $parent; - $cache_transient = $parent; - if ( 'cache' != end( $parent_path ) ) { - $counter_transient .= '_cache'; - $cache_transient .= '_cache'; - } - $counter_transient .= '_count'; - $counter = (int) get_transient( $counter_transient ); - $cache_transient .= "_{$counter}"; - $cache = get_transient( $cache_transient ); - $count = count( $cache ); - $cache_keys = array_flip( $cache ); - $expire = get_rocket_purge_cron_interval(); - if ( ! isset( $cache_keys[ $branch ] ) ) { - if ( $count >= apply_filters( 'rocket_async_css_max_branch_length', 50 ) ) { - $counter ++; - set_transient( $counter_transient, $counter, $expire ); - $cache_transient = $parent; - if ( 'cache' != end( $parent_path ) ) { - $cache_transient .= '_cache'; - } - $cache_transient .= "_{$counter}"; - $cache = array(); - } - $cache[] = $branch; - set_transient( $cache_transient, $cache, $expire ); - } - set_transient( $branch, $value, $expire ); - } - - protected static function delete_cache_branch( $path = array() ) { - if ( is_array( $path ) ) { - if ( ! empty( $path ) ) { - $path = self::TRANSIENT_PREFIX . implode( '_', $path ) . '_'; - } else { - $path = self::TRANSIENT_PREFIX; - } - } - $counter_transient = "{$path}cache_count"; - $counter = get_transient( $counter_transient ); - - if ( is_null( $counter ) || false === $counter ) { - delete_transient( rtrim( $path, '_' ) ); - - return; - } - for ( $i = 1; $i <= $counter; $i ++ ) { - $transient_name = "{$path}cache_{$i}"; - $cache = get_transient( "{$path}cache_{$i}" ); - if ( ! empty( $cache ) ) { - foreach ( $cache as $sub_branch ) { - self::delete_cache_branch( "{$sub_branch}_" ); - } - delete_transient( $transient_name ); - } - } - delete_transient( $counter_transient ); - } } \ No newline at end of file diff --git a/wp-criticalcss.php b/wp-criticalcss.php index 44236a8..3ba853c 100644 --- a/wp-criticalcss.php +++ b/wp-criticalcss.php @@ -4,7 +4,7 @@ Plugin Name: WP Critical CSS Plugin URI: https://github.com/pcfreak30/wp-criticalcss Description: Use CriticalCSS.com web service to automatically create the required CSS for above the fold -Version: 0.4.5 +Version: 0.5.0 Author: Derrick Hammer Author URI: https://www.derrickhammer.com License: GPL3