Skip to content

Commit 0d2c7f0

Browse files
committed
*Version bump to 0.5.0
1 parent 1ff8951 commit 0d2c7f0

File tree

3 files changed

+128
-119
lines changed

3 files changed

+128
-119
lines changed

README.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ This is used as a special version of the web page that forcibly disables support
6767

6868
== Changelog ==
6969

70+
### 0.5.0 ###
71+
72+
* Bug: Replace purge lock with disable_external_integration method due to the order that the actions run
73+
* Bug: Disable external integration when purging cache from web check queue
74+
* Enhancement: Improve redirect_canonical logic
75+
* Enhancement: Rebuild cache system without using SQL
76+
* Cleanup: Clean up code and fix typo with cache
77+
78+
7079
### 0.4.5 ###
7180

7281
* Change: Generalize fix_woocommerce_rewrite to fix_rewrites

lib/class-wp-criticalcss.php

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class WP_CriticalCSS {
77
/**
88
*
99
*/
10-
const VERSION = '0.4.5';
10+
const VERSION = '0.5.0';
1111

1212
/**
1313
*
@@ -238,13 +238,6 @@ public static function update_settings( array $settings ) {
238238
}
239239
}
240240

241-
/**
242-
*
243-
*/
244-
public static function reset_web_check_transients() {
245-
self::delete_cache_branch();
246-
}
247-
248241
/**
249242
*
250243
*/
@@ -607,6 +600,87 @@ public static function get_item_hash( $item ) {
607600
return md5( serialize( $type ) );
608601
}
609602

603+
protected function get_cache_fragment( $path ) {
604+
if ( ! in_array( 'cache', $path ) ) {
605+
array_unshift( $path, 'cache' );
606+
}
607+
608+
return get_transient( self::TRANSIENT_PREFIX . implode( '_', $path ) );
609+
}
610+
611+
protected static function update_cache_fragment( $path, $value ) {
612+
if ( ! in_array( 'cache', $path ) ) {
613+
array_unshift( $path, 'cache' );
614+
}
615+
self::build_cache_tree( array_slice( $path, 0, count( $path ) - 1 ) );
616+
self::update_tree_branch( $path, $value );
617+
}
618+
619+
protected static function build_cache_tree( $path ) {
620+
$levels = count( $path );
621+
$expire = get_rocket_purge_cron_interval();
622+
for ( $i = 0; $i < $levels; $i ++ ) {
623+
$transient_id = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 1 ) );
624+
$transient_cache_id = $transient_id;
625+
if ( 'cache' != $path[ $i ] ) {
626+
$transient_cache_id .= '_cache';
627+
}
628+
$transient_cache_id .= '_1';
629+
$cache = get_transient( $transient_cache_id );
630+
$transient_value = array();
631+
if ( $i + 1 < $levels ) {
632+
$transient_value[] = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 2 ) );
633+
}
634+
if ( ! is_null( $cache ) && false !== $cache ) {
635+
$transient_value = array_unique( array_merge( $cache, $transient_value ) );
636+
}
637+
set_transient( $transient_cache_id, $transient_value, $expire );
638+
$transient_counter_id = $transient_id;
639+
if ( 'cache' != $path[ $i ] ) {
640+
$transient_counter_id .= '_cache';
641+
}
642+
$transient_counter_id .= '_count';
643+
$transient_counter = get_transient( $transient_counter_id );
644+
if ( is_null( $transient_counter ) || false === $transient_counter ) {
645+
set_transient( $transient_counter_id, 1, $expire );
646+
}
647+
}
648+
}
649+
650+
protected static function update_tree_branch( $path, $value ) {
651+
$branch = self::TRANSIENT_PREFIX . implode( '_', $path );
652+
$parent_path = array_slice( $path, 0, count( $path ) - 1 );
653+
$parent = self::TRANSIENT_PREFIX . implode( '_', $parent_path );
654+
$counter_transient = $parent;
655+
$cache_transient = $parent;
656+
if ( 'cache' != end( $parent_path ) ) {
657+
$counter_transient .= '_cache';
658+
$cache_transient .= '_cache';
659+
}
660+
$counter_transient .= '_count';
661+
$counter = (int) get_transient( $counter_transient );
662+
$cache_transient .= "_{$counter}";
663+
$cache = get_transient( $cache_transient );
664+
$count = count( $cache );
665+
$cache_keys = array_flip( $cache );
666+
$expire = get_rocket_purge_cron_interval();
667+
if ( ! isset( $cache_keys[ $branch ] ) ) {
668+
if ( $count >= apply_filters( 'rocket_async_css_max_branch_length', 50 ) ) {
669+
$counter ++;
670+
set_transient( $counter_transient, $counter, $expire );
671+
$cache_transient = $parent;
672+
if ( 'cache' != end( $parent_path ) ) {
673+
$cache_transient .= '_cache';
674+
}
675+
$cache_transient .= "_{$counter}";
676+
$cache = array();
677+
}
678+
$cache[] = $branch;
679+
set_transient( $cache_transient, $cache, $expire );
680+
}
681+
set_transient( $branch, $value, $expire );
682+
}
683+
610684
/**
611685
* @return int
612686
*/
@@ -816,6 +890,42 @@ public static function sync_options( $value, $old_value ) {
816890
return $value;
817891
}
818892

