[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Server-side rendering of the `core/accordion` block.
   4   *
   5   * @package WordPress
   6   * @since 6.9.0
   7   *
   8   * @param array $attributes The block attributes.
   9   * @param string $content The block content.
  10   *
  11   * @return string Returns the updated markup.
  12   */
  13  function render_block_core_accordion( $attributes, $content ) {
  14      if ( ! $content ) {
  15          return $content;
  16      }
  17  
  18      $p         = new WP_HTML_Tag_Processor( $content );
  19      $autoclose = $attributes['autoclose'] ? 'true' : 'false';
  20  
  21      if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion' ) ) ) {
  22          $p->set_attribute( 'data-wp-interactive', 'core/accordion' );
  23          $p->set_attribute( 'data-wp-context', '{ "autoclose": ' . $autoclose . ', "accordionItems": [] }' );
  24  
  25          // Only modify content if directives have been set.
  26          $content = $p->get_updated_html();
  27      }
  28  
  29      return $content;
  30  }
  31  
  32  /**
  33   * Registers the `core/accordion` block on server.
  34   *
  35   * @since 6.9.0
  36   */
  37  function register_block_core_accordion() {
  38      register_block_type_from_metadata(
  39          __DIR__ . '/accordion',
  40          array(
  41              'render_callback' => 'render_block_core_accordion',
  42          )
  43      );
  44  }
  45  add_action( 'init', 'register_block_core_accordion' );


Generated : Fri Oct 24 08:20:05 2025 Cross-referenced by PHPXref