PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.3
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / class-evf-template-loader.php
everest-forms / includes Last commit date
abstracts 2 years ago admin 2 years ago elementor 4 years ago export 3 years ago fields 2 years ago interfaces 8 years ago libraries 2 years ago log-handlers 4 years ago shortcodes 2 years ago stats 3 years ago templates 5 years ago class-everest-forms.php 2 years ago class-evf-ajax.php 2 years ago class-evf-autoloader.php 7 years ago class-evf-background-updater.php 7 years ago class-evf-cache-helper.php 6 years ago class-evf-cron.php 3 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 5 years ago class-evf-emails.php 2 years ago class-evf-fields.php 2 years ago class-evf-form-block.php 4 years ago class-evf-form-handler.php 3 years ago class-evf-form-task.php 2 years ago class-evf-forms-features.php 2 years ago class-evf-frontend-scripts.php 2 years ago class-evf-install.php 2 years ago class-evf-integrations.php 7 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 5 years ago class-evf-post-types.php 5 years ago class-evf-privacy.php 6 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 4 years ago class-evf-smart-tags.php 2 years ago class-evf-template-loader.php 2 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 2 years ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 3 years ago evf-formatting-functions.php 4 years ago evf-notice-functions.php 4 years ago evf-template-functions.php 4 years ago evf-template-hooks.php 7 years ago evf-update-functions.php 5 years ago
class-evf-template-loader.php
234 lines
1 <?php
2 /**
3 * Template Loader
4 *
5 * @package EverestForms\Classes
6 * @version 1.3.1
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Template loader class.
13 */
14 class EVF_Template_Loader {
15
16 /**
17 * Store the form ID.
18 *
19 * @var integer
20 */
21 private static $form_id = 0;
22
23 /**
24 * Store whether we're processing a form preview inside the_content filter.
25 *
26 * @var boolean
27 */
28 private static $in_content_filter = false;
29
30 /**
31 * Hook in methods.
32 */
33 public static function init() {
34 self::$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
35
36 if ( ! is_admin() && isset( $_GET['evf_preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
37 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) );
38 add_filter( 'edit_post_link', array( __CLASS__, 'edit_form_link' ) );
39 add_filter( 'home_template_hierarchy', array( __CLASS__, 'template_include' ) );
40 add_filter( 'frontpage_template_hierarchy', array( __CLASS__, 'template_include' ) );
41 add_action( 'template_redirect', array( __CLASS__, 'form_preview_init' ) );
42 add_filter( 'astra_remove_entry_header_content', '__return_true' ); // Need to remove in next version, If astra release the patches.
43 } else {
44 add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
45 }
46 }
47
48 /**
49 * Hook into pre_get_posts to limit posts.
50 *
51 * @param WP_Query $q Query instance.
52 */
53 public static function pre_get_posts( $q ) {
54 // Limit one post to query.
55 if ( $q->is_main_query() ) {
56 $q->set( 'posts_per_page', 1 );
57 }
58 }
59
60 /**
61 * Change edit link of preview page.
62 *
63 * @param string $link Edit post link.
64 */
65 public static function edit_form_link( $link ) {
66 if ( 0 < self::$form_id ) {
67 return '<a href="' . esc_url( admin_url( 'admin.php?page=evf-builder&tab=fields&form_id=' . self::$form_id ) ) . '" class="post-edit-link">' . esc_html__( 'Edit Form', 'everest-forms' ) . '</a>';
68 }
69
70 return $link;
71 }
72
73 /**
74 * A list of template candidates.
75 *
76 * @param array $templates A list of template candidates, in descending order of priority.
77 *
78 * @return array
79 */
80 public static function template_include( $templates ) {
81 return array( 'page.php', 'single.php', 'index.php' );
82 }
83
84 /**
85 * Load a template.
86 *
87 * Handles template usage so that we can use our own templates instead of the themes.
88 *
89 * Templates are in the 'templates' folder. everest-forms looks for theme.
90 * overrides in /theme/everest-forms/ by default.
91 *
92 * For beginners, it also looks for a everest-forms.php template first. If the user adds.
93 * this to the theme (containing a everest-forms() inside) this will be used for all.
94 * everest-forms templates.
95 *
96 * @param string $template Template to load.
97 * @return string
98 */
99 public static function template_loader( $template ) {
100 if ( is_embed() ) {
101 return $template;
102 }
103
104 $default_file = self::get_template_loader_default_file();
105
106 if ( $default_file ) {
107 /**
108 * Filter hook to choose which files to find before EverestForms does it's own logic.
109 *
110 * @since 1.0.0
111 * @var array
112 */
113 $search_files = self::get_template_loader_files( $default_file );
114 $template = locate_template( $search_files );
115
116 if ( ! $template || EVF_TEMPLATE_DEBUG_MODE ) {
117 $template = evf()->plugin_path() . '/templates/' . $default_file;
118 }
119 }
120
121 return $template;
122 }
123
124 /**
125 * Get the default filename for a template.
126 *
127 * @since 1.0.0
128 * @return string
129 */
130 private static function get_template_loader_default_file() {
131 return '';
132 }
133
134 /**
135 * Get an array of filenames to search for a given template.
136 *
137 * @since 1.0.0
138 * @param string $default_file The default file name.
139 * @return string[]
140 */
141 private static function get_template_loader_files( $default_file ) {
142 $search_files = apply_filters( 'everest_forms_template_loader_files', array(), $default_file );
143 $search_files[] = 'everest-forms.php';
144
145 if ( is_page_template() ) {
146 $search_files[] = get_page_template_slug();
147 }
148
149 $search_files[] = $default_file;
150 $search_files[] = evf()->template_path() . $default_file;
151
152 return array_unique( $search_files );
153 }
154
155 /*
156 |--------------------------------------------------------------------------
157 | Form Preview Handling
158 |--------------------------------------------------------------------------
159 */
160
161 /**
162 * Hook in methods to enhance the form preview.
163 */
164 public static function form_preview_init() {
165 if ( ! is_user_logged_in() || is_admin() ) {
166 return;
167 }
168
169 if ( 0 < self::$form_id ) {
170 add_filter( 'the_title', array( __CLASS__, 'form_preview_title_filter' ), 100, 1 );
171 add_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ),999 );
172 add_filter( 'get_the_excerpt', array( __CLASS__, 'form_preview_content_filter' ),999 );
173 add_filter( 'post_thumbnail_html', '__return_empty_string' );
174 }
175 }
176
177 /**
178 * Filter the title and insert form preview title.
179 *
180 * @param string $title Existing title.
181 * @return string
182 */
183 public static function form_preview_title_filter( $title ) {
184 $form = evf()->form->get(
185 self::$form_id,
186 array(
187 'content_only' => true,
188 )
189 );
190
191 if ( ! empty( $form['settings']['form_title'] ) && in_the_loop() ) {
192 if ( is_customize_preview() ) {
193 return esc_html( sanitize_text_field( $form['settings']['form_title'] ) );
194 }
195
196 /* translators: %s - Form name. */
197 return sprintf( esc_html__( '%s &ndash; Preview', 'everest-forms' ), sanitize_text_field( $form['settings']['form_title'] ) );
198 }
199
200 return $title;
201 }
202
203 /**
204 * Filter the content and insert form preview content.
205 *
206 * @param string $content Existing post content.
207 * @return string
208 */
209 public static function form_preview_content_filter( $content ) {
210 if ( ! is_user_logged_in() || ! is_main_query() || ! in_the_loop() ) {
211 return $content;
212 }
213
214 self::$in_content_filter = true;
215
216 // Remove the filter we're in to avoid nested calls.
217 remove_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ) );
218
219 if ( current_user_can( 'everest_forms_view_forms', self::$form_id ) ) {
220 if ( function_exists( 'apply_shortcodes' ) ) {
221 $content = apply_shortcodes( '[everest_form id="' . absint( self::$form_id ) . '"]' );
222 } else {
223 $content = do_shortcode( '[everest_form id="' . absint( self::$form_id ) . '"]' );
224 }
225 }
226
227 self::$in_content_filter = false;
228
229 return $content;
230 }
231 }
232
233 add_action( 'init', array( 'EVF_Template_Loader', 'init' ) );
234