[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/blocks/ -> pattern.php (source)

   1  <?php
   2  /**
   3   * Server-side rendering of the `core/pattern` block.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   *  Registers the `core/pattern` block on the server.
  10   *
  11   * @return void
  12   */
  13  function register_block_core_pattern() {
  14      register_block_type_from_metadata(
  15          __DIR__ . '/pattern',
  16          array(
  17              'render_callback' => 'render_block_core_pattern',
  18          )
  19      );
  20  }
  21  
  22  /**
  23   * Renders the `core/pattern` block on the server.
  24   *
  25   * @param array $attributes Block attributes.
  26   *
  27   * @return string Returns the output of the pattern.
  28   */
  29  function render_block_core_pattern( $attributes ) {
  30      if ( empty( $attributes['slug'] ) ) {
  31          return '';
  32      }
  33  
  34      $slug     = $attributes['slug'];
  35      $registry = WP_Block_Patterns_Registry::get_instance();
  36      if ( ! $registry->is_registered( $slug ) ) {
  37          return '';
  38      }
  39  
  40      $pattern = $registry->get_registered( $slug );
  41      return do_blocks( $pattern['content'] );
  42  }
  43  
  44  add_action( 'init', 'register_block_core_pattern' );


Generated: Tue Jan 25 01:00:04 2022 Cross-referenced by PHPXref 0.7.1