Skip to content

Commit

Permalink
Clean up Limit Global Styles logic (#70121)
Browse files Browse the repository at this point in the history
Cleans up some technical debt from the logic that limits Global Styles:
- The `theme_json_user` filter is no longer used to block styles since WP.com no longer loads the Gutenberg version that triggered it
- Remove usages of `_Gutenberg` classes since they are not intended to be used externally.
  • Loading branch information
mmtr authored Dec 6, 2022
1 parent 76b16dd commit 96e552a
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,14 @@ function wpcom_block_global_styles_frontend( $theme_json ) {

if ( class_exists( 'WP_Theme_JSON_Data' ) ) {
return new WP_Theme_JSON_Data( array(), 'custom' );
} elseif ( class_exists( 'WP_Theme_JSON_Data_Gutenberg' ) ) {
return new WP_Theme_JSON_Data_Gutenberg( array(), 'custom' );
}

/*
* If both `WP_Theme_JSON_Data` and `WP_Theme_JSON_Data_Gutenberg` are missing,
* then the site is running an old version of WordPress and Gutenberg where we
* cannot block the user styles properly.
* If `WP_Theme_JSON_Data` is missing, then the site is running an old
* version of WordPress we cannot block the user styles properly.
*/
return $theme_json;
}
add_filter( 'theme_json_user', 'wpcom_block_global_styles_frontend' );
add_filter( 'wp_theme_json_data_user', 'wpcom_block_global_styles_frontend' );

/**
Expand Down Expand Up @@ -217,7 +213,15 @@ function wpcom_track_global_styles( $blog_id, $post, $updated ) {
* @return bool Returns true if custom styles are in use.
*/
function wpcom_global_styles_in_use() {
$user_cpt = WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_wp_global_styles( wp_get_theme() );
/*
* If `WP_Theme_JSON_Resolver` is missing, then the site is running an old version
* of WordPress, so we cannot determine whether the site has custom styles.
*/
if ( ! class_exists( 'WP_Theme_JSON_Resolver' ) ) {
return false;
}

$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme() );

if ( ! isset( $user_cpt['post_content'] ) ) {
do_action( 'global_styles_log', 'global_styles_not_in_use' );
Expand Down

0 comments on commit 96e552a

Please sign in to comment.