PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.0.6
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.0.6
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
RestApi 1 year ago abstracts 1 year ago admin 1 year ago blocks 1 year ago elementor 2 years ago export 1 year ago fields 1 year ago interfaces 8 years ago libraries 3 years ago log-handlers 4 years ago shortcodes 1 year ago stats 3 years ago templates 5 years ago class-everest-forms.php 1 year ago class-evf-ajax.php 1 year 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 6 years 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-emails.php 1 year ago class-evf-fields.php 2 years ago class-evf-form-handler.php 2 years ago class-evf-form-task.php 1 year ago class-evf-forms-features.php 2 years ago class-evf-frontend-scripts.php 1 year ago class-evf-install.php 2 years ago class-evf-integrations.php 2 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-report-cron.php 2 years ago class-evf-reporting.php 2 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 4 years ago class-evf-smart-tags.php 1 year 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 1 year ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 2 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 8 years ago evf-update-functions.php 5 years ago
class-evf-template-loader.php
255 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 if ( 0 < self::$form_id ) {
173 add_filter( 'the_title', array( __CLASS__, 'form_preview_title_filter' ), 100, 1 );
174 add_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ), 999 );
175 add_filter( 'get_the_excerpt', array( __CLASS__, 'form_preview_content_filter' ), 999 );
176 add_filter( 'post_thumbnail_html', '__return_empty_string' );
177 }
178 }
179
180 /*
181 |--------------------------------------------------------------------------
182 | Email Preview Handling
183 |--------------------------------------------------------------------------
184 */
185
186 /**
187 * Hook in methods to enhance the form preview.
188 */
189 public static function email_preview_init() {
190 if ( ! is_user_logged_in() || is_admin() ) {
191 return;
192 }
193
194 $email_preview = evf()->plugin_path() . '/templates/emails/email-preview.php';
195 return $email_preview;
196 }
197
198 /**
199 * Filter the title and insert form preview title.
200 *
201 * @param string $title Existing title.
202 * @return string
203 */
204 public static function form_preview_title_filter( $title ) {
205 $form = evf()->form->get(
206 self::$form_id,
207 array(
208 'content_only' => true,
209 )
210 );
211
212 if ( ! empty( $form['settings']['form_title'] ) && in_the_loop() ) {
213 if ( is_customize_preview() ) {
214 return esc_html( sanitize_text_field( $form['settings']['form_title'] ) );
215 }
216
217 /* translators: %s - Form name. */
218 return sprintf( esc_html__( '%s &ndash; Preview', 'everest-forms' ), sanitize_text_field( $form['settings']['form_title'] ) );
219 }
220
221 return $title;
222 }
223
224 /**
225 * Filter the content and insert form preview content.
226 *
227 * @param string $content Existing post content.
228 * @return string
229 */
230 public static function form_preview_content_filter( $content ) {
231 if ( ! is_user_logged_in() || ! is_main_query() ) {
232 return $content;
233 }
234
235 self::$in_content_filter = true;
236
237 // Remove the filter we're in to avoid nested calls.
238 remove_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ) );
239
240 if ( current_user_can( 'everest_forms_view_forms', self::$form_id ) ) {
241 if ( function_exists( 'apply_shortcodes' ) ) {
242 $content = apply_shortcodes( '[everest_form id="' . absint( self::$form_id ) . '"]' );
243 } else {
244 $content = do_shortcode( '[everest_form id="' . absint( self::$form_id ) . '"]' );
245 }
246 }
247
248 self::$in_content_filter = false;
249
250 return $content;
251 }
252 }
253
254 add_action( 'init', array( 'EVF_Template_Loader', 'init' ) );
255