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

Convert theme.json to theme-json.php for better performance. #4641

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions Gruntfile.js
Expand Up @@ -1462,6 +1462,14 @@ module.exports = function(grunt) {
);
} );

grunt.registerTask( 'copy:theme-json', 'Copies theme.json file contents to theme-json.php.', function() {
var themeData = grunt.file.readJSON( SOURCE_DIR + 'wp-includes/theme.json' );
grunt.file.write(
SOURCE_DIR + 'wp-includes/theme-json.php',
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
'<?php return ' + json2php( themeData ) + ';'
);
} );

grunt.registerTask( 'copy:js', [
'copy:npm-packages',
'copy:vendor-js',
Expand Down Expand Up @@ -1511,6 +1519,7 @@ module.exports = function(grunt) {
'clean:files',
'copy:files',
'copy:block-json',
'copy:theme-json',
'copy:version',
] );

Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Expand Up @@ -121,6 +121,7 @@
<exclude-pattern>/src/wp-includes/ms-deprecated\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/pluggable-deprecated\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/rss\.php</exclude-pattern>
<exclude-pattern>/src/wp-includes/theme-json\.php</exclude-pattern>
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved

<exclude-pattern>/src/wp-includes/assets/*</exclude-pattern>
<exclude-pattern>/src/wp-includes/blocks/*</exclude-pattern>
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-theme-json-resolver.php
Expand Up @@ -162,7 +162,7 @@ public static function get_core_data() {
return static::$core;
}

$config = static::read_json_file( __DIR__ . '/theme.json' );
$config = require __DIR__ . '/theme-json.php';
$config = static::translate( $config );

/**
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/theme-json.php
@@ -0,0 +1 @@
<?php return array('version' => 2, 'settings' => array('appearanceTools' => false, 'useRootPaddingAwareAlignments' => false, 'border' => array('color' => false, 'radius' => false, 'style' => false, 'width' => false), 'color' => array('background' => true, 'custom' => true, 'customDuotone' => true, 'customGradient' => true, 'defaultDuotone' => true, 'defaultGradients' => true, 'defaultPalette' => true, 'duotone' => array(array('name' => 'Dark grayscale', 'colors' => array('#000000', '#7f7f7f'), 'slug' => 'dark-grayscale'), array('name' => 'Grayscale', 'colors' => array('#000000', '#ffffff'), 'slug' => 'grayscale'), array('name' => 'Purple and yellow', 'colors' => array('#8c00b7', '#fcff41'), 'slug' => 'purple-yellow'), array('name' => 'Blue and red', 'colors' => array('#000097', '#ff4747'), 'slug' => 'blue-red'), array('name' => 'Midnight', 'colors' => array('#000000', '#00a5ff'), 'slug' => 'midnight'), array('name' => 'Magenta and yellow', 'colors' => array('#c7005a', '#fff278'), 'slug' => 'magenta-yellow'), array('name' => 'Purple and green', 'colors' => array('#a60072', '#67ff66'), 'slug' => 'purple-green'), array('name' => 'Blue and orange', 'colors' => array('#1900d8', '#ffa96b'), 'slug' => 'blue-orange')), 'gradients' => array(array('name' => 'Vivid cyan blue to vivid purple', 'gradient' => 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)', 'slug' => 'vivid-cyan-blue-to-vivid-purple'), array('name' => 'Light green cyan to vivid green cyan', 'gradient' => 'linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%)', 'slug' => 'light-green-cyan-to-vivid-green-cyan'), array('name' => 'Luminous vivid amber to luminous vivid orange', 'gradient' => 'linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%)', 'slug' => 'luminous-vivid-amber-to-luminous-vivid-orange'), array('name' => 'Luminous vivid orange to vivid red', 'gradient' => 'linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%)', 'slug' => 'luminous-vivid-orange-to-vivid-red'), array('name' => 'Very light gray to cyan bluish gray', 'gradient' => 'linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%)', 'slug' => 'very-light-gray-to-cyan-bluish-gray'), array('name' => 'Cool to warm spectrum', 'gradient' => 'linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)', 'slug' => 'cool-to-warm-spectrum'), array('name' => 'Blush light purple', 'gradient' => 'linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%)', 'slug' => 'blush-light-purple'), array('name' => 'Blush bordeaux', 'gradient' => 'linear-gradient(135deg,rgb(254,205,165) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%)', 'slug' => 'blush-bordeaux'), array('name' => 'Luminous dusk', 'gradient' => 'linear-gradient(135deg,rgb(255,203,112) 0%,rgb(199,81,192) 50%,rgb(65,88,208) 100%)', 'slug' => 'luminous-dusk'), array('name' => 'Pale ocean', 'gradient' => 'linear-gradient(135deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%)', 'slug' => 'pale-ocean'), array('name' => 'Electric grass', 'gradient' => 'linear-gradient(135deg,rgb(202,248,128) 0%,rgb(113,206,126) 100%)', 'slug' => 'electric-grass'), array('name' => 'Midnight', 'gradient' => 'linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%)', 'slug' => 'midnight')), 'link' => false, 'palette' => array(array('name' => 'Black', 'slug' => 'black', 'color' => '#000000'), array('name' => 'Cyan bluish gray', 'slug' => 'cyan-bluish-gray', 'color' => '#abb8c3'), array('name' => 'White', 'slug' => 'white', 'color' => '#ffffff'), array('name' => 'Pale pink', 'slug' => 'pale-pink', 'color' => '#f78da7'), array('name' => 'Vivid red', 'slug' => 'vivid-red', 'color' => '#cf2e2e'), array('name' => 'Luminous vivid orange', 'slug' => 'luminous-vivid-orange', 'color' => '#ff6900'), array('name' => 'Luminous vivid amber', 'slug' => 'luminous-vivid-amber', 'color' => '#fcb900'), array('name' => 'Light green cyan', 'slug' => 'light-green-cyan', 'color' => '#7bdcb5'), array('name' => 'Vivid green cyan', 'slug' => 'vivid-green-cyan', 'color' => '#00d084'), array('name' => 'Pale cyan blue', 'slug' => 'pale-cyan-blue', 'color' => '#8ed1fc'), array('name' => 'Vivid cyan blue', 'slug' => 'vivid-cyan-blue', 'color' => '#0693e3'), array('name' => 'Vivid purple', 'slug' => 'vivid-purple', 'color' => '#9b51e0')), 'text' => true), 'layout' => array('definitions' => array('default' => array('name' => 'default', 'slug' => 'flow', 'className' => 'is-layout-flow', 'baseStyles' => array(array('selector' => ' > .alignleft', 'rules' => array('float' => 'left', 'margin-inline-start' => '0', 'margin-inline-end' => '2em')), array('selector' => ' > .alignright', 'rules' => array('float' => 'right', 'margin-inline-start' => '2em', 'margin-inline-end' => '0')), array('selector' => ' > .aligncenter', 'rules' => array('margin-left' => 'auto !important', 'margin-right' => 'auto !important'))), 'spacingStyles' => array(array('selector' => ' > *', 'rules' => array('margin-block-start' => '0', 'margin-block-end' => '0')), array('selector' => ' > * + *', 'rules' => array('margin-block-start' => null, 'margin-block-end' => '0')))), 'constrained' => array('name' => 'constrained', 'slug' => 'constrained', 'className' => 'is-layout-constrained', 'baseStyles' => array(array('selector' => ' > .alignleft', 'rules' => array('float' => 'left', 'margin-inline-start' => '0', 'margin-inline-end' => '2em')), array('selector' => ' > .alignright', 'rules' => array('float' => 'right', 'margin-inline-start' => '2em', 'margin-inline-end' => '0')), array('selector' => ' > .aligncenter', 'rules' => array('margin-left' => 'auto !important', 'margin-right' => 'auto !important')), array('selector' => ' > :where(:not(.alignleft):not(.alignright):not(.alignfull))', 'rules' => array('max-width' => 'var(--wp--style--global--content-size)', 'margin-left' => 'auto !important', 'margin-right' => 'auto !important')), array('selector' => ' > .alignwide', 'rules' => array('max-width' => 'var(--wp--style--global--wide-size)'))), 'spacingStyles' => array(array('selector' => ' > *', 'rules' => array('margin-block-start' => '0', 'margin-block-end' => '0')), array('selector' => ' > * + *', 'rules' => array('margin-block-start' => null, 'margin-block-end' => '0')))), 'flex' => array('name' => 'flex', 'slug' => 'flex', 'className' => 'is-layout-flex', 'displayMode' => 'flex', 'baseStyles' => array(array('selector' => '', 'rules' => array('flex-wrap' => 'wrap', 'align-items' => 'center')), array('selector' => ' > *', 'rules' => array('margin' => '0'))), 'spacingStyles' => array(array('selector' => '', 'rules' => array('gap' => null)))))), 'shadow' => array('defaultPresets' => true, 'presets' => array(array('name' => 'Natural', 'slug' => 'natural', 'shadow' => '6px 6px 9px rgba(0, 0, 0, 0.2)'), array('name' => 'Deep', 'slug' => 'deep', 'shadow' => '12px 12px 50px rgba(0, 0, 0, 0.4)'), array('name' => 'Sharp', 'slug' => 'sharp', 'shadow' => '6px 6px 0px rgba(0, 0, 0, 0.2)'), array('name' => 'Outlined', 'slug' => 'outlined', 'shadow' => '6px 6px 0px -3px rgba(255, 255, 255, 1), 6px 6px rgba(0, 0, 0, 1)'), array('name' => 'Crisp', 'slug' => 'crisp', 'shadow' => '6px 6px 0px rgba(0, 0, 0, 1)'))), 'spacing' => array('blockGap' => null, 'margin' => false, 'padding' => false, 'customSpacingSize' => true, 'units' => array('px', 'em', 'rem', 'vh', 'vw', '%'), 'spacingScale' => array('operator' => '*', 'increment' => 1.5, 'steps' => 7, 'mediumStep' => 1.5, 'unit' => 'rem')), 'typography' => array('customFontSize' => true, 'dropCap' => true, 'fontSizes' => array(array('name' => 'Small', 'slug' => 'small', 'size' => '13px'), array('name' => 'Medium', 'slug' => 'medium', 'size' => '20px'), array('name' => 'Large', 'slug' => 'large', 'size' => '36px'), array('name' => 'Extra Large', 'slug' => 'x-large', 'size' => '42px')), 'fontStyle' => true, 'fontWeight' => true, 'letterSpacing' => true, 'lineHeight' => false, 'textDecoration' => true, 'textTransform' => true), 'blocks' => array('core/button' => array('border' => array('radius' => true)), 'core/pullquote' => array('border' => array('color' => true, 'radius' => true, 'style' => true, 'width' => true)))), 'styles' => array('elements' => array('button' => array('color' => array('text' => '#fff', 'background' => '#32373c'), 'spacing' => array('padding' => 'calc(0.667em + 2px) calc(1.333em + 2px)'), 'typography' => array('fontSize' => 'inherit', 'fontFamily' => 'inherit', 'lineHeight' => 'inherit', 'textDecoration' => 'none'), 'border' => array('width' => '0')), 'link' => array('typography' => array('textDecoration' => 'underline'))), 'spacing' => array('blockGap' => '24px', 'padding' => array('top' => '0px', 'right' => '0px', 'bottom' => '0px', 'left' => '0px'))));