Skip to content

Commit

Permalink
hide hash post meta, minor movement of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 22, 2024
1 parent 357800d commit c01582c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/css-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public function generate_optimied_css_for_post( $post_id, $post, $update ) {
return;
}

// Get the hashed CSS from post meta.
$hashed_css = get_post_meta( $post_id, 'stackable_css_hash', true );

// Convert content to blocks.
$blocks = parse_blocks( $post->post_content );

Expand All @@ -135,11 +132,12 @@ public function generate_optimied_css_for_post( $post_id, $post, $update ) {
}
}

$serialized_css = json_encode( $styles_only );
$css_to_hash = hash( 'sha256', $serialized_css );
// Get the hashed CSS from post meta.
$hashed_css = get_post_meta( $post_id, 'stackable_css_hash', true );
$new_hashed_css = hash( 'sha256', json_encode( $styles_only ) );

// if the hash is the same, don't update
if ( hash_equals( $hashed_css, $css_to_hash ) ) {
if ( hash_equals( $hashed_css, $new_hashed_css ) ) {
return;
}

Expand All @@ -149,7 +147,7 @@ public function generate_optimied_css_for_post( $post_id, $post, $update ) {
update_post_meta( $post_id, 'stackable_optimized_css', $optimized_css );
update_post_meta( $post_id, 'stackable_optimized_css_raw', $styles );
// Update the hash of the styles.
update_post_meta( $post_id, 'stackable_css_hash', $css_to_hash );
update_post_meta( $post_id, 'stackable_css_hash', $new_hashed_css );
}

/**
Expand Down Expand Up @@ -486,7 +484,9 @@ public static function generate_css( $styles ) {
* @return boolean
*/
public function protect_optimized_css_meta( $protected, $meta_key ) {
if ( $meta_key === 'stackable_optimized_css' || $meta_key === 'stackable_optimized_css_raw' ) {
if ( $meta_key === 'stackable_optimized_css' ||
$meta_key === 'stackable_optimized_css_raw' ||
$meta_key === 'stackable_css_hash' ) {
return true;
}
return $protected;
Expand Down

0 comments on commit c01582c

Please sign in to comment.