Changeset 55234 for trunk/src/wp-includes/block-patterns.php
- Timestamp:
- 02/06/2023 07:38:08 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-patterns.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-patterns.php
r55173 r55234 160 160 161 161 /** 162 * Normalize the pattern properties to camelCase. 163 * 164 * The API's format is snake_case, `register_block_pattern()` expects camelCase. 165 * 166 * @since 6.2.0 167 * @access private 168 * 169 * @param array $pattern Pattern as returned from the Pattern Directory API. 170 * @return array Normalized pattern. 171 */ 172 function wp_normalize_remote_block_pattern( $pattern ) { 173 if ( isset( $pattern['block_types'] ) ) { 174 $pattern['blockTypes'] = $pattern['block_types']; 175 unset( $pattern['block_types'] ); 176 } 177 178 if ( isset( $pattern['viewport_width'] ) ) { 179 $pattern['viewportWidth'] = $pattern['viewport_width']; 180 unset( $pattern['viewport_width'] ); 181 } 182 183 return (array) $pattern; 184 } 185 186 /** 162 187 * Register Core's official patterns from wordpress.org/patterns. 163 188 * 164 189 * @since 5.8.0 165 190 * @since 5.9.0 The $current_screen argument was removed. 191 * @since 6.2.0 Normalize the pattern from the API (snake_case) to the 192 * format expected by `register_block_pattern` (camelCase). 166 193 * 167 194 * @param WP_Screen $deprecated Unused. Formerly the screen that the current request was triggered from. … … 197 224 $patterns = $response->get_data(); 198 225 199 foreach ( $patterns as $settings ) { 200 $pattern_name = 'core/' . sanitize_title( $settings['title'] ); 201 register_block_pattern( $pattern_name, (array) $settings ); 226 foreach ( $patterns as $pattern ) { 227 $normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); 228 $pattern_name = 'core/' . sanitize_title( $normalized_pattern['title'] ); 229 register_block_pattern( $pattern_name, $normalized_pattern ); 202 230 } 203 231 } … … 208 236 * 209 237 * @since 5.9.0 238 * @since 6.2.0 Normalized the pattern from the API (snake_case) to the 239 * format expected by `register_block_pattern()` (camelCase). 210 240 */ 211 241 function _load_remote_featured_patterns() { … … 227 257 } 228 258 $patterns = $response->get_data(); 229 259 $registry = WP_Block_Patterns_Registry::get_instance(); 230 260 foreach ( $patterns as $pattern ) { 231 $ pattern_name = sanitize_title( $pattern['title']);232 $ registry = WP_Block_Patterns_Registry::get_instance();261 $normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); 262 $pattern_name = sanitize_title( $normalized_pattern['title'] ); 233 263 // Some patterns might be already registered as core patterns with the `core` prefix. 234 264 $is_registered = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name" ); 235 265 if ( ! $is_registered ) { 236 register_block_pattern( $pattern_name, (array) $pattern );266 register_block_pattern( $pattern_name, $normalized_pattern ); 237 267 } 238 268 } … … 244 274 * 245 275 * @since 6.0.0 276 * @since 6.2.0 Normalized the pattern from the API (snake_case) to the 277 * format expected by `register_block_pattern()` (camelCase). 246 278 * @access private 247 279 */ … … 270 302 $patterns_registry = WP_Block_Patterns_Registry::get_instance(); 271 303 foreach ( $patterns as $pattern ) { 272 $pattern_name = sanitize_title( $pattern['title'] ); 304 $normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); 305 $pattern_name = sanitize_title( $normalized_pattern['title'] ); 273 306 // Some patterns might be already registered as core patterns with the `core` prefix. 274 307 $is_registered = $patterns_registry->is_registered( $pattern_name ) || $patterns_registry->is_registered( "core/$pattern_name" ); 275 308 if ( ! $is_registered ) { 276 register_block_pattern( $pattern_name, (array) $pattern );309 register_block_pattern( $pattern_name, $normalized_pattern ); 277 310 } 278 311 }
Note: See TracChangeset
for help on using the changeset viewer.