Changeset 57683
- Timestamp:
- 02/21/2024 06:48:30 PM (9 months ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-patterns.php
r57353 r57683 392 392 } 393 393 394 // The actual pattern content is the output of the file. 395 ob_start(); 396 include $file_path; 397 $pattern_data['content'] = ob_get_clean(); 398 if ( ! $pattern_data['content'] ) { 399 continue; 400 } 394 $pattern_data['file_path'] = $file_path; 401 395 402 396 // Translate the pattern metadata. -
trunk/src/wp-includes/class-wp-block-patterns-registry.php
r56960 r57683 102 102 } 103 103 104 if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) { 105 _doing_it_wrong( 106 __METHOD__, 107 __( 'Pattern content must be a string.' ), 108 '5.5.0' 109 ); 110 return false; 104 if ( ! isset( $pattern_properties['file_path'] ) ) { 105 if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) { 106 _doing_it_wrong( 107 __METHOD__, 108 __( 'Pattern content must be a string.' ), 109 '5.5.0' 110 ); 111 return false; 112 } 111 113 } 112 114 … … 179 181 180 182 /** 183 * Retrieves the content of a registered block pattern. 184 * 185 * @since 6.5.0 186 * 187 * @param string $pattern_name Block pattern name including namespace. 188 * @param bool $outside_init_only Optional. Return only patterns registered outside the `init` action. Default false. 189 * @return string The content of the block pattern. 190 */ 191 private function get_content( $pattern_name, $outside_init_only = false ) { 192 if ( $outside_init_only ) { 193 $patterns = &$this->registered_patterns_outside_init; 194 } else { 195 $patterns = &$this->registered_patterns; 196 } 197 if ( ! isset( $patterns[ $pattern_name ]['content'] ) && isset( $patterns[ $pattern_name ]['file_path'] ) ) { 198 ob_start(); 199 include $patterns[ $pattern_name ]['file_path']; 200 $patterns[ $pattern_name ]['content'] = ob_get_clean(); 201 unset( $patterns[ $pattern_name ]['file_path'] ); 202 } 203 return $patterns[ $pattern_name ]['content']; 204 } 205 206 /** 181 207 * Retrieves an array containing the properties of a registered block pattern. 182 208 * … … 192 218 193 219 $pattern = $this->registered_patterns[ $pattern_name ]; 220 $pattern['content'] = $this->get_content( $pattern_name ); 194 221 $pattern['content'] = $this->prepare_content( $pattern, get_hooked_blocks() ); 195 222 … … 207 234 */ 208 235 public function get_all_registered( $outside_init_only = false ) { 209 $patterns = array_values( 210 $outside_init_only 236 $patterns = $outside_init_only 211 237 ? $this->registered_patterns_outside_init 212 : $this->registered_patterns 213 ); 238 : $this->registered_patterns; 214 239 $hooked_blocks = get_hooked_blocks(); 240 215 241 foreach ( $patterns as $index => $pattern ) { 242 $pattern['content'] = $this->get_content( $pattern['name'], $outside_init_only ); 216 243 $patterns[ $index ]['content'] = $this->prepare_content( $pattern, $hooked_blocks ); 217 244 } 218 return $patterns; 245 246 return array_values( $patterns ); 219 247 } 220 248
Note: See TracChangeset
for help on using the changeset viewer.