-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blockbase: Optionally remove inherited style variations from child th…
…emes (#6996) * Blockbase: Remove style variations from child themes Co-authored-by: Jason Crist <jcrist@pbking.com>
- Loading branch information
Showing
5 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* Removes the style variations of Blockbase child themes inherited by the parent theme. | ||
* | ||
* @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | ||
* @param array $handler Route handler used for the request. | ||
* | ||
* @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed Result to send to the client. | ||
*/ | ||
function blockbase_remove_style_variations_from_child_themes( $response, $handler ) { | ||
if ( ! isset( $handler['callback'] ) || ! is_array( $handler['callback'] ) ) { | ||
return $response; | ||
} | ||
|
||
$handler_class = isset( $handler['callback'][0] ) ? $handler['callback'][0] : null; | ||
$handler_method = isset( $handler['callback'][1] ) ? $handler['callback'][1] : null; | ||
$opt_out = wp_get_global_settings( array( 'custom', 'optOutOfParentStyleVariations' ) ); | ||
|
||
/* | ||
* Prevents Blockbase child themes from being considered child themes in the | ||
* `wp/v2/global-styles/themes/:theme/variations` API endpoint, so they don't | ||
* inherit the style variations from the parent theme. | ||
*/ | ||
if ( $opt_out && is_a( $handler_class, 'WP_REST_Global_Styles_Controller' ) && 'get_theme_items' === $handler_method ) { | ||
add_filter( 'template_directory', 'get_stylesheet_directory' ); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
add_filter( 'rest_request_before_callbacks', 'blockbase_remove_style_variations_from_child_themes', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ | |
] | ||
}, | ||
"custom": { | ||
"optOutOfParentStyleVariations": false, | ||
"alignment": { | ||
"alignedMaxWidth": "50%" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters