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

Expose layout values from theme.json as css-variables #30081

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
if ( $content_size || $wide_size ) {
ob_start();
?>
<?php echo '.wp-container-' . $id; ?> {
--wp--layout--content-size: <?php echo $content_size ? $content_size : 'var(--wp--layout--wide-size)'; ?>;
--wp--layout--wide-size: <?php echo $wide_size ? $wide_size : 'var(--wp--layout--content-size)'; ?>;
aristath marked this conversation as resolved.
Show resolved Hide resolved
}
<?php echo '.wp-container-' . $id; ?> > * {
max-width: <?php echo $content_size ? $content_size : $wide_size; ?>;
max-width: var(--wp--layout--content-size);
margin-left: auto;
margin-right: auto;
}

<?php echo '.wp-container-' . $id; ?> > .alignwide {
max-width: <?php echo $wide_size ? $wide_size : $content_size; ?>;
max-width: var(--wp-layout--wide-size);
}

<?php echo '.wp-container-' . $id; ?> .alignfull {
Expand Down
16 changes: 7 additions & 9 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,13 @@ private static function compute_preset_vars( $declarations, $settings ) {
* @return array Returns the modified $declarations.
*/
private static function compute_theme_vars( $declarations, $settings ) {
foreach ( array( 'layout', 'custom' ) as $tree ) {
$values = _wp_array_get( $settings, array( $tree ), array() );
$css_vars = self::flatten_tree( $values );
foreach ( $css_vars as $key => $value ) {
$declarations[] = array(
'name' => '--wp--' . $tree . '--' . $key,
'value' => $value,
);
}
$custom_values = _wp_array_get( $settings, array( 'custom' ), array() );
$css_vars = self::flatten_tree( $custom_values );
foreach ( $css_vars as $key => $value ) {
$declarations[] = array(
'name' => '--wp--custom--' . $key,
'value' => $value,
);
}

return $declarations;
Expand Down