PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.6.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.6.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 6 years ago admin 6 years ago export 6 years ago fields 6 years ago interfaces 8 years ago libraries 7 years ago log-handlers 6 years ago shortcodes 6 years ago templates 6 years ago class-everest-forms.php 6 years ago class-evf-ajax.php 6 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-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 7 years ago class-evf-emails.php 6 years ago class-evf-fields.php 6 years ago class-evf-form-block.php 6 years ago class-evf-form-handler.php 6 years ago class-evf-form-task.php 6 years ago class-evf-forms-features.php 6 years ago class-evf-frontend-scripts.php 6 years ago class-evf-install.php 6 years ago class-evf-integrations.php 7 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 6 years ago class-evf-post-types.php 6 years ago class-evf-privacy.php 6 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 7 years ago class-evf-smart-tags.php 6 years ago class-evf-template-loader.php 6 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 6 years ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 6 years ago evf-formatting-functions.php 6 years ago evf-notice-functions.php 6 years ago evf-template-functions.php 6 years ago evf-template-hooks.php 7 years ago evf-update-functions.php 6 years ago
class-evf-template-loader.php
226 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( 'template_include', array( __CLASS__, 'template_include' ) );
40 add_action( 'template_redirect', array( __CLASS__, 'form_preview_init' ) );
41 } else {
42 add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
43 }
44 }
45
46 /**
47 * Hook into pre_get_posts to limit posts.
48 *
49 * @param WP_Query $q Query instance.
50 */
51 public static function pre_get_posts( $q ) {
52 // Limit one post to query.
53 if ( $q->is_main_query() ) {
54 $q->set( 'posts_per_page', 1 );
55 }
56 }
57
58 /**
59 * Change edit link of preview page.
60 *
61 * @param string $link Edit post link.
62 */
63 public static function edit_form_link( $link ) {
64 if ( 0 < self::$form_id ) {
65 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>';
66 }
67
68 return $link;
69 }
70
71 /**
72 * Limit page templates to singular pages only.
73 *
74 * @return string
75 */
76 public static function template_include() {
77 return locate_template( array( 'page.php', 'single.php', 'index.php' ) );
78 }
79
80 /**
81 * Load a template.
82 *
83 * Handles template usage so that we can use our own templates instead of the themes.
84 *
85 * Templates are in the 'templates' folder. everest-forms looks for theme.
86 * overrides in /theme/everest-forms/ by default.
87 *
88 * For beginners, it also looks for a everest-forms.php template first. If the user adds.
89 * this to the theme (containing a everest-forms() inside) this will be used for all.
90 * everest-forms templates.
91 *
92 * @param string $template Template to load.
93 * @return string
94 */
95 public static function template_loader( $template ) {
96 if ( is_embed() ) {
97 return $template;
98 }
99
100 $default_file = self::get_template_loader_default_file();
101
102 if ( $default_file ) {
103 /**
104 * Filter hook to choose which files to find before EverestForms does it's own logic.
105 *
106 * @since 1.0.0
107 * @var array
108 */
109 $search_files = self::get_template_loader_files( $default_file );
110 $template = locate_template( $search_files );
111
112 if ( ! $template || EVF_TEMPLATE_DEBUG_MODE ) {
113 $template = evf()->plugin_path() . '/templates/' . $default_file;
114 }
115 }
116
117 return $template;
118 }
119
120 /**
121 * Get the default filename for a template.
122 *
123 * @since 1.0.0
124 * @return string
125 */
126 private static function get_template_loader_default_file() {
127 return '';
128 }
129
130 /**
131 * Get an array of filenames to search for a given template.
132 *
133 * @since 1.0.0
134 * @param string $default_file The default file name.
135 * @return string[]
136 */
137 private static function get_template_loader_files( $default_file ) {
138 $search_files = apply_filters( 'everest_forms_template_loader_files', array(), $default_file );
139 $search_files[] = 'everest-forms.php';
140
141 if ( is_page_template() ) {
142 $search_files[] = get_page_template_slug();
143 }
144
145 $search_files[] = $default_file;
146 $search_files[] = evf()->template_path() . $default_file;
147
148 return array_unique( $search_files );
149 }
150
151 /*
152 |--------------------------------------------------------------------------
153 | Form Preview Handling
154 |--------------------------------------------------------------------------
155 */
156
157 /**
158 * Hook in methods to enhance the form preview.
159 */
160 public static function form_preview_init() {
161 if ( ! is_user_logged_in() || is_admin() ) {
162 return;
163 }
164
165 if ( 0 < self::$form_id ) {
166 add_filter( 'the_title', array( __CLASS__, 'form_preview_title_filter' ) );
167 add_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ) );
168 add_filter( 'get_the_excerpt', array( __CLASS__, 'form_preview_content_filter' ) );
169 add_filter( 'post_thumbnail_html', '__return_empty_string' );
170 }
171 }
172
173 /**
174 * Filter the title and insert form preview title.
175 *
176 * @param string $title Existing title.
177 * @return string
178 */
179 public static function form_preview_title_filter( $title ) {
180 $form = evf()->form->get(
181 self::$form_id,
182 array(
183 'content_only' => true,
184 )
185 );
186
187 if ( ! empty( $form['settings']['form_title'] ) && in_the_loop() ) {
188 if ( is_customize_preview() ) {
189 return esc_html( sanitize_text_field( $form['settings']['form_title'] ) );
190 }
191
192 /* translators: %s - Form name. */
193 return sprintf( esc_html__( '%s &ndash; Preview', 'everest-forms' ), sanitize_text_field( $form['settings']['form_title'] ) );
194 }
195
196 return $title;
197 }
198
199 /**
200 * Filter the content and insert form preview content.
201 *
202 * @param string $content Existing post content.
203 * @return string
204 */
205 public static function form_preview_content_filter( $content ) {
206 if ( ! is_user_logged_in() || ! is_main_query() || ! in_the_loop() ) {
207 return $content;
208 }
209
210 self::$in_content_filter = true;
211
212 // Remove the filter we're in to avoid nested calls.
213 remove_filter( 'the_content', array( __CLASS__, 'form_preview_content_filter' ) );
214
215 if ( current_user_can( 'manage_everest_forms' ) ) {
216 $content = do_shortcode( '[everest_form id="' . absint( self::$form_id ) . '"]' );
217 }
218
219 self::$in_content_filter = false;
220
221 return $content;
222 }
223 }
224
225 add_action( 'init', array( 'EVF_Template_Loader', 'init' ) );
226