893+
/**
894+
*
895+
*/
896+
public static function reset_web_check_transients() {
897+
self::delete_cache_branch();
898+
}
899+
900+
protected static function delete_cache_branch( $path = array() ) {
901+
if ( is_array( $path ) ) {
902+
if ( ! empty( $path ) ) {
903+
$path = self::TRANSIENT_PREFIX . implode( '_', $path ) . '_';
904+
} else {
905+
$path = self::TRANSIENT_PREFIX;
906+
}
907+
}
908+
$counter_transient = "{$path}cache_count";
909+
$counter = get_transient( $counter_transient );
910+
911+
if ( is_null( $counter ) || false === $counter ) {
912+
delete_transient( rtrim( $path, '_' ) );
913+
914+
return;
915+
}
916+
for ( $i = 1; $i <= $counter; $i ++ ) {
917+
$transient_name = "{$path}cache_{$i}";
918+
$cache = get_transient( "{$path}cache_{$i}" );
919+
if ( ! empty( $cache ) ) {
920+
foreach ( $cache as $sub_branch ) {
921+
self::delete_cache_branch( "{$sub_branch}_" );
922+
}
923+
delete_transient( $transient_name );
924+
}
925+
}
926+
delete_transient( $counter_transient );
927+
}
928+
819929
public static function reset_web_check_post_transient( $post ) {
820930
$post = get_post( $post );
821931
$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 ) {
886996
), admin_url( 'admin-post.php' ) ), $action ),
887997
) );
888998
}
889-
890-
protected function get_cache_fragment( $path ) {
891-
if ( ! in_array( 'cache', $path ) ) {
892-
array_unshift( $path, 'cache' );
893-
}
894-
895-
return get_transient( self::TRANSIENT_PREFIX . implode( '_', $path ) );
896-
}
897-
898-
protected static function update_cache_fragment( $path, $value ) {
899-
if ( ! in_array( 'cache', $path ) ) {
900-
array_unshift( $path, 'cache' );
901-
}
902-
self::build_cache_tree( array_slice( $path, 0, count( $path ) - 1 ) );
903-
self::update_tree_branch( $path, $value );
904-
}
905-
906-
protected static function build_cache_tree( $path ) {
907-
$levels = count( $path );
908-
$expire = get_rocket_purge_cron_interval();
909-
for ( $i = 0; $i < $levels; $i ++ ) {
910-
$transient_id = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 1 ) );
911-
$transient_cache_id = $transient_id;
912-
if ( 'cache' != $path[ $i ] ) {
913-
$transient_cache_id .= '_cache';
914-
}
915-
$transient_cache_id .= '_1';
916-
$cache = get_transient( $transient_cache_id );
917-
$transient_value = array();
918-
if ( $i + 1 < $levels ) {
919-
$transient_value[] = self::TRANSIENT_PREFIX . implode( '_', array_slice( $path, 0, $i + 2 ) );
920-
}
921-
if ( ! is_null( $cache ) && false !== $cache ) {
922-
$transient_value = array_unique( array_merge( $cache, $transient_value ) );
923-
}
924-
set_transient( $transient_cache_id, $transient_value, $expire );
925-
$transient_counter_id = $transient_id;
926-
if ( 'cache' != $path[ $i ] ) {
927-
$transient_counter_id .= '_cache';
928-
}
929-
$transient_counter_id .= '_count';
930-
$transient_counter = get_transient( $transient_counter_id );
931-
if ( is_null( $transient_counter ) || false === $transient_counter ) {
932-
set_transient( $transient_counter_id, 1, $expire );
933-
}
934-
}
935-
}
936-
937-
protected static function update_tree_branch( $path, $value ) {
938-
$branch = self::TRANSIENT_PREFIX . implode( '_', $path );
939-
$parent_path = array_slice( $path, 0, count( $path ) - 1 );
940-
$parent = self::TRANSIENT_PREFIX . implode( '_', $parent_path );
941-
$counter_transient = $parent;
942-
$cache_transient = $parent;
943-
if ( 'cache' != end( $parent_path ) ) {
944-
$counter_transient .= '_cache';
945-
$cache_transient .= '_cache';
946-
}
947-
$counter_transient .= '_count';
948-
$counter = (int) get_transient( $counter_transient );
949-
$cache_transient .= "_{$counter}";
950-
$cache = get_transient( $cache_transient );
951-
$count = count( $cache );
952-
$cache_keys = array_flip( $cache );
953-
$expire = get_rocket_purge_cron_interval();
954-
if ( ! isset( $cache_keys[ $branch ] ) ) {
955-
if ( $count >= apply_filters( 'rocket_async_css_max_branch_length', 50 ) ) {
956-
$counter ++;
957-
set_transient( $counter_transient, $counter, $expire );
958-
$cache_transient = $parent;
959-
if ( 'cache' != end( $parent_path ) ) {
960-
$cache_transient .= '_cache';
961-
}
962-
$cache_transient .= "_{$counter}";
963-
$cache = array();
964-
}
965-
$cache[] = $branch;
966-
set_transient( $cache_transient, $cache, $expire );
967-
}
968-
set_transient( $branch, $value, $expire );
969-
}
970-
971-
protected static function delete_cache_branch( $path = array() ) {
972-
if ( is_array( $path ) ) {
973-
if ( ! empty( $path ) ) {
974-
$path = self::TRANSIENT_PREFIX . implode( '_', $path ) . '_';
975-
} else {
976-
$path = self::TRANSIENT_PREFIX;
977-
}
978-
}
979-
$counter_transient = "{$path}cache_count";
980-
$counter = get_transient( $counter_transient );
981-
982-
if ( is_null( $counter ) || false === $counter ) {
983-
delete_transient( rtrim( $path, '_' ) );
984-
985-
return;
986-
}
987-
for ( $i = 1; $i <= $counter; $i ++ ) {
988-
$transient_name = "{$path}cache_{$i}";
989-
$cache = get_transient( "{$path}cache_{$i}" );
990-
if ( ! empty( $cache ) ) {
991-
foreach ( $cache as $sub_branch ) {
992-
self::delete_cache_branch( "{$sub_branch}_" );
993-
}
994-
delete_transient( $transient_name );
995-
}
996-
}
997-
delete_transient( $counter_transient );
998-
}
999999
}

wp-criticalcss.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: WP Critical CSS
55
Plugin URI: https://github.com/pcfreak30/wp-criticalcss
66
Description: Use CriticalCSS.com web service to automatically create the required CSS for above the fold
7-
Version: 0.4.5
7+
Version: 0.5.0
88
Author: Derrick Hammer
99
Author URI: https://www.derrickhammer.com
1010
License: GPL3

0 commit comments

Comments
 (0)