Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 4b07c82

Browse files
mmtrpbking
andauthored
Blockbase: Optionally remove inherited style variations from child themes (#6996)
* Blockbase: Remove style variations from child themes Co-authored-by: Jason Crist <jcrist@pbking.com>
1 parent fb7e010 commit 4b07c82

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

blockbase/functions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function blockbase_scripts() {
103103
}
104104

105105
require get_template_directory() . '/inc/fonts/custom-fonts.php';
106+
require get_template_directory() . '/inc/rest-api.php';
106107

107108

108109
// Force menus to reload

blockbase/inc/rest-api.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Removes the style variations of Blockbase child themes inherited by the parent theme.
5+
*
6+
* @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client.
7+
* @param array $handler Route handler used for the request.
8+
*
9+
* @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed Result to send to the client.
10+
*/
11+
function blockbase_remove_style_variations_from_child_themes( $response, $handler ) {
12+
if ( ! isset( $handler['callback'] ) || ! is_array( $handler['callback'] ) ) {
13+
return $response;
14+
}
15+
16+
$handler_class = isset( $handler['callback'][0] ) ? $handler['callback'][0] : null;
17+
$handler_method = isset( $handler['callback'][1] ) ? $handler['callback'][1] : null;
18+
$opt_out = wp_get_global_settings( array( 'custom', 'optOutOfParentStyleVariations' ) );
19+
20+
/*
21+
* Prevents Blockbase child themes from being considered child themes in the
22+
* `wp/v2/global-styles/themes/:theme/variations` API endpoint, so they don't
23+
* inherit the style variations from the parent theme.
24+
*/
25+
if ( $opt_out && is_a( $handler_class, 'WP_REST_Global_Styles_Controller' ) && 'get_theme_items' === $handler_method ) {
26+
add_filter( 'template_directory', 'get_stylesheet_directory' );
27+
}
28+
29+
return $response;
30+
}
31+
32+
add_filter( 'rest_request_before_callbacks', 'blockbase_remove_style_variations_from_child_themes', 10, 2 );

blockbase/theme.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
]
9494
},
9595
"custom": {
96+
"optOutOfParentStyleVariations": false,
9697
"alignment": {
9798
"alignedMaxWidth": "50%"
9899
},

jackson/theme.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"primary": "var(--wp--preset--color--foreground)",
2525
"secondary": "var(--wp--preset--color--foreground)",
2626
"tertiary": "var(--wp--preset--color--background)"
27-
}
27+
},
28+
"optOutOfParentStyleVariations": true
2829
}
2930
},
3031
"styles": {

kingsley/theme.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"primary": "var(--wp--preset--color--foreground)",
2525
"secondary": "var(--wp--preset--color--foreground)",
2626
"tertiary": "var(--wp--preset--color--background)"
27-
}
27+
},
28+
"optOutOfParentStyleVariations": true
2829
}
2930
},
3031
"styles": {

0 commit comments

Comments
 (0)