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
1100       */
1101      $block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
1102      if ( ! is_null( $block_template ) ) {
1103           return $block_template;
1104      }
1105
1106      $parts = explode( '//', $id, 2 );
1107      if ( count( $parts ) < 2 ) {
1108           /** This filter is documented in wp-includes/block-template-utils.php */
1109           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1110      }
1111      list( $theme, $slug ) = $parts;
1112
1113      if ( wp_get_theme()->get_stylesheet() !== $theme ) {
1114           /** This filter is documented in wp-includes/block-template-utils.php */
1115           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1116      }
1117
1118      $template_file = _get_block_template_file( $template_type, $slug );
1119      if ( null === $template_file ) {
1120           /** This filter is documented in wp-includes/block-template-utils.php */
1121           return apply_filters( 'get_block_file_template', null, $id, $template_type );
1122      }
1123
1124      $block_template = _build_block_template_result_from_file( $template_file, $template_type );
1125
1126      /**
1127       * Filters the block template object after it has been (potentially) fetched from the theme file.
1128       *
1129       * @since 5.9.0
1130       *
1131       * @param WP_Block_Template|null $block_template The found block template, or null if there is none.
1132       * @param string                 $id             Template unique identifier (example: theme_slug//template_slug).
1133       * @param string                 $template_type  Template type: `'wp_template'` or '`wp_template_part'`.
1134       */
1135      return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
1136 }
1137
1138 /**
1139  * Prints a block template part.
1140  *
1141  * @since 5.9.0
1142  *
1143  * @param string $part The block template part to print. Use "header" or "footer".
1144  */