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 / admin / class-evf-admin-menus.php
everest-forms / includes / admin Last commit date
builder 2 years ago plugin-updates 8 years ago settings 2 years ago views 2 years ago class-evf-admin-addons.php 4 years ago class-evf-admin-assets.php 2 years ago class-evf-admin-builder.php 7 years ago class-evf-admin-deactivation-feedback.php 3 years ago class-evf-admin-editor.php 4 years ago class-evf-admin-entries-table-list.php 3 years ago class-evf-admin-entries.php 4 years ago class-evf-admin-form-templates.php 3 years ago class-evf-admin-forms-table-list.php 3 years ago class-evf-admin-forms.php 3 years ago class-evf-admin-import-export.php 4 years ago class-evf-admin-menus.php 2 years ago class-evf-admin-notices.php 3 years ago class-evf-admin-settings.php 2 years ago class-evf-admin-tools.php 4 years ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 2 years ago evf-admin-functions.php 3 years ago
class-evf-admin-menus.php
447 lines
1 <?php
2 /**
3 * Setup menus in WP admin.
4 *
5 * @package EverestForms\Admin
6 * @version 1.2.0
7 * @since 1.0.0
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 if ( class_exists( 'EVF_Admin_Menus', false ) ) {
13 return new EVF_Admin_Menus();
14 }
15
16 /**
17 * EVF_Admin_Menus Class.
18 */
19 class EVF_Admin_Menus {
20
21 /**
22 * Hook in tabs.
23 */
24 public function __construct() {
25 // Add menus.
26 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
27 add_action( 'admin_menu', array( $this, 'builder_menu' ), 20 );
28 add_action( 'admin_menu', array( $this, 'entries_menu' ), 30 );
29 add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
30 add_action( 'admin_menu', array( $this, 'tools_menu' ), 60 );
31 // Add admin topbar menu.
32 add_action( 'admin_bar_menu', array( $this, 'admin_top_menu_bar' ), 100 );
33
34 if ( apply_filters( 'everest_forms_show_addons_page', true ) ) {
35 add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
36 }
37
38 if ( ! evf_get_license_plan() ) {
39 add_action( 'admin_menu', array( $this, 'upgrade_to_pro_menu' ), 80 );
40 }
41
42 add_action( 'admin_head', array( $this, 'menu_highlight' ) );
43 add_action( 'admin_head', array( $this, 'custom_menu_count' ) );
44 add_action( 'admin_head', array( $this, 'hide_submenu_items' ) );
45 add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
46 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 11, 3 );
47 }
48
49 /**
50 * Returns a base64 URL for the SVG for use in the menu.
51 *
52 * @param string $fill SVG Fill color code. Default: '#82878c'.
53 * @param bool $base64 Whether or not to return base64-encoded SVG.
54 * @return string
55 */
56 public static function get_icon_svg( $fill = '#82878c', $base64 = true ) {
57 $svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path fill="' . $fill . '" d="M18.1 4h-3.8l1.2 2h3.9zM20.6 8h-3.9l1.2 2h3.9zM20.6 18H5.8L12 7.9l2.5 4.1H12l-1.2 2h7.3L12 4.1 2.2 20h19.6z"/></g></svg>';
58
59 if ( $base64 ) {
60 return 'data:image/svg+xml;base64,' . base64_encode( $svg );
61 }
62
63 return $svg;
64 }
65
66 /**
67 * Admin top menu bar.
68 *
69 * @param \WP_Admin_Bar $wp_admin_bar Instance of admin bar.
70 */
71 public function admin_top_menu_bar( WP_Admin_Bar $wp_admin_bar ) {
72 if ( ! is_admin_bar_showing() || ! current_user_can( 'manage_everest_forms' ) ) {
73 return;
74 }
75
76 $wp_admin_bar->add_menu(
77 array(
78 'id' => 'everest-forms-menu',
79 'parent' => null,
80 'group' => null,
81 'title' => 'Everest Forms', // you can use img tag with image link. it will show the image icon Instead of the title.
82 'href' => admin_url( 'admin.php?page=evf-builder' ),
83 )
84 );
85
86 $wp_admin_bar->add_menu(
87 array(
88 'parent' => 'everest-forms-menu',
89 'id' => 'everest-forms-all-forms',
90 'title' => __( 'All Forms', 'everest-forms' ),
91 'href' => admin_url( 'admin.php?page=evf-builder' ),
92 )
93 );
94
95 $wp_admin_bar->add_menu(
96 array(
97 'parent' => 'everest-forms-menu',
98 'id' => 'everest-forms-add-new',
99 'title' => __( 'Add New', 'everest-forms' ),
100 'href' => admin_url( 'admin.php?page=evf-builder&create-form=1' ),
101 )
102 );
103
104 $wp_admin_bar->add_menu(
105 array(
106 'parent' => 'everest-forms-menu',
107 'id' => 'everest-forms-entries',
108 'title' => __( 'Entries', 'everest-forms' ),
109 'href' => admin_url( 'admin.php?page=evf-entries' ),
110 )
111 );
112
113 $wp_admin_bar->add_menu(
114 array(
115 'parent' => 'everest-forms-menu',
116 'id' => 'everest-forms-tools',
117 'title' => __( 'Tools', 'everest-forms' ),
118 'href' => admin_url( 'admin.php?page=evf-tools' ),
119 )
120 );
121
122 $href = add_query_arg(
123 array(
124 'utm_medium' => 'admin-bar',
125 'utm_source' => 'WordPress',
126 'utm_content' => 'Documentation',
127 ),
128 'https://docs.everestforms.net/'
129 );
130
131 $wp_admin_bar->add_menu(
132 array(
133 'parent' => 'everest-forms-menu',
134 'id' => 'everest-forms-docs',
135 'title' => __( 'Docs', 'everest-forms' ),
136 'href' => $href,
137 'meta' => array(
138 'target' => '_blank',
139 'rel' => 'noopener noreferrer',
140 ),
141 )
142 );
143
144 do_action( 'everest_forms_top_admin_bar_menu', $wp_admin_bar );
145 }
146
147 /**
148 * Add menu items.
149 */
150 public function admin_menu() {
151 add_menu_page( esc_html__( 'Everest Forms', 'everest-forms' ), esc_html__( 'Everest Forms', 'everest-forms' ), 'manage_everest_forms', 'everest-forms', null, self::get_icon_svg(), '55.5' );
152 }
153
154 /**
155 * Add menu items.
156 */
157 public function builder_menu() {
158 $builder_page = add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Builder', 'everest-forms' ), esc_html__( 'All Forms', 'everest-forms' ), current_user_can( 'everest_forms_create_forms' ) ? 'everest_forms_create_forms' : 'everest_forms_view_forms', 'evf-builder', array( $this, 'builder_page' ) );
159
160 add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Setup', 'everest-forms' ), esc_html__( 'Add New', 'everest-forms' ), current_user_can( 'everest_forms_create_forms' ) ? 'everest_forms_create_forms' : 'everest_forms_edit_forms', 'evf-builder&create-form=1', array( $this, 'builder_page' ) );
161
162 add_action( 'load-' . $builder_page, array( $this, 'builder_page_init' ) );
163
164 /*
165 * Page redirects based on user's capability as 'All Forms' and 'Add New' both have same handle.
166 *
167 * - If only `everest_forms_create_forms` roles - dont show view all forms list table.
168 * - If only `everest_forms_view_forms` roles - dont show create new template selection.
169 */
170 if ( ! current_user_can( 'manage_everest_forms' ) ) {
171 if ( ! current_user_can( 'everest_forms_create_forms' ) ) {
172 if ( isset( $_GET['page'], $_GET['create-form'] ) && 'evf-builder' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification
173 wp_safe_redirect( admin_url( 'admin.php?page=evf-builder' ) );
174 exit;
175 }
176 } elseif ( ! current_user_can( 'everest_forms_view_forms' ) ) {
177 if ( ! isset( $_GET['create-form'] ) && ( ! empty( $_GET['page'] ) && 'evf-builder' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
178 wp_safe_redirect( admin_url( 'admin.php?page=evf-builder&create-form=1' ) );
179 exit;
180 }
181 }
182 }
183 }
184
185 /**
186 * Loads builder page.
187 */
188 public function builder_page_init() {
189 global $current_tab, $forms_table_list;
190
191 evf()->form_fields();
192
193 // Include builder pages.
194 EVF_Admin_Builder::get_builder_pages();
195
196 // Get current tab/section.
197 $current_tab = empty( $_GET['tab'] ) ? 'fields' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
198
199 if ( ! isset( $_GET['tab'], $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
200 $forms_table_list = new EVF_Admin_Forms_Table_List();
201
202 // Add screen option.
203 add_screen_option(
204 'per_page',
205 array(
206 'default' => 20,
207 'option' => 'evf_forms_per_page',
208 )
209 );
210 }
211
212 do_action( 'everest_forms_builder_page_init' );
213 }
214
215 /**
216 * Add menu item.
217 */
218 public function entries_menu() {
219 $entries_page = add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Entries', 'everest-forms' ), esc_html__( 'Entries', 'everest-forms' ), current_user_can( 'everest_forms_view_entries' ) ? 'everest_forms_view_entries' : 'everest_forms_view_others_entries', 'evf-entries', array( $this, 'entries_page' ) );
220 add_action( 'load-' . $entries_page, array( $this, 'entries_page_init' ) );
221 }
222
223 /**
224 * Loads entries into memory.
225 */
226 public function entries_page_init() {
227 global $entries_table_list;
228
229 if ( ! isset( $_GET['view-entry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
230 $entries_table_list = new EVF_Admin_Entries_Table_List();
231
232 // Add screen option.
233 add_screen_option(
234 'per_page',
235 array(
236 'default' => 20,
237 'option' => 'evf_entries_per_page',
238 )
239 );
240 }
241
242 do_action( 'everest_forms_entries_page_init' );
243 }
244
245 /**
246 * Add menu item.
247 */
248 public function settings_menu() {
249 $settings_page = add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms settings', 'everest-forms' ), esc_html__( 'Settings', 'everest-forms' ), 'manage_everest_forms', 'evf-settings', array( $this, 'settings_page' ) );
250
251 add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
252 }
253
254 /**
255 * Loads settings page.
256 */
257 public function settings_page_init() {
258 global $current_tab, $current_section;
259
260 // Include settings pages.
261 EVF_Admin_Settings::get_settings_pages();
262
263 // Get current tab/section.
264 $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
265 $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
266
267 // Save settings if data has been posted.
268 if ( apply_filters( '' !== $current_section ? "everest_forms_save_settings_{$current_tab}_{$current_section}" : "everest_forms_save_settings_{$current_tab}", ! empty( $_POST ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
269 EVF_Admin_Settings::save();
270 }
271
272 // Add any posted messages.
273 if ( ! empty( $_GET['evf_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
274 EVF_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['evf_error'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
275 }
276
277 if ( ! empty( $_GET['evf_message'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
278 EVF_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['evf_message'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
279 }
280
281 do_action( 'everest_forms_settings_page_init' );
282 }
283
284 /**
285 * Add menu item.
286 */
287 public function tools_menu() {
288 add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms tools', 'everest-forms' ), esc_html__( 'Tools', 'everest-forms' ), 'manage_everest_forms', 'evf-tools', array( $this, 'tools_page' ) );
289 }
290
291 /**
292 * Add menu item.
293 */
294 public function upgrade_to_pro_menu() {
295 add_submenu_page(
296 'everest-forms',
297 esc_html__( 'Everest Forms Upgrade to Pro', 'everest-forms' ),
298 sprintf(
299 '<span style="color:#FF8C39; font-weight: 600;"><svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: bottom;" ><rect x="0.5" y="0.5" width="19" height="19" rx="2.5" fill="#FF8C39" stroke="#FF8C39"/><path d="M10 5L13 13H7L10 5Z" fill="#EFEFEF"/><path fill="white" fill-rule="evenodd" d="M5 7L5.71429 13H14.2857L15 7L10 11.125L5 7ZM14.2857 13.5714H5.71427V15H14.2857V13.5714Z" clip-rule="evenodd"/></svg><span style="margin-left:5px;">%s</span></span>',
300 esc_html__( 'Upgrade to Pro', 'everest-forms' )
301 ),
302 'manage_everest_forms',
303 esc_url_raw( 'https://everestforms.net/pricing/' )
304 );
305 }
306
307 /**
308 * Addons menu item.
309 */
310 public function addons_menu() {
311 add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Add-ons', 'everest-forms' ), esc_html__( 'Add-ons', 'everest-forms' ), 'manage_everest_forms', 'evf-addons', array( $this, 'addons_page' ) );
312 }
313
314 /**
315 * Highlights the correct top level admin menu item.
316 */
317 public function menu_highlight() {
318 global $parent_file, $submenu_file;
319
320 $screen = get_current_screen();
321 $screen_id = $screen ? $screen->id : '';
322
323 // Check to make sure we're on a EverestForms builder setup page.
324 if ( isset( $_GET['create-form'] ) && in_array( $screen_id, array( 'everest-forms_page_evf-builder' ), true ) ) { // phpcs:ignore WordPress.Security.NonceVerification
325 $parent_file = 'everest-forms'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride
326 $submenu_file = 'evf-builder&create-form=1'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride
327 }
328 }
329
330 /**
331 * Adds the custom count to the menu.
332 */
333 public function custom_menu_count() {
334 global $submenu;
335
336 // Add count if user has access.
337 if ( isset( $submenu['everest-forms'] ) ) {
338 if ( apply_filters( 'everest_forms_include_count_in_menu', true ) && current_user_can( 'manage_everest_forms' ) ) {
339 do_action( 'everest_forms_custom_menu_count' );
340 }
341 }
342 }
343
344 /**
345 * Hide submenu menu item if a user can't access.
346 *
347 * @since 1.7.5
348 */
349 public function hide_submenu_items() {
350 global $submenu;
351
352 if ( ! isset( $submenu['everest-forms'] ) ) {
353 return;
354 }
355
356 // Remove 'Everest Forms' sub menu item.
357 foreach ( $submenu['everest-forms'] as $key => $item ) {
358 if ( isset( $item[2] ) && 'everest-forms' === $item[2] ) {
359 unset( $submenu['everest-forms'][ $key ] );
360 break;
361 }
362 }
363
364 // Remove 'All Forms' sub menu item if a user can't read forms.
365 if ( ! current_user_can( 'everest_forms_view_forms' ) ) {
366 foreach ( $submenu['everest-forms'] as $key => $item ) {
367 if ( isset( $item[2] ) && 'evf-builder' === $item[2] ) {
368 unset( $submenu['everest-forms'][ $key ] );
369 break;
370 }
371 }
372 }
373
374 // Remove 'Add New' sub menu item if a user can't create forms.
375 if ( ! current_user_can( 'everest_forms_create_forms' ) ) {
376 foreach ( $submenu['everest-forms'] as $key => $item ) {
377 if ( isset( $item[2] ) && 'evf-builder&create-form=1' === $item[2] ) {
378 unset( $submenu['everest-forms'][ $key ] );
379 break;
380 }
381 }
382 }
383 }
384
385 /**
386 * Custom menu order.
387 *
388 * @param bool $enabled Whether custom menu ordering is already enabled.
389 * @return bool
390 */
391 public function custom_menu_order( $enabled ) {
392 return $enabled || current_user_can( 'manage_everest_forms' );
393 }
394
395 /**
396 * Validate screen options on update.
397 *
398 * @param bool|int $status Screen option value. Default false to skip.
399 * @param string $option The option name.
400 * @param int $value The number of rows to use.
401 */
402 public function set_screen_option( $status, $option, $value ) {
403 if ( in_array( $option, array( 'evf_forms_per_page', 'evf_entries_per_page' ), true ) ) {
404 return $value;
405 }
406
407 return $status;
408 }
409
410 /**
411 * Init the settings page.
412 */
413 public function builder_page() {
414 EVF_Admin_Forms::page_output();
415 }
416
417 /**
418 * Init the entries page.
419 */
420 public function entries_page() {
421 EVF_Admin_Entries::page_output();
422 }
423
424 /**
425 * Init the settings page.
426 */
427 public function settings_page() {
428 EVF_Admin_Settings::output();
429 }
430
431 /**
432 * Init the status page.
433 */
434 public function tools_page() {
435 EVF_Admin_Tools::output();
436 }
437
438 /**
439 * Init the addons page.
440 */
441 public function addons_page() {
442 EVF_Admin_Addons::output();
443 }
444 }
445
446 return new EVF_Admin_Menus();
447