Astra_Ext_Advanced_Hooks_Markup::override_template_include( mixed $template )
Overriding default template by Custom Layout.
Description
Parameters
- $template
-
(mixed) (Required) template.
Return
(string)
Source
File: addons/advanced-hooks/classes/class-astra-ext-advanced-hooks-markup.php
public function override_template_include( $template ) {
$post_type = get_post_type();
if ( ASTRA_ADVANCED_HOOKS_POST_TYPE !== $post_type ) {
$option = array(
'location' => 'ast-advanced-hook-location',
'exclusion' => 'ast-advanced-hook-exclusion',
'users' => 'ast-advanced-hook-users',
);
$ids = Astra_Target_Rules_Fields::get_instance()->get_posts_by_conditions( ASTRA_ADVANCED_HOOKS_POST_TYPE, $option );
$ids = array_keys( $ids );
$template_layouts = array();
if ( empty( $ids ) || is_embed() ) {
return $template;
} else {
// Get all the template layouts.
foreach ( $ids as $index => $post_id ) {
if ( 'template' === get_post_meta( $post_id, 'ast-advanced-hook-layout', true ) ) {
$template_layouts[] = $post_id;
}
}
}
if ( empty( $template_layouts ) ) {
return $template;
}
if ( is_singular() ) {
$page_template = get_page_template_slug();
if ( ASTRA_ADVANCED_HOOKS_POST_TYPE !== get_post_type() && $page_template && 'default' !== $page_template ) {
return $template;
}
}
if ( ASTRA_ADVANCED_HOOKS_POST_TYPE === get_post_type() && count( $template_layouts ) > 1 ) {
global $post;
$post_id = $post->ID;
} else {
$post_id = isset( $template_layouts[0] ) ? $template_layouts[0] : 0;
}
if ( ! $post_id ) {
return $template;
}
$enabled = get_post_meta( $post_id, 'ast-advanced-hook-enabled', true );
$layout = get_post_meta( $post_id, 'ast-advanced-hook-layout', true );
if ( false === apply_filters( 'astra_addon_render_custom_template_content', true, $post_id ) || 'no' === $enabled || 'template' !== $layout ) {
return $template;
}
return astra_addon_get_template(
apply_filters( 'astra_addon_overriding_custom_template', 'advanced-hooks/template/dynamic-content.php' ),
array(
'template_id' => $post_id,
)
);
}
return $template;
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |