<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52746] branches/5.9/src/wp-includes/class-wp-theme-json.php: Themes: Allow extending `WP_Theme_JSON` and `WP_Theme_JSON_Resolver` classes.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52746">52746</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52746","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>audrasjb</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-02-17 11:13:09 +0000 (Thu, 17 Feb 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Themes: Allow extending `WP_Theme_JSON` and `WP_Theme_JSON_Resolver` classes.
This change updates methods visibility from `private` to `protected` and adds late static binding.
Original PRs from Gutenberg repository:
- https://github.com/WordPress/gutenberg/pull/38625
- https://github.com/WordPress/gutenberg/pull/38671
Props oandregal, Mamaduka, kapilpaul.
Merges <a href="https://core.trac.wordpress.org/changeset/52744">[52744]</a> to the 5.9 branch.
Fixes <a href="https://core.trac.wordpress.org/ticket/55178">#55178</a>.
See <a href="https://core.trac.wordpress.org/ticket/55179">#55179</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches59srcwpincludesclasswpthemejsonresolverphp">branches/5.9/src/wp-includes/class-wp-theme-json-resolver.php</a></li>
<li><a href="#branches59srcwpincludesclasswpthemejsonphp">branches/5.9/src/wp-includes/class-wp-theme-json.php</a></li>
</ul>
<h3>Property Changed</h3>
<ul>
<li><a href="#branches59">branches/5.9/</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/5.9
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/5.9 2022-02-17 09:09:12 UTC (rev 52745)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/5.9 2022-02-17 11:13:09 UTC (rev 52746)
</ins><a id="branches59"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/5.9</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43747,43751-43754,43758,43760-43765,43767-43770,43772,43774-43781,43783,43785,43790-43806,43808-43821,43825,43828,43830-43834,43836-43843,43846-43863,43867-43889,43891-43894,43897-43905,43908-43909,43911-43929,43931-43942,43946-43947,43949-43956,43959-43964,43967-43969,43988,43994,44014,44017,44047,44183,44185,44187-44206,44208-44213,44231-44232,44235,44248,44284,44287-44288
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.5:49373-49379,49381
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.8:51889
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:52453-52457,52535-52536,52547,52555,52558,52562-52563,52574,52589,52612-52613,52618,52626,52628,52631,52633,52637,52644,52648,52651,52656,52658,52662,52664,52668,52672-52673,52675-52677,52679,52681-52682,52686,52695,52697,52726,52730,52733,52735,52738
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:52453-52457,52535-52536,52547,52555,52558,52562-52563,52574,52589,52612-52613,52618,52626,52628,52631,52633,52637,52644,52648,52651,52656,52658,52662,52664,52668,52672-52673,52675-52677,52679,52681-52682,52686,52695,52697,52726,52730,52733,52735,52738,52744
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches59srcwpincludesclasswpthemejsonresolverphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.9/src/wp-includes/class-wp-theme-json-resolver.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.9/src/wp-includes/class-wp-theme-json-resolver.php 2022-02-17 09:09:12 UTC (rev 52745)
+++ branches/5.9/src/wp-includes/class-wp-theme-json-resolver.php 2022-02-17 11:13:09 UTC (rev 52746)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -25,7 +25,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var WP_Theme_JSON
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $core = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $core = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Container for data coming from the theme.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -33,7 +33,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var WP_Theme_JSON
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $theme = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $theme = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether or not the theme supports theme.json.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -41,7 +41,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $theme_has_support = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $theme_has_support = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Container for data coming from the user.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -49,7 +49,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var WP_Theme_JSON
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $user = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $user = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Stores the ID of the custom post type
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -58,7 +58,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var int
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $user_custom_post_type_id = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $user_custom_post_type_id = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Container to keep loaded i18n schema for `theme.json`.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -67,7 +67,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0 Renamed from `$theme_json_i18n` to `$i18n_schema`.
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $i18n_schema = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $i18n_schema = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Processes a file that adheres to the theme.json schema
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,7 +78,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $file_path Path to file. Empty if no file.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Contents that adhere to the theme.json schema.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function read_json_file( $file_path ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function read_json_file( $file_path ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $config = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $file_path ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -113,13 +113,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Default 'default'.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Returns the modified $theme_json_structure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function translate( $theme_json, $domain = 'default' ) {
- if ( null === self::$i18n_schema ) {
- $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
- self::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function translate( $theme_json, $domain = 'default' ) {
+ if ( null === static::$i18n_schema ) {
+ $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
+ static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return translate_settings_using_i18n_schema( self::$i18n_schema, $theme_json, $domain );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -130,15 +130,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Theme_JSON Entity that holds core data.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_core_data() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null !== self::$core ) {
- return self::$core;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( null !== static::$core ) {
+ return static::$core;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $config = self::read_json_file( __DIR__ . '/theme.json' );
- $config = self::translate( $config );
- self::$core = new WP_Theme_JSON( $config, 'default' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $config = static::read_json_file( __DIR__ . '/theme.json' );
+ $config = static::translate( $config );
+ static::$core = new WP_Theme_JSON( $config, 'default' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return self::$core;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return static::$core;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -159,21 +159,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $deprecated ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_argument( __METHOD__, '5.9.0' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null === self::$theme ) {
- $theme_json_data = self::read_json_file( self::get_file_path_from_theme( 'theme.json' ) );
- $theme_json_data = self::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
- self::$theme = new WP_Theme_JSON( $theme_json_data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( null === static::$theme ) {
+ $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) );
+ $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
+ static::$theme = new WP_Theme_JSON( $theme_json_data );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( wp_get_theme()->parent() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Get parent theme.json.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $parent_theme_json_data = self::read_json_file( self::get_file_path_from_theme( 'theme.json', true ) );
- $parent_theme_json_data = self::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) );
+ $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $parent_theme = new WP_Theme_JSON( $parent_theme_json_data );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Merge the child theme.json into the parent theme.json.
</span><span class="cx" style="display: block; padding: 0 10px"> // The child theme takes precedence over the parent.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $parent_theme->merge( self::$theme );
- self::$theme = $parent_theme;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $parent_theme->merge( static::$theme );
+ static::$theme = $parent_theme;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,10 +181,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * We want the presets and settings declared in theme.json
</span><span class="cx" style="display: block; padding: 0 10px"> * to override the ones declared via theme supports.
</span><span class="cx" style="display: block; padding: 0 10px"> * So we take theme supports, transform it to theme.json shape
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * and merge the self::$theme upon that.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * and merge the static::$theme upon that.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! self::theme_has_support() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! static::theme_has_support() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $theme_support_data['settings']['color'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_support_data['settings']['color'] = array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,7 +210,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $with_theme_supports = new WP_Theme_JSON( $theme_support_data );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $with_theme_supports->merge( self::$theme );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $with_theme_supports->merge( static::$theme );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $with_theme_supports;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -299,12 +299,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Theme_JSON Entity that holds styles for user data.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_user_data() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null !== self::$user ) {
- return self::$user;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( null !== static::$user ) {
+ return static::$user;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $config = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user_cpt = self::get_user_data_from_wp_global_styles( wp_get_theme() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( array_key_exists( 'post_content', $user_cpt ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $decoded_data = json_decode( $user_cpt['post_content'], true );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -326,9 +326,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $config = $decoded_data;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$user = new WP_Theme_JSON( $config, 'custom' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$user = new WP_Theme_JSON( $config, 'custom' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return self::$user;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return static::$user;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -363,11 +363,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $result = new WP_Theme_JSON();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result->merge( self::get_core_data() );
- $result->merge( self::get_theme_data() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result->merge( static::get_core_data() );
+ $result->merge( static::get_theme_data() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'custom' === $origin ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result->merge( self::get_user_data() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result->merge( static::get_user_data() );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $result;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -382,17 +382,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return integer|null
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_user_global_styles_post_id() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null !== self::$user_custom_post_type_id ) {
- return self::$user_custom_post_type_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( null !== static::$user_custom_post_type_id ) {
+ return static::$user_custom_post_type_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user_cpt = self::get_user_data_from_wp_global_styles( wp_get_theme(), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme(), true );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( array_key_exists( 'ID', $user_cpt ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$user_custom_post_type_id = $user_cpt['ID'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$user_custom_post_type_id = $user_cpt['ID'];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return self::$user_custom_post_type_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return static::$user_custom_post_type_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -404,14 +404,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function theme_has_support() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! isset( self::$theme_has_support ) ) {
- self::$theme_has_support = (
- is_readable( self::get_file_path_from_theme( 'theme.json' ) ) ||
- is_readable( self::get_file_path_from_theme( 'theme.json', true ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( static::$theme_has_support ) ) {
+ static::$theme_has_support = (
+ is_readable( static::get_file_path_from_theme( 'theme.json' ) ) ||
+ is_readable( static::get_file_path_from_theme( 'theme.json', true ) )
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return self::$theme_has_support;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return static::$theme_has_support;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -426,7 +426,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $template Optional. Use template theme directory. Default false.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The whole file path or empty if the file doesn't exist.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_file_path_from_theme( $file_name, $template = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_file_path_from_theme( $file_name, $template = false ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $path = $template ? get_template_directory() : get_stylesheet_directory();
</span><span class="cx" style="display: block; padding: 0 10px"> $candidate = $path . '/' . $file_name;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -441,12 +441,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * and `$i18n_schema` variables to reset.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function clean_cached_data() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$core = null;
- self::$theme = null;
- self::$user = null;
- self::$user_custom_post_type_id = null;
- self::$theme_has_support = null;
- self::$i18n_schema = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$core = null;
+ static::$theme = null;
+ static::$user = null;
+ static::$user_custom_post_type_id = null;
+ static::$theme_has_support = null;
+ static::$i18n_schema = null;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="branches59srcwpincludesclasswpthemejsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.9/src/wp-includes/class-wp-theme-json.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.9/src/wp-includes/class-wp-theme-json.php 2022-02-17 09:09:12 UTC (rev 52745)
+++ branches/5.9/src/wp-includes/class-wp-theme-json.php 2022-02-17 11:13:09 UTC (rev 52746)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -24,7 +24,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private $theme_json = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $theme_json = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Holds block metadata extracted from block.json
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,7 +34,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $blocks_metadata = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $blocks_metadata = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * The CSS selector for the top-level styles.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -366,20 +366,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * One of 'default', 'theme', or 'custom'. Default 'theme'.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function __construct( $theme_json = array(), $origin = 'theme' ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! in_array( $origin, self::VALID_ORIGINS, true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $origin = 'theme';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $valid_block_names = array_keys( self::get_blocks_metadata() );
- $valid_element_names = array_keys( self::ELEMENTS );
- $theme_json = self::sanitize( $this->theme_json, $valid_block_names, $valid_element_names );
- $this->theme_json = self::maybe_opt_in_into_settings( $theme_json );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $valid_block_names = array_keys( static::get_blocks_metadata() );
+ $valid_element_names = array_keys( static::ELEMENTS );
+ $theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names );
+ $this->theme_json = static::maybe_opt_in_into_settings( $theme_json );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Internally, presets are keyed by origin.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $nodes = self::get_setting_nodes( $this->theme_json );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $nodes = static::get_setting_nodes( $this->theme_json );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $nodes as $node ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::PRESETS_METADATA as $preset_metadata ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::PRESETS_METADATA as $preset_metadata ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $path = array_merge( $node['path'], $preset_metadata['path'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $preset = _wp_array_get( $this->theme_json, $path, null );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( null !== $preset ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -400,7 +400,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $theme_json A theme.json structure to modify.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array The modified theme.json structure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function maybe_opt_in_into_settings( $theme_json ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function maybe_opt_in_into_settings( $theme_json ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $new_theme_json = $theme_json;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if (
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -407,13 +407,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> isset( $new_theme_json['settings']['appearanceTools'] ) &&
</span><span class="cx" style="display: block; padding: 0 10px"> true === $new_theme_json['settings']['appearanceTools']
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::do_opt_in_into_settings( $new_theme_json['settings'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::do_opt_in_into_settings( $new_theme_json['settings'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $new_theme_json['settings']['blocks'] ) && is_array( $new_theme_json['settings']['blocks'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $new_theme_json['settings']['blocks'] as &$block ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $block['appearanceTools'] ) && ( true === $block['appearanceTools'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::do_opt_in_into_settings( $block );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::do_opt_in_into_settings( $block );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -428,7 +428,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $context The context to which the settings belong.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function do_opt_in_into_settings( &$context ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function do_opt_in_into_settings( &$context ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $to_opt_in = array(
</span><span class="cx" style="display: block; padding: 0 10px"> array( 'border', 'color' ),
</span><span class="cx" style="display: block; padding: 0 10px"> array( 'border', 'radius' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -463,7 +463,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $valid_element_names List of valid element names.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array The sanitized output.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function sanitize( $input, $valid_block_names, $valid_element_names ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function sanitize( $input, $valid_block_names, $valid_element_names ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $output = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $input ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -470,11 +470,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $output;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $output = array_intersect_key( $input, array_flip( self::VALID_TOP_LEVEL_KEYS ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $output = array_intersect_key( $input, array_flip( static::VALID_TOP_LEVEL_KEYS ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Some styles are only meant to be available at the top-level (e.g.: blockGap),
</span><span class="cx" style="display: block; padding: 0 10px"> // hence, the schema for blocks & elements should not have them.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $styles_non_top_level = self::VALID_STYLES;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $styles_non_top_level = static::VALID_STYLES;
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( array_keys( $styles_non_top_level ) as $section ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( array_keys( $styles_non_top_level[ $section ] ) as $prop ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'top' === $styles_non_top_level[ $section ][ $prop ] ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -492,14 +492,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $schema_styles_blocks = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $schema_settings_blocks = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $valid_block_names as $block ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $schema_settings_blocks[ $block ] = self::VALID_SETTINGS;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $schema_settings_blocks[ $block ] = static::VALID_SETTINGS;
</ins><span class="cx" style="display: block; padding: 0 10px"> $schema_styles_blocks[ $block ] = $styles_non_top_level;
</span><span class="cx" style="display: block; padding: 0 10px"> $schema_styles_blocks[ $block ]['elements'] = $schema_styles_elements;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $schema['styles'] = self::VALID_STYLES;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $schema['styles'] = static::VALID_STYLES;
</ins><span class="cx" style="display: block; padding: 0 10px"> $schema['styles']['blocks'] = $schema_styles_blocks;
</span><span class="cx" style="display: block; padding: 0 10px"> $schema['styles']['elements'] = $schema_styles_elements;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $schema['settings'] = self::VALID_SETTINGS;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $schema['settings'] = static::VALID_SETTINGS;
</ins><span class="cx" style="display: block; padding: 0 10px"> $schema['settings']['blocks'] = $schema_settings_blocks;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Remove anything that's not present in the schema.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -513,7 +513,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = self::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = static::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $result ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $output[ $subtree ] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -554,12 +554,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Block metadata.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_blocks_metadata() {
- if ( null !== self::$blocks_metadata ) {
- return self::$blocks_metadata;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_blocks_metadata() {
+ if ( null !== static::$blocks_metadata ) {
+ return static::$blocks_metadata;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$blocks_metadata = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$blocks_metadata = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $registry = WP_Block_Type_Registry::get_instance();
</span><span class="cx" style="display: block; padding: 0 10px"> $blocks = $registry->get_all_registered();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -568,9 +568,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> isset( $block_type->supports['__experimentalSelector'] ) &&
</span><span class="cx" style="display: block; padding: 0 10px"> is_string( $block_type->supports['__experimentalSelector'] )
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector'];
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if (
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -577,23 +577,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> isset( $block_type->supports['color']['__experimentalDuotone'] ) &&
</span><span class="cx" style="display: block; padding: 0 10px"> is_string( $block_type->supports['color']['__experimentalDuotone'] )
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone'];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Assign defaults, then overwrite those that the block sets by itself.
</span><span class="cx" style="display: block; padding: 0 10px"> // If the block selector is compounded, will append the element to each
</span><span class="cx" style="display: block; padding: 0 10px"> // individual block selector.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $block_selectors = explode( ',', self::$blocks_metadata[ $block_name ]['selector'] );
- foreach ( self::ELEMENTS as $el_name => $el_selector ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $block_selectors = explode( ',', static::$blocks_metadata[ $block_name ]['selector'] );
+ foreach ( static::ELEMENTS as $el_name => $el_selector ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $element_selector = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $block_selectors as $selector ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $element_selector[] = $selector . ' ' . $el_selector;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return self::$blocks_metadata;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return static::$blocks_metadata;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -607,7 +607,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $schema Schema to adhere to.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Returns the modified $tree.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function remove_keys_not_in_schema( $tree, $schema ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function remove_keys_not_in_schema( $tree, $schema ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $tree = array_intersect_key( $tree, $schema );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $schema as $key => $data ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -616,7 +616,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_array( $schema[ $key ] ) && is_array( $tree[ $key ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $tree[ $key ] = self::remove_keys_not_in_schema( $tree[ $key ], $schema[ $key ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $tree[ $key ] = static::remove_keys_not_in_schema( $tree[ $key ], $schema[ $key ] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $tree[ $key ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $tree[ $key ] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -670,10 +670,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * - `variables`: only the CSS Custom Properties for presets & custom ones.
</span><span class="cx" style="display: block; padding: 0 10px"> * - `styles`: only the styles section in theme.json.
</span><span class="cx" style="display: block; padding: 0 10px"> * - `presets`: only the classes for the presets.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $origins A list of origins to include. By default it includes `self::VALID_ORIGINS`.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $origins A list of origins to include. By default it includes VALID_ORIGINS.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string Stylesheet.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = self::VALID_ORIGINS ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null ) {
+ if ( null === $origins ) {
+ $origins = static::VALID_ORIGINS;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_string( $types ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Dispatch error and map old arguments to new ones.
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_argument( __FUNCTION__, '5.9.0' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -686,9 +690,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $blocks_metadata = self::get_blocks_metadata();
- $style_nodes = self::get_style_nodes( $this->theme_json, $blocks_metadata );
- $setting_nodes = self::get_setting_nodes( $this->theme_json, $blocks_metadata );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $blocks_metadata = static::get_blocks_metadata();
+ $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata );
+ $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $stylesheet = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -775,7 +779,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $style_nodes Nodes with styles.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The new stylesheet.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function get_block_classes( $style_nodes ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function get_block_classes( $style_nodes ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $block_rules = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $style_nodes as $metadata ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -786,7 +790,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $node = _wp_array_get( $this->theme_json, $metadata['path'], array() );
</span><span class="cx" style="display: block; padding: 0 10px"> $selector = $metadata['selector'];
</span><span class="cx" style="display: block; padding: 0 10px"> $settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $declarations = self::compute_style_properties( $node, $settings );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $declarations = static::compute_style_properties( $node, $settings );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // 1. Separate the ones who use the general selector
</span><span class="cx" style="display: block; padding: 0 10px"> // and the ones who use the duotone selector.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -806,20 +810,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * user-generated values take precedence in the CSS cascade.
</span><span class="cx" style="display: block; padding: 0 10px"> * @link https://github.com/WordPress/gutenberg/issues/36147.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $block_rules .= 'body { margin: 0; }';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // 2. Generate the rules that use the general selector.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $block_rules .= self::to_ruleset( $selector, $declarations );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $block_rules .= static::to_ruleset( $selector, $declarations );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // 3. Generate the rules that use the duotone selector.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $metadata['duotone'] ) && ! empty( $declarations_duotone ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $selector_duotone = self::scope_selector( $metadata['selector'], $metadata['duotone'] );
- $block_rules .= self::to_ruleset( $selector_duotone, $declarations_duotone );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $selector_duotone = static::scope_selector( $metadata['selector'], $metadata['duotone'] );
+ $block_rules .= static::to_ruleset( $selector_duotone, $declarations_duotone );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $block_rules .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
</span><span class="cx" style="display: block; padding: 0 10px"> $block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
</span><span class="cx" style="display: block; padding: 0 10px"> $block_rules .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -864,7 +868,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $origins List of origins to process presets from.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The new stylesheet.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function get_preset_classes( $setting_nodes, $origins ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function get_preset_classes( $setting_nodes, $origins ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $preset_rules = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $setting_nodes as $metadata ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -874,7 +878,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $selector = $metadata['selector'];
</span><span class="cx" style="display: block; padding: 0 10px"> $node = _wp_array_get( $this->theme_json, $metadata['path'], array() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $preset_rules .= self::compute_preset_classes( $node, $selector, $origins );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $preset_rules .= static::compute_preset_classes( $node, $selector, $origins );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $preset_rules;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -901,7 +905,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $origins List of origins to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The new stylesheet.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function get_css_variables( $nodes, $origins ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function get_css_variables( $nodes, $origins ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $stylesheet = '';
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $nodes as $metadata ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( null === $metadata['selector'] ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -911,9 +915,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $selector = $metadata['selector'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $node = _wp_array_get( $this->theme_json, $metadata['path'], array() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $declarations = array_merge( self::compute_preset_vars( $node, $origins ), self::compute_theme_vars( $node ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $declarations = array_merge( static::compute_preset_vars( $node, $origins ), static::compute_theme_vars( $node ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stylesheet .= self::to_ruleset( $selector, $declarations );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $stylesheet .= static::to_ruleset( $selector, $declarations );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $stylesheet;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -929,7 +933,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $declarations List of declarations.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string CSS ruleset.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function to_ruleset( $selector, $declarations ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function to_ruleset( $selector, $declarations ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $declarations ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -957,7 +961,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $to_append Selector to append.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function append_to_selector( $selector, $to_append ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function append_to_selector( $selector, $to_append ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $new_selectors = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $selectors = explode( ',', $selector );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $selectors as $sel ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -979,8 +983,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $origins List of origins to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The result of processing the presets.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function compute_preset_classes( $settings, $selector, $origins ) {
- if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function compute_preset_classes( $settings, $selector, $origins ) {
+ if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Classes at the global level do not need any CSS prefixed,
</span><span class="cx" style="display: block; padding: 0 10px"> // and we don't want to increase its specificity.
</span><span class="cx" style="display: block; padding: 0 10px"> $selector = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -987,14 +991,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $stylesheet = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::PRESETS_METADATA as $preset_metadata ) {
- $slugs = self::get_settings_slugs( $settings, $preset_metadata, $origins );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::PRESETS_METADATA as $preset_metadata ) {
+ $slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $preset_metadata['classes'] as $class => $property ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $slugs as $slug ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $css_var = self::replace_slug_in_string( $preset_metadata['css_vars'], $slug );
- $class_name = self::replace_slug_in_string( $class, $slug );
- $stylesheet .= self::to_ruleset(
- self::append_to_selector( $selector, $class_name ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug );
+ $class_name = static::replace_slug_in_string( $class, $slug );
+ $stylesheet .= static::to_ruleset(
+ static::append_to_selector( $selector, $class_name ),
</ins><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => $property,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1026,7 +1030,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $selector Original selector.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string Scoped selector.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function scope_selector( $scope, $selector ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function scope_selector( $scope, $selector ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $scopes = explode( ',', $scope );
</span><span class="cx" style="display: block; padding: 0 10px"> $selectors = explode( ',', $selector );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1076,7 +1080,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $origins List of origins to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of presets where each key is a slug and each value is the preset value.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $result = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1118,7 +1122,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $origins List of origins to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of presets where the key and value are both the slug.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_settings_slugs( $settings, $preset_metadata, $origins = self::VALID_ORIGINS ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_settings_slugs( $settings, $preset_metadata, $origins = null ) {
+ if ( null === $origins ) {
+ $origins = static::VALID_ORIGINS;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $result = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1145,7 +1153,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug The slug value to use to generate the custom property.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The CSS Custom Property. Something along the lines of `--wp--preset--color--black`.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function replace_slug_in_string( $input, $slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function replace_slug_in_string( $input, $slug ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return strtr( $input, array( '$slug' => $slug ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1166,13 +1174,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $origins List of origins to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Returns the modified $declarations.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function compute_preset_vars( $settings, $origins ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function compute_preset_vars( $settings, $origins ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $declarations = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::PRESETS_METADATA as $preset_metadata ) {
- $values_by_slug = self::get_settings_values_by_slug( $settings, $preset_metadata, $origins );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::PRESETS_METADATA as $preset_metadata ) {
+ $values_by_slug = static::get_settings_values_by_slug( $settings, $preset_metadata, $origins );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $values_by_slug as $slug => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $declarations[] = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'name' => self::replace_slug_in_string( $preset_metadata['css_vars'], $slug ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'name' => static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'value' => $value,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1196,10 +1204,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $settings Settings to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Returns the modified $declarations.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function compute_theme_vars( $settings ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function compute_theme_vars( $settings ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $declarations = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $custom_values = _wp_array_get( $settings, array( 'custom' ), array() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $css_vars = self::flatten_tree( $custom_values );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $css_vars = static::flatten_tree( $custom_values );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $css_vars as $key => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $declarations[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => '--wp--custom--' . $key,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1247,7 +1255,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $token Optional. Token to use between levels. Default '--'.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array The flattened tree.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function flatten_tree( $tree, $prefix = '', $token = '--' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function flatten_tree( $tree, $prefix = '', $token = '--' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result = array();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $tree as $property => $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $new_key = $prefix . str_replace(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1260,7 +1268,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $new_prefix = $new_key . $token;
</span><span class="cx" style="display: block; padding: 0 10px"> $result = array_merge(
</span><span class="cx" style="display: block; padding: 0 10px"> $result,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::flatten_tree( $value, $new_prefix, $token )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static::flatten_tree( $value, $new_prefix, $token )
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $result[ $new_key ] = $value;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1286,7 +1294,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $properties Properties metadata.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Returns the modified $declarations.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function compute_style_properties( $styles, $settings = array(), $properties = self::PROPERTIES_METADATA ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function compute_style_properties( $styles, $settings = array(), $properties = null ) {
+ if ( null === $properties ) {
+ $properties = static::PROPERTIES_METADATA;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $declarations = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $styles ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $declarations;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1293,7 +1305,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $properties as $css_property => $value_path ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = self::get_property_value( $styles, $value_path );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = static::get_property_value( $styles, $value_path );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Look up protected properties, keyed by value path.
</span><span class="cx" style="display: block; padding: 0 10px"> // Skip protected properties that are explicitly set to `null`.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1300,8 +1312,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_array( $value_path ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $path_string = implode( '.', $value_path );
</span><span class="cx" style="display: block; padding: 0 10px"> if (
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array_key_exists( $path_string, self::PROTECTED_PROPERTIES ) &&
- _wp_array_get( $settings, self::PROTECTED_PROPERTIES[ $path_string ], null ) === null
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) &&
+ _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
</ins><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1336,7 +1348,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $path Which property to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string|array Style property value.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_property_value( $styles, $path ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_property_value( $styles, $path ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $value = _wp_array_get( $styles, $path, '' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' === $value || is_array( $value ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1379,7 +1391,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $selectors List of selectors per block.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_setting_nodes( $theme_json, $selectors = array() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_setting_nodes( $theme_json, $selectors = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $nodes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $theme_json['settings'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $nodes;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1388,7 +1400,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Top-level.
</span><span class="cx" style="display: block; padding: 0 10px"> $nodes[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'settings' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'selector' => self::ROOT_BLOCK_SELECTOR,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'selector' => static::ROOT_BLOCK_SELECTOR,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Calculate paths for blocks.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1433,7 +1445,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $selectors List of selectors per block.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_style_nodes( $theme_json, $selectors = array() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_style_nodes( $theme_json, $selectors = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $nodes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $theme_json['styles'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $nodes;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1442,7 +1454,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Top-level.
</span><span class="cx" style="display: block; padding: 0 10px"> $nodes[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'styles' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'selector' => self::ROOT_BLOCK_SELECTOR,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'selector' => static::ROOT_BLOCK_SELECTOR,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $theme_json['styles']['elements'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1449,7 +1461,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $theme_json['styles']['elements'] as $element => $node ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $nodes[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'styles', 'elements', $element ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'selector' => self::ELEMENTS[ $element ],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'selector' => static::ELEMENTS[ $element ],
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1523,10 +1535,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * with the equivalent dfefault presets: if a slug is present as a default
</span><span class="cx" style="display: block; padding: 0 10px"> * we remove it from the theme presets.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $nodes = self::get_setting_nodes( $incoming_data );
- $slugs_global = self::get_default_slugs( $this->theme_json, array( 'settings' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $nodes = static::get_setting_nodes( $incoming_data );
+ $slugs_global = static::get_default_slugs( $this->theme_json, array( 'settings' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $nodes as $node ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $slugs_node = self::get_default_slugs( $this->theme_json, $node['path'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> $slugs = array_merge_recursive( $slugs_global, $slugs_node );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Replace the spacing.units.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1537,10 +1549,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Replace the presets.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::PRESETS_METADATA as $preset ) {
- $override_preset = self::should_override_preset( $this->theme_json, $node['path'], $preset['override'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::PRESETS_METADATA as $preset ) {
+ $override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['override'] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::VALID_ORIGINS as $origin ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::VALID_ORIGINS as $origin ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $base_path = array_merge( $node['path'], $preset['path'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $path = array_merge( $base_path, array( $origin ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $content = _wp_array_get( $incoming_data, $path, null );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1551,7 +1563,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'theme' === $origin && $preset['use_default_names'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $content as &$item ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! array_key_exists( 'name', $item ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $name = self::get_name_from_defaults( $item['slug'], $base_path );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $name = static::get_name_from_defaults( $item['slug'], $base_path );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( null !== $name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $item['name'] = $name;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1566,7 +1578,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> _wp_array_set( $this->theme_json, $path, $content );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $slugs_for_preset = _wp_array_get( $slugs, $preset['path'], array() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $content = self::filter_slugs( $content, $slugs_for_preset );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $content = static::filter_slugs( $content, $slugs_for_preset );
</ins><span class="cx" style="display: block; padding: 0 10px"> _wp_array_set( $this->theme_json, $path, $content );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1584,7 +1596,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool|array $override Data to compute whether to override the preset.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return boolean
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function should_override_preset( $theme_json, $path, $override ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function should_override_preset( $theme_json, $path, $override ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_bool( $override ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $override;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1636,10 +1648,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $node_path The path to inspect. It's 'settings' by default.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function get_default_slugs( $data, $node_path ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function get_default_slugs( $data, $node_path ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $slugs = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::PRESETS_METADATA as $metadata ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::PRESETS_METADATA as $metadata ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $path = array_merge( $node_path, $metadata['path'], array( 'default' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $preset = _wp_array_get( $data, $path, null );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $preset ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1668,7 +1680,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $base_path The path to inspect. It's 'settings' by default.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string|null
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function get_name_from_defaults( $slug, $base_path ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function get_name_from_defaults( $slug, $base_path ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $path = array_merge( $base_path, array( 'default' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $default_content = _wp_array_get( $this->theme_json, $path, null );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $default_content ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1691,7 +1703,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $slugs The slugs that should not be overriden.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array The new node.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function filter_slugs( $node, $slugs ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function filter_slugs( $node, $slugs ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $slugs ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $node;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1719,12 +1731,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $valid_block_names = array_keys( self::get_blocks_metadata() );
- $valid_element_names = array_keys( self::ELEMENTS );
- $theme_json = self::sanitize( $theme_json, $valid_block_names, $valid_element_names );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $valid_block_names = array_keys( static::get_blocks_metadata() );
+ $valid_element_names = array_keys( static::ELEMENTS );
+ $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $blocks_metadata = self::get_blocks_metadata();
- $style_nodes = self::get_style_nodes( $theme_json, $blocks_metadata );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $blocks_metadata = static::get_blocks_metadata();
+ $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $style_nodes as $metadata ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $input = _wp_array_get( $theme_json, $metadata['path'], array() );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $input ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1731,13 +1743,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $output = self::remove_insecure_styles( $input );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $output = static::remove_insecure_styles( $input );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $output ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _wp_array_set( $sanitized, $metadata['path'], $output );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $setting_nodes = self::get_setting_nodes( $theme_json );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $setting_nodes = static::get_setting_nodes( $theme_json );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $setting_nodes as $metadata ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $input = _wp_array_get( $theme_json, $metadata['path'], array() );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $input ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1744,7 +1756,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $output = self::remove_insecure_settings( $input );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $output = static::remove_insecure_settings( $input );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $output ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _wp_array_set( $sanitized, $metadata['path'], $output );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1774,10 +1786,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $input Node to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function remove_insecure_settings( $input ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function remove_insecure_settings( $input ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $output = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( self::PRESETS_METADATA as $preset_metadata ) {
- foreach ( self::VALID_ORIGINS as $origin ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::PRESETS_METADATA as $preset_metadata ) {
+ foreach ( static::VALID_ORIGINS as $origin ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $path_with_origin = array_merge( $preset_metadata['path'], array( $origin ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $presets = _wp_array_get( $input, $path_with_origin, null );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( null === $presets ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1802,7 +1814,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $preset_is_valid = true;
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $preset_metadata['properties'] as $property ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! self::is_safe_css_declaration( $property, $value ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! static::is_safe_css_declaration( $property, $value ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $preset_is_valid = false;
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1831,13 +1843,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $input Node to process.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function remove_insecure_styles( $input ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function remove_insecure_styles( $input ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $output = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $declarations = self::compute_style_properties( $input );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $declarations = static::compute_style_properties( $input );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $declarations as $declaration ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( self::is_safe_css_declaration( $declaration['name'], $declaration['value'] ) ) {
- $path = self::PROPERTIES_METADATA[ $declaration['name'] ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( static::is_safe_css_declaration( $declaration['name'], $declaration['value'] ) ) {
+ $path = static::PROPERTIES_METADATA[ $declaration['name'] ];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Check the value isn't an array before adding so as to not
</span><span class="cx" style="display: block; padding: 0 10px"> // double up shorthand and longhand styles.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1859,7 +1871,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $property_value Value in a CSS declaration, i.e. the `red` in `color: red`.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static function is_safe_css_declaration( $property_name, $property_value ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static function is_safe_css_declaration( $property_name, $property_value ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $style_to_validate = $property_name . ': ' . $property_value;
</span><span class="cx" style="display: block; padding: 0 10px"> $filtered = esc_html( safecss_filter_attr( $style_to_validate ) );
</span><span class="cx" style="display: block; padding: 0 10px"> return ! empty( trim( $filtered ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1887,7 +1899,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_from_editor_settings( $settings ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_settings = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'version' => self::LATEST_SCHEMA,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'version' => static::LATEST_SCHEMA,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'settings' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>