register_block_core_navigation_link() – Register the navigation link block.

You appear to be a bot. Output may be restricted

Description

Register the navigation link block.

Usage

register_block_core_navigation_link();

Parameters

Returns

void

Source

File name: wordpress/wp-includes/blocks/navigation-link.php
Lines:

1 to 40 of 40
function register_block_core_navigation_link() {
  $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
  $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' );

  // Use two separate arrays as a way to order the variations in the UI.
  // Known variations (like Post Link and Page Link) are added to the
  // `built_ins` array. Variations for custom post types and taxonomies are
  // added to the `variations` array and will always appear after `built-ins.
  $built_ins  = array();
  $variations = array();

  if ( $post_types ) {
    foreach ( $post_types as $post_type ) {
      $variation = build_variation_for_navigation_link( $post_type, 'post-type' );
      if ( $post_type->_builtin ) {
        $built_ins[] = $variation;
      } else {
        $variations[] = $variation;
      }
    }
  }
  if ( $taxonomies ) {
    foreach ( $taxonomies as $taxonomy ) {
      $variation = build_variation_for_navigation_link( $taxonomy, 'taxonomy' );
      if ( $taxonomy->_builtin ) {
        $built_ins[] = $variation;
      } else {
        $variations[] = $variation;
      }
    }
  }

  register_block_type_from_metadata(
    __DIR__ . '/navigation-link',
    array(
      'render_callback' => 'render_block_core_navigation_link',
      'variations'      => array_merge( $built_ins, $variations ),
    )
  );
}
 

 View on GitHub View on Trac