_load_remote_featured_patterns() – Register `Featured` (category) patterns from wordpress.org/patterns.

You appear to be a bot. Output may be restricted

Description

Register Featured (category) patterns from wordpress.org/patterns.

Usage

_load_remote_featured_patterns();

Parameters

Returns

void

Source

File name: wordpress/wp-includes/block-patterns.php


Lines:

1 to 31 of 31
function _load_remote_featured_patterns() {
  $supports_core_patterns = get_theme_support( 'core-block-patterns' );

  
/** This filter is documented in wp-includes/block-patterns.php */
  $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true );

  if ( ! $should_load_remote || ! $supports_core_patterns ) {
    return;
  }

  $request         = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
  $featured_cat_id = 26; // This is the `Featured` category id from pattern directory.
  $request->set_param( 'category', $featured_cat_id );
  $response = rest_do_request( $request );
  if ( $response->is_error() ) {
    return;
  }
  $patterns = $response->get_data();

  foreach ( $patterns as $pattern ) {
    $pattern_name = sanitize_title( $pattern['title'] );
    $registry     = WP_Block_Patterns_Registry::get_instance();
    // Some patterns might be already registered as core patterns with the `core` prefix.
    $is_registered = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name" );
    if ( ! $is_registered ) {
      register_block_pattern( $pattern_name, (array) $pattern );
    }
  }
}
 

 View on GitHub View on Trac