| @@ -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 nothing and keeps today's behaviour. | |
| 24 | + * theme that trips it syncs its name with no design rather than nothing at all. | |
| 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 when theme.json is unavailable, or the slice is oversized. | |
| 31 | + * @return array|null Null only where this WordPress cannot resolve theme.json at all. | |
| 32 | 32 | */ |
| 33 | 33 | public static function get_theme_styles() { |
| 34 | 34 | if ( ! class_exists( 'WP_Theme_JSON_Resolver' ) ) { |
| 35 | 35 | return null; |
| @@ -55,9 +55,12 @@ | ||
| 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 | - return null; | |
| 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(); | |
| 60 | 63 | } |
| 61 | 64 | |
| 62 | 65 | return $slice; |
| 63 | 66 | } |
| @@ -196,16 +199,20 @@ | ||
| 196 | 199 | |
| 197 | 200 | /** |
| 198 | 201 | * Flatten an origin-keyed preset list into the flat list `WP_Theme_JSON` expects for one origin. |
| 199 | 202 | * |
| 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. | |
| 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. | |
| 203 | 206 | * |
| 204 | - * @param array $presets Preset list that may be origin-keyed or already flat. | |
| 207 | + * @param mixed $presets Preset list that may be origin-keyed, already flat, or not a list. | |
| 205 | 208 | * @return array |
| 206 | 209 | */ |
| 207 | - private static function flatten_presets( array $presets ) { | |
| 210 | + private static function flatten_presets( $presets ) { | |
| 211 | + if ( ! is_array( $presets ) ) { | |
| 212 | + return array(); | |
| 213 | + } | |
| 214 | + | |
| 208 | 215 | if ( empty( $presets ) || isset( $presets[0] ) ) { |
| 209 | 216 | return $presets; |
| 210 | 217 | } |
| 211 | 218 | |