PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.6.0
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.6.0
3.6.0 3.5.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
Helpers 1 year ago Integrations 3 days ago RestApi 3 days ago abilities 2 months ago abstracts 1 month ago admin 3 days ago blocks 1 year ago elementor 2 years ago export 3 months ago fields 1 week ago interfaces 8 years ago libraries 2 years ago log-handlers 1 year ago shortcodes 3 days ago stats 6 months ago templates 4 months ago traits 2 months ago class-everest-forms.php 3 days ago class-evf-addon-upsell.php 2 months ago class-evf-ajax.php 3 days ago class-evf-autoloader.php 8 years ago class-evf-background-process-import-entries.php 2 years ago class-evf-background-updater.php 8 years ago class-evf-cache-helper.php 3 months ago class-evf-cron.php 2 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 5 years ago class-evf-email-entries-report.php 4 months ago class-evf-emails.php 2 months ago class-evf-fields.php 2 months ago class-evf-form-handler.php 3 days ago class-evf-form-task.php 2 months ago class-evf-forms-features.php 2 months ago class-evf-frontend-scripts.php 3 days ago class-evf-install.php 3 months ago class-evf-integrations.php 4 months ago class-evf-log-levels.php 8 years ago class-evf-logger.php 5 years ago class-evf-post-types.php 1 year ago class-evf-privacy.php 6 years ago class-evf-report-cron.php 3 months ago class-evf-reporting.php 3 months ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 1 year ago class-evf-smart-tags.php 3 days ago class-evf-template-loader.php 3 days ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 2 months ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 5 months 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 8 years ago evf-update-functions.php 5 years ago
class-evf-template-loader.php
433 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 } elseif ( isset( $_GET['evf_email_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['evf_email_preview'] ) ) : '' ) {
44 add_filter( 'template_include', array( __CLASS__, 'email_preview_init' ) );
45 } else {
46 add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
47 }
48 }
49
50 /**
51 * Hook into pre_get_posts to limit posts.
52 *
53 * @param WP_Query $q Query instance.
54 */
55 public static function pre_get_posts( $q ) {
56 // Limit one post to query.
57 if ( $q->is_main_query() ) {
58 $q->set( 'posts_per_page', 1 );
59 }
60 }
61
62 /**
63 * Change edit link of preview page.
64 *
65 * @param string $link Edit post link.
66 */
67 public static function edit_form_link( $link ) {
68 if ( 0 < self::$form_id ) {
69 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>';
70 }
71
72 return $link;
73 }
74
75 /**
76 * A list of template candidates.
77 *
78 * @param array $templates A list of template candidates, in descending order of priority.
79 *
80 * @return array
81 */
82 public static function template_include( $templates ) {
83 $templates = apply_filters( 'everest_forms_templates_includes', array( 'page.php', 'single.php', 'index.php' ), $templates );
84 return $templates;
85 }
86
87 /**
88 * Load a template.
89 *
90 * Handles template usage so that we can use our own templates instead of the themes.
91 *
92 * Templates are in the 'templates' folder. everest-forms looks for theme.
93 * overrides in /theme/everest-forms/ by default.
94 *
95 * For beginners, it also looks for a everest-forms.php template first. If the user adds.
96 * this to the theme (containing a everest-forms() inside) this will be used for all.
97 * everest-forms templates.
98 *
99 * @param string $template Template to load.
100 * @return string
101 */
102 public static function template_loader( $template ) {
103 if ( is_embed() ) {
104 return $template;
105 }
106
107 $default_file = self::get_template_loader_default_file();
108
109 if ( $default_file ) {
110 /**
111 * Filter hook to choose which files to find before EverestForms does it's own logic.
112 *
113 * @since 1.0.0
114 * @var array
115 */
116 $search_files = self::get_template_loader_files( $default_file );
117 $template = locate_template( $search_files );
118
119 if ( ! $template || EVF_TEMPLATE_DEBUG_MODE ) {
120 $template = evf()->plugin_path() . '/templates/' . $default_file;
121 }
122 }
123
124 return $template;
125 }
126
127 /**
128 * Get the default filename for a template.
129 *
130 * @since 1.0.0
131 * @return string
132 */
133 private static function get_template_loader_default_file() {
134 return '';
135 }
136
137 /**
138 * Get an array of filenames to search for a given template.
139 *
140 * @since 1.0.0
141 * @param string $default_file The default file name.
142 * @return string[]
143 */
144 private static function get_template_loader_files( $default_file ) {
145 $search_files = apply_filters( 'everest_forms_template_loader_files', array(), $default_file );
146 $search_files[] = 'everest-forms.php';
147
148 if ( is_page_template() ) {
149 $search_files[] = get_page_template_slug();
150 }
151
152 $search_files[] = $default_file;
153 $search_files[] = evf()->template_path() . $default_file;
154
155 return array_unique( $search_files );
156 }
157
158 /*
159 |--------------------------------------------------------------------------
160 | Form Preview Handling
161 |--------------------------------------------------------------------------
162 */
163
164 /**
165 * Hook in methods to enhance the form preview.
166 */
167 public static function form_preview_init() {
168 if ( ! is_user_logged_in() || is_admin() ) {
169 return;
170 }
171
172 add_filter( 'template_include', array( __CLASS__, 'evf_form_preview_template' ), PHP_INT_MAX );
173 // if ( 0 < self::$form_id ) {
174 // add_filter( 'the_title', array( __CLASS__, 'form_preview_title_filter' ), 100, 1 );
175 // add_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ), 999 );
176 // add_filter( 'get_the_excerpt', array( __CLASS__, 'form_preview_content_filter' ), 999 );
177 // add_filter( 'post_thumbnail_html', '__return_empty_string' );
178 // }
179 }
180
181 public static function evf_form_preview_template( $evf_form_preview_template ) {
182 if ( is_embed() ) {
183 return $evf_form_preview_template;
184 }
185
186 ob_start();
187 if ( is_user_logged_in() && isset( $_GET['form_id'] ) ) {
188 self::generate_form_preview();
189 }
190 $form_content = ob_get_clean();
191
192 // Embed mode — the form ONLY, no toolbar/device-switcher/shortcode-box/side panel.
193 // Used by the "Create with AI" screen's own preview iframe (see
194 // src/templates/components/CreateWithAI.tsx), which already renders its own chrome
195 // around the iframe; the full chrome below is for the builder toolbar's "Preview"
196 // link, which deliberately opens this same route in a new tab as a standalone page.
197 if ( ! empty( $_GET['evf_preview_mode'] ) && 'embed' === $_GET['evf_preview_mode'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
198 // This route is loaded inside an iframe with no room to spare — the WP admin
199 // toolbar has no purpose there and only pushes the form down/off.
200 add_filter( 'show_admin_bar', '__return_false' );
201 return evf_get_template( 'form-preview/evf-form-preview-embed.php', array( 'form_content' => $form_content ) );
202 }
203
204 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
205 wp_register_style( 'evf-form-preview-style', evf()->plugin_url() . '/assets/css/evf-form-preview.css', array(), EVF_VERSION );
206 wp_enqueue_style( 'evf-form-preview-style' );
207
208 wp_register_script( 'evf-form-preview-script', evf()->plugin_url() . '/assets/js/frontend/evf-form-preview' . $suffix . '.js', array( 'jquery', 'tooltipster' ), EVF_VERSION );
209 wp_enqueue_script( 'evf-form-preview-script' );
210 wp_register_script( 'tooltipster', evf()->plugin_url() . '/assets/js/tooltipster/tooltipster.bundle' . $suffix . '.js', array( 'jquery' ), '4.6.2', true );
211
212 wp_localize_script(
213 'evf-form-preview-script',
214 'everest_forms_form_preview ',
215 array(
216 'ajax_url' => admin_url( 'admin-ajax.php' ),
217 'form_preview_nonce' => wp_create_nonce( 'evf_form_preview_nonce' ),
218 'pro_upgrade_link' => esc_url( 'https://everestforms.net/upgrade/?utm_medium=evf-form-preview&utm_source=evf-free&utm_campaign=preview-sidebar-btn&utm_content=Upgrade%20to%20Pro' ),
219 )
220 );
221
222 ob_start();
223 self::side_panel_content();
224
225 $side_panel_content = ob_get_clean();
226 $template = evf_get_template(
227 'form-preview/evf-form-preview-template.php',
228 array(
229 'form_content' => $form_content,
230 'side_panel_content' => $side_panel_content,
231 )
232 );
233
234 return $template;
235 }
236
237 /*
238 |--------------------------------------------------------------------------
239 | Email Preview Handling
240 |--------------------------------------------------------------------------
241 */
242
243 /**
244 * Hook in methods to enhance the form preview.
245 */
246 public static function email_preview_init() {
247 if ( ! is_user_logged_in() || is_admin() ) {
248 return;
249 }
250
251 $email_preview = evf()->plugin_path() . '/templates/emails/email-preview.php';
252 return $email_preview;
253 }
254
255 /**
256 * Filter the title and insert form preview title.
257 *
258 * @param string $title Existing title.
259 * @return string
260 */
261 public static function form_preview_title_filter( $title ) {
262 $form = evf()->form->get(
263 self::$form_id,
264 array(
265 'content_only' => true,
266 )
267 );
268
269 if ( ! empty( $form['settings']['form_title'] ) && in_the_loop() ) {
270 if ( is_customize_preview() ) {
271 return esc_html( sanitize_text_field( $form['settings']['form_title'] ) );
272 }
273
274 /* translators: %s - Form name. */
275 return sprintf( esc_html__( '%s &ndash; Preview', 'everest-forms' ), sanitize_text_field( $form['settings']['form_title'] ) );
276 }
277
278 return $title;
279 }
280
281 /**
282 * Filter the content and insert form preview content.
283 *
284 * @param string $content Existing post content.
285 * @return string
286 */
287 public static function form_preview_content_filter( $content ) {
288 if ( ! is_user_logged_in() || ! is_main_query() ) {
289 return $content;
290 }
291
292 self::$in_content_filter = true;
293
294 // Remove the filter we're in to avoid nested calls.
295 remove_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ) );
296
297 if ( current_user_can( 'everest_forms_view_forms', self::$form_id ) ) {
298 if ( function_exists( 'apply_shortcodes' ) ) {
299 $content = apply_shortcodes( '[everest_form id="' . absint( self::$form_id ) . '"]' );
300 } else {
301 $content = do_shortcode( '[everest_form id="' . absint( self::$form_id ) . '"]' );
302 }
303 }
304
305 self::$in_content_filter = false;
306
307 return $content;
308 }
309
310
311 /**
312 * Handles the preview of form.
313 *
314 * @since 3.2.2
315 */
316 public static function generate_form_preview() {
317 if ( ! is_user_logged_in() ) {
318 return;
319 }
320
321 if ( isset( $_GET['form_id'] ) ) {
322 $form_id = absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
323
324 $html = '';
325 $html .= '<div class="evf-preview-content">';
326 // Embed mode's caller (the "Create with AI" screen) already shows the form
327 // title in its OWN header above the iframe — this span would just duplicate it.
328 if ( empty( $_GET['evf_preview_mode'] ) || 'embed' !== $_GET['evf_preview_mode'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
329 $html .= '<span class="evf-form-preview-title">';
330 $html .= esc_html( get_the_title( $form_id ) );
331 $html .= '</span>';
332 }
333
334 $shortcode = sprintf( '[everest_form id="%d"]', $form_id );
335
336 if ( function_exists( 'apply_shortcodes' ) ) {
337 $content = apply_shortcodes( $shortcode );
338 } else {
339 $content = do_shortcode( $shortcode );
340 }
341 $html .= $content;
342 $html .= '</div>';
343
344 echo $html;
345 }
346 }
347
348 /**
349 * Side panel content.
350 *
351 * @since 4.0
352 */
353 public static function side_panel_content() {
354
355 $is_pro_active = is_plugin_active( 'everest-forms-pro/everest-forms-pro.php' );
356 if ( ! $is_pro_active ) {
357 $heading = esc_html__( 'Our Pro Features.', 'everest-forms' );
358 $pro_features = array(
359 esc_html__( 'Stripe & PayPal Integration', 'everest-forms' ),
360 esc_html__( 'Style Export & Import', 'everest-forms' ),
361 esc_html__( 'Conditional Email Routing', 'everest-forms' ),
362 esc_html__( 'Advanced Form Fields', 'everest-forms' ),
363 esc_html__( 'Quiz & Survey Forms', 'everest-forms' ),
364 esc_html__( '40+ Integrations', 'everest-forms' ),
365 esc_html__( 'Multi-Step Forms', 'everest-forms' ),
366 esc_html__( 'SMS Notifications', 'everest-forms' ),
367 esc_html__( 'Calculated Fields', 'everest-forms' ),
368
369 );
370 } else {
371 $heading = esc_html__( 'Our Top Addons', 'everest-forms' );
372 $pro_features = array(
373 esc_html__( 'Style Customizer', 'everest-forms' ),
374 esc_html__( 'Custom Captcha', 'everest-forms' ),
375 esc_html__( 'Multi Part Forms', 'everest-forms' ),
376 esc_html__( 'PDF Form Submission', 'everest-forms' ),
377 esc_html__( 'Email Templates', 'everest-forms' ),
378 esc_html__( 'Survey, Polls and Quiz', 'everest-forms' ),
379 esc_html__( 'Paypal Standard', 'everest-forms' ),
380 esc_html__( 'Repeater Fields', 'everest-forms' ),
381 );
382 }
383 $is_theme_style = get_post_meta( $_GET['form_id'], 'everest_forms_enable_theme_style', true );
384 if ( 'default' === $is_theme_style ) {
385 $checked = '';
386 $data_theme = 'default';
387 } else {
388 $checked = 'checked';
389 $data_theme = 'theme';
390 }
391 $html = '';
392 $html .= '<div class="evf-from-preview-theme-toggle">';
393 $html .= '<label class="evf-form-preview-toggle-title">' . esc_html__( 'Apply Theme Style', 'everest-forms' ) . '</label>';
394 $html .= '<span class="evf-form-preview-toggle-theme-preview">';
395 $html .= '<input type="checkbox" class="evf-form-preview-theme-toggle-checkbox input-checkbox " id="evf_toggle_form_preview_theme" ' . $checked . '>';
396 $html .= '<span class="slider round"></span>';
397 $html .= '</span>';
398 $html .= '</div>';
399 $html .= '<div class="evf-form-preview-save hidden" id="evf-form-save" data-theme="' . $data_theme . '" data-id="' . absint( $_GET['form_id'] ) . '">';
400 $html .= '<img src="' . esc_url( evf()->plugin_url() . '/assets/images/save-frame.svg' ) . '" alt="Save">';
401 $html .= '<div class="evf-form-preview-save-title">' . esc_html__( 'Save', 'everest-forms' ) . '</div>';
402 $html .= '</div>';
403 $html .= '<div class="evf-form-preview-pro-features">';
404 $html .= '<p class="evf-form-preview-pro-features-title">' . esc_html__( $heading, 'everest-forms' ) . '</p>';
405 foreach ( $pro_features as $list ) {
406 $html .= '<div class="evf-form-preview-sidebar__body--list-item">';
407
408 $html .= '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" fill="none">
409 <path d="M15 5.25L6.75 13.5L3 9.75" stroke="#4CC741" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
410 </svg>';
411
412 $html .= '<span>';
413 $html .= wp_kses_post( $list );
414 $html .= '</span>';
415 $html .= '</div>';
416
417 }
418 if ( ! $is_pro_active ) {
419 $html .= '<div class="evf-form-preview-upgrade id="evf-form-save" data-theme="default" ">';
420 $html .= '<img src="' . esc_url( evf()->plugin_url() . '/assets/images/upgrade-boost-icon.svg' ) . '" alt="Upgrade">';
421 $html .= '<div class="evf-form-preview-upgrade-title">Upgrade to Pro</div>';
422 $html .= '</div>';
423 }
424
425 echo $html; // phpcs:ignore
426
427 ?>
428 <?php
429 }
430 }
431
432 add_action( 'init', array( 'EVF_Template_Loader', 'init' ) );
433