Skip to content

Commit

Permalink
Avoid duplicate queries
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 28, 2021
1 parent 2e2caa2 commit b91a650
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions lib/compat/wordpress-5.9/rest-active-global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@
function gutenberg_add_active_global_styles_link( $response, $theme ) {
if ( $theme->get_stylesheet() === wp_get_theme()->get_stylesheet() ) {
// This creates a record for the current theme if not existant.
WP_Theme_JSON_Resolver_Gutenberg::get_user_custom_post_type_id();
}
$id = WP_Theme_JSON_Resolver_Gutenberg::get_user_custom_post_type_id();
} else {

$wp_query_args = array(
'post_status' => array( 'publish' ),
'post_type' => 'wp_global_styles',
'posts_per_page' => 1,
'no_found_rows' => true,
'tax_query' => array(
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $theme->get_stylesheet(),
$wp_query_args = array(
'post_status' => array( 'publish' ),
'post_type' => 'wp_global_styles',
'posts_per_page' => 1,
'no_found_rows' => true,
'tax_query' => array(
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $theme->get_stylesheet(),
),
),
),
);
$global_styles_query = new WP_Query( $wp_query_args );
if ( count( $global_styles_query->posts ) ) {
);
$global_styles_query = new WP_Query( $wp_query_args );
$id = count( $global_styles_query->posts ) ? $global_styles_query->posts[0]->ID : null;
}

if ( $id ) {
$response->add_link(
'https://api.w.org/user-global-styles',
rest_url( 'wp/v2/global-styles/' . $global_styles_query->posts[0]->ID )
rest_url( 'wp/v2/global-styles/' . $id )
);
}

Expand Down

0 comments on commit b91a650

Please sign in to comment.