Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: get_block_file_template

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 3 times in this file.

Line Code
1309       */
1310      $block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
1311      if ( ! is_null( $block_template ) ) {
1312           return $block_template;
1313      }
1314
1315      $parts = explode( '//', $id, 2 );
1316      if ( count( $parts ) < 2 ) {
1317           /** This filter is documented in wp-includes/block-template-utils.php */
1318           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1319      }
1320      list( $theme, $slug ) = $parts;
1321
1322      if ( get_stylesheet() === $theme ) {
1323           $template_file = _get_block_template_file( $template_type, $slug );
1324           if ( null !== $template_file ) {
1325                $block_template = _build_block_template_result_from_file( $template_file, $template_type );
1326
1327                /** This filter is documented in wp-includes/block-template-utils.php */
1328                return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
1329           }
1330      }
1331
1332      $block_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $slug );
1333
1334      /**
1335       * Filters the block template object after it has been (potentially) fetched from the theme file.
1336       *
1337       * @since 5.9.0
1338       *
1339       * @param WP_Block_Template|null $block_template The found block template, or null if there is none.
1340       * @param string                 $id             Template unique identifier (example: 'theme_slug//template_slug').
1341       * @param string                 $template_type  Template type. Either 'wp_template' or 'wp_template_part'.
1342       */
1343      return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
1344 }
1345
1346 /**
1347  * Prints a block template part.
1348  *
1349  * @since 5.9.0
1350  *
1351  * @param string $part The block template part to print, for example 'header' or 'footer'.
1352  */