PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.9.4
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.9.4
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 / admin / class-evf-admin-forms.php
everest-forms / includes / admin Last commit date
builder 3 years ago plugin-updates 8 years ago settings 4 years ago views 4 years ago class-evf-admin-addons.php 4 years ago class-evf-admin-assets.php 3 years ago class-evf-admin-builder.php 8 years ago class-evf-admin-editor.php 4 years ago class-evf-admin-entries-table-list.php 4 years ago class-evf-admin-entries.php 4 years ago class-evf-admin-forms-table-list.php 4 years ago class-evf-admin-forms.php 4 years ago class-evf-admin-import-export.php 4 years ago class-evf-admin-menus.php 5 years ago class-evf-admin-notices.php 4 years ago class-evf-admin-settings.php 3 years ago class-evf-admin-tools.php 4 years ago class-evf-admin-welcome.php 5 years ago class-evf-admin.php 4 years ago evf-admin-functions.php 3 years ago
class-evf-admin-forms.php
275 lines
1 <?php
2 /**
3 * EverestForms Admin Forms Class
4 *
5 * @package EverestForms\Admin
6 * @since 1.2.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Admin_Forms class.
13 */
14 class EVF_Admin_Forms {
15
16 /**
17 * Initialize the forms admin actions.
18 */
19 public function __construct() {
20 add_action( 'admin_init', array( $this, 'actions' ) );
21 add_action( 'deleted_post', array( $this, 'delete_entries' ) );
22 add_filter( 'wp_untrash_post_status', array( $this, 'untrash_form_status' ), 10, 2 );
23 }
24
25 /**
26 * Check if is forms page.
27 *
28 * @return bool
29 */
30 private function is_forms_page() {
31 return isset( $_GET['page'] ) && 'evf-builder' === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification
32 }
33
34 /**
35 * Page output.
36 */
37 public static function page_output() {
38 global $current_tab;
39
40 if ( isset( $_GET['form_id'] ) && $current_tab ) { // phpcs:ignore WordPress.Security.NonceVerification
41 $form = evf()->form->get( absint( $_GET['form_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
42 $form_id = is_object( $form ) ? absint( $form->ID ) : absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
43 $form_data = is_object( $form ) ? evf_decode( $form->post_content ) : false;
44
45 include 'views/html-admin-page-builder.php';
46 } elseif ( isset( $_GET['create-form'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
47 $templates = array();
48 $refresh_url = add_query_arg(
49 array(
50 'page' => 'evf-builder&create-form=1',
51 'action' => 'evf-template-refresh',
52 'evf-template-nonce' => wp_create_nonce( 'refresh' ),
53 ),
54 admin_url( 'admin.php' )
55 );
56 $license_plan = evf_get_license_plan();
57 $current_section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '_all'; // phpcs:ignore WordPress.Security.NonceVerification
58
59 if ( '_featured' !== $current_section ) {
60 $category = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : 'free'; // phpcs:ignore WordPress.Security.NonceVerification
61 $templates = self::get_template_data( $category );
62 }
63
64 /**
65 * Addon page view.
66 *
67 * @uses $templates
68 * @uses $refresh_url
69 * @uses $current_section
70 */
71 include 'views/html-admin-page-builder-setup.php';
72 } else {
73 self::table_list_output();
74 }
75 }
76
77 /**
78 * Get sections for the addons screen.
79 *
80 * @return array of objects
81 */
82 public static function get_sections() {
83 $template_sections = get_transient( 'evf_template_sections_list' );
84
85 if ( false === $template_sections ) {
86 $template_sections = evf_get_json_file_contents( 'assets/extensions-json/templates/template-sections.json' );
87
88 if ( $template_sections ) {
89 set_transient( 'evf_template_sections_list', $template_sections, WEEK_IN_SECONDS );
90 }
91 }
92
93 return apply_filters( 'everest_forms_template_sections', $template_sections );
94 }
95
96 /**
97 * Get section content for the template screen.
98 *
99 * @return array
100 */
101 public static function get_template_data() {
102 $template_data = get_transient( 'evf_template_section_list' );
103
104 if ( false === $template_data ) {
105 $template_data = evf_get_json_file_contents( 'assets/extensions-json/templates/all_templates.json' );
106 // Removing directory so the templates can be reinitialized.
107 $folder_path = untrailingslashit( plugin_dir_path( EVF_PLUGIN_FILE ) . '/assets/images/templates' );
108
109 foreach ( $template_data->templates as $template_tuple ) {
110 // We retrieve the image, then use them instead of the remote server.
111 $image = wp_remote_get( $template_tuple->image );
112 $type = wp_remote_retrieve_header( $image, 'content-type' );
113
114 // Remote file check failed, we'll fallback to remote image.
115 if ( ! $type ) {
116 continue;
117 }
118
119 $temp_name = explode( '/', $template_tuple->image );
120 $relative_path = $folder_path . '/' . end( $temp_name );
121 $exists = file_exists( $relative_path );
122
123 // If it exists, utilize this file instead of remote file.
124 if ( $exists ) {
125 $template_tuple->image = plugin_dir_url( EVF_PLUGIN_FILE ) . 'assets/images/templates/' . end( $temp_name );
126 }
127 }
128
129 if ( ! empty( $template_data->templates ) ) {
130 set_transient( 'evf_template_section_list', $template_data, WEEK_IN_SECONDS );
131 }
132 }
133
134 if ( ! empty( $template_data->templates ) ) {
135 return apply_filters( 'everest_forms_template_section_data', $template_data->templates );
136 }
137 }
138
139 /**
140 * Table list output.
141 */
142 public static function table_list_output() {
143 global $forms_table_list;
144
145 $forms_table_list->process_bulk_action();
146 $forms_table_list->prepare_items();
147 ?>
148 <div class="wrap">
149 <h1 class="wp-heading-inline"><?php esc_html_e( 'All Forms', 'everest-forms' ); ?></h1>
150 <?php if ( current_user_can( 'everest_forms_create_forms' ) ) : ?>
151 <a href="<?php echo esc_url( admin_url( 'admin.php?page=evf-builder&create-form=1' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add New', 'everest-forms' ); ?></a>
152 <?php endif; ?>
153 <hr class="wp-header-end">
154
155 <?php settings_errors(); ?>
156
157 <form id="form-list" method="post">
158 <input type="hidden" name="page" value="everest-forms"/>
159 <?php
160 $forms_table_list->views();
161 $forms_table_list->search_box( __( 'Search Forms', 'everest-forms' ), 'everest-forms' );
162 $forms_table_list->display();
163
164 wp_nonce_field( 'save', 'everest-forms_nonce' );
165 ?>
166 </form>
167 </div>
168 <?php
169 }
170
171 /**
172 * Forms admin actions.
173 */
174 public function actions() {
175 if ( $this->is_forms_page() ) {
176 // Empty trash.
177 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
178 $this->empty_trash();
179 }
180
181 // Duplicate form.
182 if ( isset( $_REQUEST['action'] ) && 'duplicate_form' === $_REQUEST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification
183 $this->duplicate_form();
184 }
185 }
186 }
187
188 /**
189 * Empty Trash.
190 */
191 private function empty_trash() {
192 check_admin_referer( 'bulk-forms' );
193
194 $count = 0;
195 $form_ids = get_posts(
196 array(
197 'post_type' => 'everest_form',
198 'ignore_sticky_posts' => true,
199 'nopaging' => true,
200 'post_status' => 'trash',
201 'fields' => 'ids',
202 )
203 );
204
205 foreach ( $form_ids as $form_id ) {
206 if ( wp_delete_post( $form_id, true ) ) {
207 $count ++;
208 }
209 }
210
211 add_settings_error(
212 'empty_trash',
213 'empty_trash',
214 /* translators: %d: number of forms */
215 sprintf( _n( '%d form permanently deleted.', '%d forms permanently deleted.', $count, 'everest-forms' ), $count ),
216 'updated'
217 );
218 }
219
220 /**
221 * Duplicate form.
222 */
223 private function duplicate_form() {
224 if ( empty( $_REQUEST['form_id'] ) ) {
225 wp_die( esc_html__( 'No form to duplicate has been supplied!', 'everest-forms' ) );
226 }
227
228 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : '';
229
230 check_admin_referer( 'everest-forms-duplicate-form_' . $form_id );
231
232 $duplicate_id = evf()->form->duplicate( $form_id );
233
234 // Redirect to the edit screen for the new form page.
235 wp_safe_redirect( admin_url( 'admin.php?page=evf-builder&tab=fields&form_id=' . $duplicate_id ) );
236 exit;
237 }
238
239 /**
240 * Remove entry and its associated meta.
241 *
242 * When form is deleted then it also deletes its entries meta.
243 *
244 * @param int $postid Post ID.
245 */
246 public function delete_entries( $postid ) {
247 global $wpdb;
248
249 $entries = evf_get_entries_ids( $postid );
250
251 // Delete entry.
252 if ( ! empty( $entries ) ) {
253 foreach ( $entries as $entry_id ) {
254 $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) );
255 $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) );
256 }
257 }
258 }
259
260 /**
261 * Untrash form status.
262 *
263 * @since 1.7.5
264 *
265 * @param string $new_status The new status of the post being restored.
266 * @param int $post_id The ID of the post being restored.
267 * @return string
268 */
269 public function untrash_form_status( $new_status, $post_id ) {
270 return current_user_can( 'everest_forms_edit_forms', $post_id ) ? 'publish' : $new_status;
271 }
272 }
273
274 new EVF_Admin_Forms();
275