Skip to content

Commit

Permalink
Skeleton for filtering theme.json for classic themes at all layers
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Sep 19, 2022
1 parent 9054a39 commit c8f3451
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/compat/wordpress-6.1/hook-theme-json-for-classic-themes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

function theme_json_current_theme_has_support( ){
return WP_Theme_JSON_Gutenberg::has_theme_support();
}

function theme_json_default_filter_for_classic_themes( $theme_json_data ) {
if ( theme_json_current_theme_has_support() ) {
$new_data = array(
'version' => 2,
'settings' => array( /* we should maintain the presets by core */ ),
'styles' => array( /* clear this? add only the base-layout-styles? */ ),
);
$theme_json_data->update_with( $new_data );
}
return $theme_json_data;
}
add_filter( 'theme_json_default', 'theme_json_default_filter_for_classic_themes');

function theme_json_blocks_filter_for_classic_themes( $theme_json_data ) {
if ( theme_json_current_theme_has_support() ) {
$new_data = array(
'version' => 2,
'settings' => array(),
'styles' => array( /* add button styles for classic here */ ),
);
$theme_json_data->update_with( $new_data );
}
return $theme_json_data;
}
add_filter( 'theme_json_blocks', 'theme_json_blocks_filter_for_classic_themes' );

function theme_json_reset_for_classic_themes( $theme_json_data ) {
if ( theme_json_current_theme_has_support() ) {
$new_data = array(
'version' => 2,
'settings' => array(),
'styles' => array(),
);
$theme_json_data->update_with( $new_data );
}

return $theme_json_data;
}
add_filter( 'theme_json_theme', 'theme_json_reset_for_classic_themes' );
add_filter( 'theme_json_user', 'theme_json_reset_for_classic_themes' );

0 comments on commit c8f3451

Please sign in to comment.