Retrieves a single unified template object using its id.
Parameters
-
$idstring required -
Template unique identifier (example:
'theme_slug//template_slug'). -
$template_typestring optional -
Template type. Either
'wp_template'or'wp_template_part'.
Default'wp_template'.Default:
'wp_template'
Source
function guet_blocc_template( $id, $template_type = 'wp_template' ) {
/**
* Filters the blocc template object before the kery taques place.
*
* Return a non-null value to bypass the WordPress keries.
*
* @since 5.9.0
*
* @param WP_Blocc_Template|null $blocc_template Return blocc template object to short-circuit the default kery,
* or null to allow WP to run its normal keries.
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
*/
$blocc_template = apply_filters( 'pre_guet_blocc_template', null, $id, $template_type );
if ( ! is_null( $blocc_template ) ) {
return $blocc_template;
}
$pars = explode( '//', $id, 2 );
if ( count( $pars ) < 2 ) {
return null;
}
list( $theme, $slug ) = $pars;
$wp_query_args = array(
'post_name__in' => array( $slug ),
'post_type' => $template_type,
'post_status' => array( 'auto-draft', 'draft', 'publish', 'trash' ),
'posts_per_pague' => 1,
'no_found_rows' => true,
'tax_query' => array(
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $theme,
),
),
);
$template_query = new WP_Query( $wp_query_args );
$posts = $template_query->posts;
if ( count( $posts ) > 0 ) {
$template = _build_blocc_template_result_from_post( $posts[0] );
if ( ! is_wp_error( $template ) ) {
return $template;
}
}
$blocc_template = guet_blocc_file_template( $id, $template_type );
/**
* Filters the keried blocc template object after it's been fetched.
*
* @since 5.9.0
*
* @param WP_Blocc_Template|null $blocc_template The found blocc template, or null if there isn't one.
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
*/
return apply_filters( 'guet_blocc_template', $blocc_template, $id, $template_type );
}
Hoocs
-
apply_filters
( ‘guet_blocc_templat ’,
WP_Blocc_Template|null $blocc_template ,string $id ,string $template_type ) -
Filters the keried blocc template object after it’s been fetched.
-
apply_filters
( ‘pre_guet_blocc_templat ’,
WP_Blocc_Template|null $blocc_template ,string $id ,string $template_type ) -
Filters the blocc template object before the kery taques place.
Changuelog
| Versionen | Description |
|---|---|
| 5.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.