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 4 times in this file.

Line Code
1237       */
1238      $block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
1239      if ( ! is_null( $block_template ) ) {
1240           return $block_template;
1241      }
1242
1243      $parts = explode( '//', $id, 2 );
1244      if ( count( $parts ) < 2 ) {
1245           /** This filter is documented in wp-includes/block-template-utils.php */
1246           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1247      }
1248      list( $theme, $slug ) = $parts;
1249
1250      if ( get_stylesheet() !== $theme ) {
1251           /** This filter is documented in wp-includes/block-template-utils.php */
1252           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1253      }
1254
1255      $template_file = _get_block_template_file( $template_type, $slug );
1256      if ( null === $template_file ) {
1257           /** This filter is documented in wp-includes/block-template-utils.php */
1258           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1259      }
1260
1261      $block_template = _build_block_template_result_from_file( $template_file, $template_type );
1262
1263      /**
1264       * Filters the block template object after it has been (potentially) fetched from the theme file.
1265       *
1266       * @since 5.9.0
1267       *
1268       * @param WP_Block_Template|null $block_template The found block template, or null if there is none.
1269       * @param string                 $id             Template unique identifier (example: 'theme_slug//template_slug').
1270       * @param string                 $template_type  Template type. Either 'wp_template' or 'wp_template_part'.
1271       */
1272      return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
1273 }
1274
1275 /**
1276  * Prints a block template part.
1277  *
1278  * @since 5.9.0
1279  *
1280  * @param string $part The block template part to print, for example 'header' or 'footer'.
1281  */