1: <?php
2: /**
3: * Loading the templates
4: * Needs to work with other themes. These template files af a function that iThemes Builder needs to render the template.
5: *
6: * @package EPL
7: * @subpackage Templates/Themes
8: * @copyright Copyright (c) 2020, Merv Barrett
9: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10: * @since 1.0.0
11: */
12:
13: // Exit if accessed directly.
14: if ( ! defined( 'ABSPATH' ) ) {
15: exit;
16: }
17:
18: // phpcs:disable WordPress.Security.NonceVerification
19:
20: /**
21: * Load Custom Template from Plugin Directory
22: *
23: * @param string $template Template name.
24: *
25: * @return string
26: * @since 1.0.0
27: */
28: function epl_load_core_templates( $template ) {
29:
30: global $epl_settings;
31:
32: $template_path = epl_get_content_path();
33:
34: if ( isset( $epl_settings['epl_feeling_lucky'] ) && 'on' === $epl_settings['epl_feeling_lucky'] ) {
35: return $template;
36: }
37:
38: $post_tpl = '';
39: if ( is_epl_post_single() ) {
40:
41: $common_tpl = apply_filters( 'epl_common_single_template', 'single-listing.php' );
42: $post_tpl = 'single-' . str_replace( '_', '-', get_post_type() ) . '.php';
43: $find[] = $post_tpl;
44: $find[] = epl_template_path() . $post_tpl;
45: $find[] = $common_tpl;
46: $find[] = epl_template_path() . $common_tpl;
47:
48: } elseif ( epl_is_search() ) {
49:
50: $common_tpl = apply_filters( 'epl_common_search_template', 'archive-listing.php' );
51: $post_tpl = 'archive-listing.php';
52: if ( isset( $_GET['post_type'] ) ) {
53:
54: if ( is_array( $_GET['post_type'] ) ) {
55: $post_tpl = 'search-listing.php';
56: } else {
57: $post_tpl = 'search-' . sanitize_title( wp_unslash( $_GET['post_type'] ) ) . '.php';
58: }
59: }
60: $find[] = $post_tpl;
61: $find[] = epl_template_path() . $post_tpl;
62: $find[] = 'search-listing.php';
63: $find[] = epl_template_path() . 'search-listing.php';
64: $find[] = $common_tpl;
65: $find[] = epl_template_path() . $common_tpl;
66: $find = array_unique( $find );
67:
68: } elseif ( is_epl_post_archive() ) {
69: $common_tpl = apply_filters( 'epl_common_archive_template', 'archive-listing.php' );
70: $post_tpl = 'archive-' . str_replace( '_', '-', get_post_type() ) . '.php';
71: $find[] = $post_tpl;
72: $find[] = epl_template_path() . $post_tpl;
73: $find[] = $common_tpl;
74: $find[] = epl_template_path() . $common_tpl;
75: } elseif ( is_tax( 'location' ) || is_tax( 'tax_feature' ) || is_tax( 'tax_business_listing' ) ) {
76:
77: $term = get_queried_object();
78: $common_tpl = apply_filters( 'epl_common_taxonomy_template', 'archive-listing.php' );
79:
80: $post_tpl = 'taxonomy-' . $term->taxonomy . '.php';
81: $find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
82: $find[] = epl_template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
83: $find[] = 'taxonomy-' . $term->taxonomy . '.php';
84: $find[] = epl_template_path() . 'taxonomy-' . $term->taxonomy . '.php';
85: $find[] = $common_tpl;
86: $find[] = $post_tpl;
87: $find[] = epl_template_path() . $common_tpl;
88:
89: }
90: if ( $post_tpl ) {
91: /*** Template found in theme ? */
92: $template = locate_template( array_unique( $find ) );
93: if ( ! $template ) {
94: /*** If not found, fallback to extension's default template */
95: $template = $template_path . $common_tpl;
96:
97: if ( ! file_exists( $template ) ) {
98: /*** If extension doesnt have templates, fallback to core templates */
99: $template = EPL_PATH_TEMPLATES_CONTENT . $common_tpl;
100: }
101: }
102: }
103: return $template;
104: }
105: add_filter( 'template_include', 'epl_load_core_templates' );
106:
107: /**
108: * Template Loader for Single Listings
109: *
110: * @since 2.0.0
111: * @since 3.4.14 Added TwentyTwenty theme support.
112: * @since 3.4.26 Added Avada theme support.
113: */
114: function epl_render_single_post() {
115:
116: if ( epl_is_builder_framework_theme() ) {
117: $template_path = EPL_PATH_TEMPLATES_POST_TYPES_ITHEMES;
118: } elseif ( epl_is_genesis_framework_theme() ) {
119: $template_path = EPL_PATH_TEMPLATES_POST_TYPES_GENESIS;
120: } elseif ( epl_is_divi_framework_theme() ) {
121: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . 'divi/';
122: } elseif ( epl_is_twenty_twenty_theme() ) {
123: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . 'twentytwenty/';
124: } elseif ( epl_is_avada_theme() ) {
125: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . 'avada/';
126: } elseif ( file_exists( EPL_PATH_TEMPLATES_POST_TYPES . epl_get_active_theme() ) ) {
127: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . trailingslashit( epl_get_active_theme() );
128: } else {
129: $template_path = EPL_PATH_TEMPLATES_POST_TYPES_DEFAULT;
130: }
131: $common_tpl = 'single-listing.php';
132: $template = $template_path . $common_tpl;
133: include $template;
134: }
135: add_action( 'epl_render_single_post', 'epl_render_single_post' );
136:
137: /**
138: * Template Loader for Archive
139: *
140: * @since 2.0.0
141: * @since 3.4.14 Added TwentyTwenty theme support.
142: * @since 3.4.26 Added Avada theme support.
143: */
144: function epl_render_archive_post() {
145:
146: if ( epl_is_builder_framework_theme() ) {
147: $template_path = EPL_PATH_TEMPLATES_POST_TYPES_ITHEMES;
148: } elseif ( epl_is_genesis_framework_theme() ) {
149: $template_path = EPL_PATH_TEMPLATES_POST_TYPES_GENESIS;
150: } elseif ( epl_is_divi_framework_theme() ) {
151: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . 'divi/';
152: } elseif ( epl_is_twenty_twenty_theme() ) {
153: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . 'twentytwenty/';
154: } elseif ( epl_is_avada_theme() ) {
155: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . 'avada/';
156: } elseif ( file_exists( EPL_PATH_TEMPLATES_POST_TYPES . epl_get_active_theme() ) ) {
157: $template_path = EPL_PATH_TEMPLATES_POST_TYPES . trailingslashit( epl_get_active_theme() );
158: } else {
159: $template_path = EPL_PATH_TEMPLATES_POST_TYPES_DEFAULT;
160: }
161: $common_tpl = 'archive-listing.php';
162: $template = $template_path . $common_tpl;
163: include $template;
164: }
165: add_action( 'epl_render_archive_post', 'epl_render_archive_post' );
166:
167: /**
168: * Add extra class for twentysixteen theme
169: *
170: * @param string $class_name Class name.
171: * @return string
172: *
173: * @since 3.0.0
174: */
175: function epl_active_theme_name_twentysixteen( $class_name ) {
176:
177: if ( epl_get_active_theme() === 'twentysixteen' && ! is_single() ) {
178: $class_name = $class_name . ' content-area';
179: }
180: return $class_name;
181: }
182: add_filter( 'epl_active_theme_name', 'epl_active_theme_name_twentysixteen' );
183: