| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | /** |
| 21 | 21 | * Refuse to sync a slice larger than this, in bytes. |
| 22 | 22 | * |
| 23 | 23 | * A bound on a pathological palette, not a budget: ordinary themes are orders below it, and a |
| 24 | - * theme that trips it syncs its name with no design rather than nothing at all. | |
| 24 | + * theme that trips it syncs nothing and keeps today's behaviour. | |
| 25 | 25 | */ |
| 26 | 26 | const MAX_PAYLOAD_BYTES = 51200; |
| 27 | 27 | |
| 28 | 28 | /** |
| @@ -27,9 +27,9 @@ | ||
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The active theme's inheritable design. |
| 30 | 30 | * |
| 31 | - * @return array|null Null only where this WordPress cannot resolve theme.json at all. | |
| 31 | + * @return array|null Null when theme.json is unavailable, or the slice is oversized. | |
| 32 | 32 | */ |
| 33 | 33 | public static function get_theme_styles() { |
| 34 | 34 | if ( ! class_exists( 'WP_Theme_JSON_Resolver' ) ) { |
| 35 | 35 | return null; |
| @@ -55,12 +55,9 @@ | ||
| 55 | 55 | |
| 56 | 56 | // phpcs:ignore Jetpack.Functions.JsonEncodeFlags.Missing -- measuring the wire representation, which Sync encodes with default flags. |
| 57 | 57 | $encoded = wp_json_encode( $slice ); |
| 58 | 58 | if ( false === $encoded || strlen( $encoded ) > self::MAX_PAYLOAD_BYTES ) { |
| 59 | - // Reporting nothing would hit the same staleness the empty slice above exists to avoid, | |
| 60 | - // so carry the theme's name with no design and let the receiving end fall back. | |
| 61 | - $slice['settings'] = self::preset_sources( array() ); | |
| 62 | - $slice['styles'] = array(); | |
| 59 | + return null; | |
| 63 | 60 | } |
| 64 | 61 | |
| 65 | 62 | return $slice; |
| 66 | 63 | } |
| @@ -199,20 +196,16 @@ | ||
| 199 | 196 | |
| 200 | 197 | /** |
| 201 | 198 | * Flatten an origin-keyed preset list into the flat list `WP_Theme_JSON` expects for one origin. |
| 202 | 199 | * |
| 203 | - * Nothing here is assumed about the shape: core's schema leaves a non-array preset list | |
| 204 | - * untouched, and its constructor only origin-keys a scalar when `isset( $preset[0] ) || empty( | |
| 205 | - * $preset )`, so a theme.json declaring `true` or a number reaches this as that bare scalar. | |
| 200 | + * Each origin is checked rather than assumed: core's schema leaves a non-array preset list | |
| 201 | + * untouched and the `WP_Theme_JSON` constructor origin-keys it anyway, so a theme.json | |
| 202 | + * declaring a scalar there reaches this with a string where a list belongs. | |
| 206 | 203 | * |
| 207 | - * @param mixed $presets Preset list that may be origin-keyed, already flat, or not a list. | |
| 204 | + * @param array $presets Preset list that may be origin-keyed or already flat. | |
| 208 | 205 | * @return array |
| 209 | 206 | */ |
| 210 | - private static function flatten_presets( $presets ) { | |
| 211 | - if ( ! is_array( $presets ) ) { | |
| 212 | - return array(); | |
| 213 | - } | |
| 214 | - | |
| 207 | + private static function flatten_presets( array $presets ) { | |
| 215 | 208 | if ( empty( $presets ) || isset( $presets[0] ) ) { |
| 216 | 209 | return $presets; |
| 217 | 210 | } |
| 218 | 211 | |