Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockbase: Remove inherited style variations from child themes #6996

Merged
merged 6 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blockbase/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function blockbase_scripts() {
}

require get_template_directory() . '/inc/fonts/custom-fonts.php';
require get_template_directory() . '/inc/rest-api.php';


// Force menus to reload
Expand Down
32 changes: 32 additions & 0 deletions blockbase/inc/rest-api.php
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 );
1 change: 1 addition & 0 deletions blockbase/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
]
},
"custom": {
"optOutOfParentStyleVariations": false,
"alignment": {
"alignedMaxWidth": "50%"
},
Expand Down
3 changes: 2 additions & 1 deletion jackson/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"primary": "var(--wp--preset--color--foreground)",
"secondary": "var(--wp--preset--color--foreground)",
"tertiary": "var(--wp--preset--color--background)"
}
},
"optOutOfParentStyleVariations": true
}
},
"styles": {
Expand Down
3 changes: 2 additions & 1 deletion kingsley/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"primary": "var(--wp--preset--color--foreground)",
"secondary": "var(--wp--preset--color--foreground)",
"tertiary": "var(--wp--preset--color--background)"
}
},
"optOutOfParentStyleVariations": true
}
},
"styles": {
Expand Down