PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / trunk
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI vtrunk
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-install.php
everest-forms / includes Last commit date
Helpers 11 months ago Integrations 1 week ago RestApi 2 weeks ago abilities 2 weeks ago abstracts 2 weeks ago admin 2 weeks ago blocks 1 year ago elementor 2 years ago export 2 months ago fields 2 weeks ago interfaces 8 years ago libraries 2 years ago log-handlers 1 year ago shortcodes 2 weeks ago stats 5 months ago templates 3 months ago traits 2 weeks ago class-everest-forms.php 1 week ago class-evf-addon-upsell.php 2 weeks ago class-evf-ajax.php 2 weeks ago class-evf-autoloader.php 7 years ago class-evf-background-process-import-entries.php 1 year ago class-evf-background-updater.php 7 years ago class-evf-cache-helper.php 2 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 3 months ago class-evf-emails.php 2 weeks ago class-evf-fields.php 2 weeks ago class-evf-form-handler.php 2 weeks ago class-evf-form-task.php 2 weeks ago class-evf-forms-features.php 2 weeks ago class-evf-frontend-scripts.php 2 weeks ago class-evf-install.php 2 months ago class-evf-integrations.php 3 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 2 months ago class-evf-reporting.php 2 months ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 1 year ago class-evf-smart-tags.php 9 months ago class-evf-template-loader.php 1 year ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 2 weeks ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 4 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 7 years ago evf-update-functions.php 5 years ago
class-evf-install.php
749 lines
1 <?php
2 /**
3 * Installation related functions and actions.
4 *
5 * @package EverestForms\Classes
6 * @version 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Install Class.
13 */
14 class EVF_Install {
15
16 /**
17 * DB updates and callbacks that need to be run per version.
18 *
19 * @var array
20 */
21 private static $db_updates = array(
22 '1.0.0' => array(
23 'evf_update_100_db_version',
24 ),
25 '1.0.1' => array(
26 'evf_update_101_db_version',
27 ),
28 '1.0.2' => array(
29 'evf_update_102_db_version',
30 ),
31 '1.0.3' => array(
32 'evf_update_103_db_version',
33 ),
34 '1.1.0' => array(
35 'evf_update_110_update_forms',
36 'evf_update_110_db_version',
37 ),
38 '1.1.6' => array(
39 'evf_update_116_delete_options',
40 'evf_update_116_db_version',
41 ),
42 '1.2.0' => array(
43 'evf_update_120_db_rename_options',
44 'evf_update_120_db_version',
45 ),
46 '1.3.0' => array(
47 'evf_update_130_db_version',
48 ),
49 '1.4.0' => array(
50 'evf_update_140_db_multiple_email',
51 'evf_update_140_db_version',
52 ),
53 '1.4.4' => array(
54 'evf_update_144_delete_options',
55 'evf_update_144_db_version',
56 ),
57 '1.4.9' => array(
58 'evf_update_149_db_rename_options',
59 'evf_update_149_no_payment_options',
60 'evf_update_149_db_version',
61 ),
62 '1.5.0' => array(
63 'evf_update_150_field_datetime_type',
64 'evf_update_150_db_version',
65 ),
66 '1.6.0' => array(
67 'evf_update_160_db_version',
68 ),
69 '1.7.5' => array(
70 'evf_update_175_remove_capabilities',
71 'evf_update_175_restore_draft_forms',
72 'evf_update_175_db_version',
73 ),
74 );
75
76 /**
77 * Background update class.
78 *
79 * @var object
80 */
81 private static $background_updater;
82
83 /**
84 * Hook in tabs.
85 */
86 public static function init() {
87 add_action( 'init', array( __CLASS__, 'check_version' ), 5 );
88 add_action( 'init', array( __CLASS__, 'init_background_updater' ), 5 );
89 add_action( 'admin_init', array( __CLASS__, 'install_actions' ) );
90 add_filter( 'map_meta_cap', array( __CLASS__, 'filter_map_meta_cap' ), 10, 4 );
91 if ( defined( 'EVF_PLUGIN_BASENAME' ) ) {
92 add_filter( 'plugin_action_links_' . EVF_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) );
93 }
94 add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 );
95 add_filter( 'wpmu_drop_tables', array( __CLASS__, 'wpmu_drop_tables' ) );
96 add_filter( 'cron_schedules', array( __CLASS__, 'cron_schedules' ) );
97 }
98
99 /**
100 * Init background updates
101 */
102 public static function init_background_updater() {
103 include_once __DIR__ . '/class-evf-background-updater.php';
104 self::$background_updater = new EVF_Background_Updater();
105 }
106
107 /**
108 * Check EverestForms version and run the updater is required.
109 *
110 * This check is done on all requests and runs if the versions do not match.
111 */
112 public static function check_version() {
113 if ( ! defined( 'IFRAME_REQUEST' ) && version_compare( get_option( 'everest_forms_version' ), evf()->version, '<' ) ) {
114 self::install();
115 do_action( 'everest_forms_updated' );
116 }
117 }
118
119 /**
120 * Install actions when a update button is clicked within the admin area.
121 *
122 * This function is hooked into admin_init to affect admin only.
123 */
124 public static function install_actions() {
125 if ( ! empty( $_GET['do_update_everest_forms'] ) ) {
126 check_admin_referer( 'evf_db_update', 'evf_db_update_nonce' );
127 self::update();
128 EVF_Admin_Notices::add_notice( 'update' );
129 }
130 if ( ! empty( $_GET['force_update_everest_forms'] ) ) {
131 do_action( 'wp_' . get_current_blog_id() . '_evf_updater_cron' );
132 wp_safe_redirect( admin_url( 'admin.php?page=evf-settings' ) );
133 exit;
134 }
135 }
136
137 /**
138 * Install EVF.
139 */
140 public static function install() {
141 if ( ! is_blog_installed() ) {
142 return;
143 }
144
145 // Check if we are not already running this routine.
146 if ( 'yes' === get_transient( 'evf_installing' ) ) {
147 return;
148 }
149
150 // If we made it till here nothing is running yet, lets set the transient now.
151 set_transient( 'evf_installing', 'yes', MINUTE_IN_SECONDS * 10 );
152 evf_maybe_define_constant( 'EVF_INSTALLING', true );
153
154 self::remove_admin_notices();
155 self::create_options();
156 self::create_tables();
157 self::create_roles();
158 self::setup_environment();
159 self::create_cron_jobs();
160 self::create_files();
161 self::create_forms();
162 self::maybe_set_activation_transients();
163 self::update_evf_version();
164 self::maybe_update_db_version();
165 self::maybe_add_activated_date();
166
167 delete_transient( 'evf_installing' );
168 delete_transient( 'evf_template_section_list' );
169
170 do_action( 'everest_forms_flush_rewrite_rules' );
171 do_action( 'everest_forms_installed' );
172 }
173
174 /**
175 * Reset any notices added to admin.
176 */
177 private static function remove_admin_notices() {
178 include_once __DIR__ . '/admin/class-evf-admin-notices.php';
179 EVF_Admin_Notices::remove_all_notices();
180 }
181
182 /**
183 * Setup EVF environment - post types, taxonomies, endpoints.
184 */
185 private static function setup_environment() {
186 EVF_Post_Types::register_post_types();
187 }
188
189 /**
190 * Is this a brand new EVF install?
191 *
192 * @return boolean
193 */
194 private static function is_new_install() {
195 return is_null( get_option( 'everest_forms_version', null ) ) && is_null( get_option( 'everest_forms_db_version', null ) );
196 }
197
198 /**
199 * Is a DB update needed?
200 *
201 * @return boolean
202 */
203 public static function needs_db_update() {
204 $current_db_version = get_option( 'everest_forms_db_version', null );
205 $updates = self::get_db_update_callbacks();
206 $update_versions = array_keys( $updates );
207 usort( $update_versions, 'version_compare' );
208
209 return ! is_null( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' );
210 }
211
212 /**
213 * See if we need to set redirect transients for activation or not.
214 */
215 private static function maybe_set_activation_transients() {
216 if ( self::is_new_install() ) {
217 set_transient( '_evf_activation_redirect', 1, 30 );
218 }
219 }
220
221 /**
222 * See if we need to show or run database updates during install.
223 */
224 private static function maybe_update_db_version() {
225 if ( self::needs_db_update() ) {
226 if ( apply_filters( 'everest_forms_enable_auto_update_db', false ) ) {
227 self::init_background_updater();
228 self::update();
229 } else {
230 EVF_Admin_Notices::add_notice( 'update' );
231 }
232 } else {
233 self::update_db_version();
234 }
235 }
236
237 /**
238 * Store the initial plugin activation date during install.
239 */
240 private static function maybe_add_activated_date() {
241 $activated_date = get_option( 'everest_forms_activated', '' );
242
243 if ( empty( $activated_date ) ) {
244 update_option( 'everest_forms_activated', time() );
245 }
246 }
247
248 /**
249 * Update EVF version to current.
250 */
251 private static function update_evf_version() {
252 delete_option( 'everest_forms_version' );
253 add_option( 'everest_forms_version', evf()->version );
254 }
255
256 /**
257 * Get list of DB update callbacks.
258 *
259 * @return array
260 */
261 public static function get_db_update_callbacks() {
262 return self::$db_updates;
263 }
264
265 /**
266 * Push all needed DB updates to the queue for processing.
267 */
268 private static function update() {
269 $current_db_version = get_option( 'everest_forms_db_version' );
270 $logger = evf_get_logger();
271 $update_queued = false;
272
273 foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) {
274 if ( version_compare( $current_db_version, $version, '<' ) ) {
275 foreach ( $update_callbacks as $update_callback ) {
276 $logger->info(
277 sprintf( 'Queuing %s - %s', $version, $update_callback ),
278 array( 'source' => 'evf_db_updates' )
279 );
280 self::$background_updater->push_to_queue( $update_callback );
281 $update_queued = true;
282 }
283 }
284 }
285
286 if ( $update_queued ) {
287 self::$background_updater->save()->dispatch();
288 }
289 }
290
291 /**
292 * Update DB version to current.
293 *
294 * @param string|null $version New EverestForms DB version or null.
295 */
296 public static function update_db_version( $version = null ) {
297 delete_option( 'everest_forms_db_version' );
298 add_option( 'everest_forms_db_version', is_null( $version ) ? evf()->version : $version );
299 }
300
301 /**
302 * Add more cron schedules.
303 *
304 * @param array $schedules List of WP scheduled cron jobs.
305 * @return array
306 */
307 public static function cron_schedules( $schedules ) {
308 $schedules['monthly'] = array(
309 'interval' => 2635200,
310 'display' => __( 'Monthly', 'everest-forms' ),
311 );
312 return $schedules;
313 }
314
315 /**
316 * Create cron jobs (clear them first).
317 */
318 private static function create_cron_jobs() {
319 wp_clear_scheduled_hook( 'everest_forms_cleanup_logs' );
320 wp_clear_scheduled_hook( 'everest_forms_cleanup_sessions' );
321 wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'everest_forms_cleanup_logs' );
322 wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'everest_forms_cleanup_sessions' );
323 }
324
325 /**
326 * Default options.
327 *
328 * Sets up the default options used on the settings page.
329 */
330 private static function create_options() {
331 // Include settings so that we can run through defaults.
332 include_once __DIR__ . '/admin/class-evf-admin-settings.php';
333
334 $settings = EVF_Admin_Settings::get_settings_pages();
335
336 foreach ( $settings as $section ) {
337 if ( ! is_object( $section ) || ! method_exists( $section, 'get_settings' ) ) {
338 continue;
339 }
340
341 $subsections = array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) );
342
343 foreach ( $subsections as $subsection ) {
344 foreach ( $section->get_settings( $subsection ) as $value ) {
345 if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
346 $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
347 add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
348 }
349 }
350 }
351 }
352 }
353
354 /**
355 * Set up the database tables which the plugin needs to function.
356 */
357 private static function create_tables() {
358 global $wpdb;
359
360 $wpdb->hide_errors();
361
362 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
363
364 /**
365 * Before updating with DBDELTA, add fields column to entries table schema.
366 */
367 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}evf_entries';" ) ) {
368 if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}evf_entries` LIKE 'fields';" ) ) {
369 $wpdb->query( "ALTER TABLE {$wpdb->prefix}evf_entries ADD `fields` longtext NULL AFTER `referer`;" );
370 }
371 }
372
373 /**
374 * Change wp_evf_sessions schema to use a bigint auto increment field
375 * instead of char(32) field as the primary key. Doing this change primarily
376 * as it should reduce the occurrence of deadlocks, but also because it is
377 * not a good practice to use a char(32) field as the primary key of a table.
378 */
379 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}evf_sessions'" ) ) {
380 if ( ! $wpdb->get_var( "SHOW KEYS FROM {$wpdb->prefix}evf_sessions WHERE Key_name = 'PRIMARY' AND Column_name = 'session_id'" ) ) {
381 $wpdb->query(
382 "ALTER TABLE `{$wpdb->prefix}evf_sessions` DROP PRIMARY KEY, DROP KEY `session_id`, ADD PRIMARY KEY(`session_id`), ADD UNIQUE KEY(`session_key`)"
383 );
384 }
385 }
386
387 dbDelta( self::get_schema() );
388 }
389
390 /**
391 * Get Table schema.
392 *
393 * When adding or removing a table, make sure to update the list of tables in EVF_Install::get_tables().
394 *
395 * @return string
396 */
397 private static function get_schema() {
398 global $wpdb;
399
400 $charset_collate = '';
401
402 if ( $wpdb->has_cap( 'collation' ) ) {
403 $charset_collate = $wpdb->get_charset_collate();
404 }
405
406 $tables = "
407 CREATE TABLE {$wpdb->prefix}evf_entries (
408 entry_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
409 form_id BIGINT UNSIGNED NOT NULL,
410 user_id BIGINT UNSIGNED NOT NULL,
411 user_device varchar(100) NOT NULL,
412 user_ip_address VARCHAR(100) NULL DEFAULT '',
413 referer text NOT NULL,
414 fields longtext NULL,
415 status varchar(20) NOT NULL,
416 viewed tinyint(1) NOT NULL DEFAULT '0',
417 starred tinyint(1) NOT NULL DEFAULT '0',
418 date_created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
419 PRIMARY KEY (entry_id),
420 KEY form_id (form_id)
421 ) $charset_collate;
422 CREATE TABLE {$wpdb->prefix}evf_entrymeta (
423 meta_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
424 entry_id BIGINT UNSIGNED NOT NULL,
425 meta_key varchar(255) default NULL,
426 meta_value longtext NULL,
427 PRIMARY KEY (meta_id),
428 KEY entry_id (entry_id),
429 KEY meta_key (meta_key(32))
430 ) $charset_collate;
431 CREATE TABLE {$wpdb->prefix}evf_sessions (
432 session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
433 session_key char(32) NOT NULL,
434 session_value longtext NOT NULL,
435 session_expiry BIGINT UNSIGNED NOT NULL,
436 PRIMARY KEY (session_id),
437 UNIQUE KEY session_key (session_key)
438 ) $charset_collate;
439 ";
440
441 return $tables;
442 }
443
444 /**
445 * Return a list of EverestForms tables. Used to make sure all UM tables are dropped when uninstalling the plugin
446 * in a single site or multi site environment.
447 *
448 * @return array UM tables.
449 */
450 public static function get_tables() {
451 global $wpdb;
452
453 $tables = array(
454 "{$wpdb->prefix}evf_entries",
455 "{$wpdb->prefix}evf_entrymeta",
456 "{$wpdb->prefix}evf_sessions",
457 );
458
459 return $tables;
460 }
461
462 /**
463 * Drop EverestForms tables.
464 */
465 public static function drop_tables() {
466 global $wpdb;
467
468 $tables = self::get_tables();
469
470 foreach ( $tables as $table ) {
471 $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
472 }
473 }
474
475 /**
476 * Uninstall tables when MU blog is deleted.
477 *
478 * @param array $tables List of tables that will be deleted by WP.
479 * @return string[]
480 */
481 public static function wpmu_drop_tables( $tables ) {
482 return array_merge( $tables, self::get_tables() );
483 }
484
485 /**
486 * Create roles and capabilities.
487 */
488 public static function create_roles() {
489 global $wp_roles;
490
491 if ( ! class_exists( 'WP_Roles' ) ) {
492 return;
493 }
494
495 if ( ! isset( $wp_roles ) ) {
496 $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
497 }
498
499 $capabilities = self::get_core_capabilities();
500
501 foreach ( $capabilities as $cap_group ) {
502 foreach ( $cap_group as $cap ) {
503 $wp_roles->add_cap( 'administrator', $cap );
504 }
505 }
506 }
507
508 /**
509 * Get the core capabilities.
510 *
511 * Core capabilities are assigned to admin during installation or reset.
512 *
513 * @since 1.0.0
514 * @since 1.7.5 Removed unused post type capabilities and added supported ones.
515 *
516 * @return array $capabilities Core capabilities.
517 */
518 private static function get_core_capabilities() {
519 $capabilities = array();
520
521 $capabilities['core'] = array(
522 'manage_everest_forms',
523 );
524
525 $capability_types = array( 'forms', 'entries' );
526
527 foreach ( $capability_types as $capability_type ) {
528 if ( 'forms' === $capability_type ) {
529 $capabilities[ $capability_type ][] = "everest_forms_create_{$capability_type}";
530 }
531
532 foreach ( array( 'view', 'edit', 'delete' ) as $context ) {
533 $capabilities[ $capability_type ][] = "everest_forms_{$context}_{$capability_type}";
534 $capabilities[ $capability_type ][] = "everest_forms_{$context}_others_{$capability_type}";
535 }
536 }
537
538 return $capabilities;
539 }
540
541 /**
542 * Get the meta capabilities.
543 *
544 * @since 1.7.5
545 *
546 * @param string $cap Capability name to get.
547 * @return array $meta_caps Meta capabilities.
548 */
549 private static function get_meta_caps( $cap = '' ) {
550 $meta_caps = array();
551 $meta_cap_types = array( 'form', 'form_entries', 'entry' );
552
553 foreach ( $meta_cap_types as $meta_cap_type ) {
554 if ( $cap && $cap !== $meta_cap_type ) {
555 continue;
556 }
557
558 foreach ( array( 'view', 'edit', 'delete' ) as $context ) {
559 $meta_caps[ "everest_forms_{$context}_{$meta_cap_type}" ] = array(
560 'own' => 'form' === $meta_cap_type ? "everest_forms_{$context}_forms" : "everest_forms_{$context}_entries",
561 'others' => 'form' === $meta_cap_type ? "everest_forms_{$context}_others_forms" : "everest_forms_{$context}_others_entries",
562 );
563 }
564 }
565
566 return $meta_caps;
567 }
568
569 /**
570 * Remove EverestForms roles.
571 */
572 public static function remove_roles() {
573 global $wp_roles;
574
575 if ( ! class_exists( 'WP_Roles' ) ) {
576 return;
577 }
578
579 if ( ! isset( $wp_roles ) ) {
580 $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
581 }
582
583 $capabilities = self::get_core_capabilities();
584
585 foreach ( $capabilities as $cap_group ) {
586 foreach ( $cap_group as $cap ) {
587 $wp_roles->remove_cap( 'administrator', $cap );
588 }
589 }
590 }
591
592 /**
593 * Create default contact form.
594 */
595 public static function create_forms() {
596 $forms_count = wp_count_posts( 'everest_form' );
597
598 if ( empty( $forms_count->publish ) ) {
599 include_once __DIR__ . '/templates/contact.php';
600
601 // Create a form.
602 $form_id = wp_insert_post(
603 array(
604 'post_title' => esc_html__( 'Contact Form', 'everest-forms' ),
605 'post_status' => 'publish',
606 'post_type' => 'everest_form',
607 'post_content' => '{}',
608 )
609 );
610
611 if ( $form_id ) {
612 wp_update_post(
613 array(
614 'ID' => $form_id,
615 'post_content' => evf_encode( array_merge( array( 'id' => $form_id ), $form_template['contact'] ) ),
616 )
617 );
618 }
619
620 update_option( 'everest_forms_default_form_page_id', $form_id );
621 }
622 }
623
624 /**
625 * Create files/directories.
626 */
627 private static function create_files() {
628 // Bypass if filesystem is read-only and/or non-standard upload system is used.
629 if ( apply_filters( 'everest_forms_install_skip_create_files', false ) ) {
630 return;
631 }
632
633 // Install files and folders for uploading files and prevent hotlinking.
634 $files = array(
635 array(
636 'base' => EVF_LOG_DIR,
637 'file' => '.htaccess',
638 'content' => 'deny from all',
639 ),
640 array(
641 'base' => EVF_LOG_DIR,
642 'file' => 'index.html',
643 'content' => '',
644 ),
645 );
646
647 foreach ( $files as $file ) {
648 if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
649 $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
650 if ( $file_handle ) {
651 fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
652 fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
653 }
654 }
655 }
656 }
657
658 /**
659 * Filter user's capabilities for the given primitive or meta capability.
660 *
661 * @since 1.7.5
662 *
663 * @param string[] $caps Array of the user's capabilities.
664 * @param string $cap Capability being checked.
665 * @param int $user_id The user ID.
666 * @param array $args Adds context to the capability check, typically the object ID.
667 *
668 * @return string[] Array of required capabilities for the requested action.
669 */
670 public static function filter_map_meta_cap( $caps, $cap, $user_id, $args ) {
671 $meta_caps = self::get_meta_caps();
672 $entry_caps = self::get_meta_caps( 'entry' );
673
674 // Check if meta cap is valid to proceed.
675 if ( in_array( $cap, array_keys( $meta_caps ), true ) ) {
676 $id = isset( $args[0] ) ? (int) $args[0] : 0;
677
678 // Check if meta cap requires form ID from entry.
679 if ( in_array( $cap, array_keys( $entry_caps ), true ) ) {
680 $entry = evf_get_entry( $id, false, array( 'cap' => false ) );
681 if ( ! $entry ) {
682 return $caps;
683 }
684
685 $id = isset( $entry->form_id ) ? (int) $entry->form_id : 0;
686 }
687
688 $form = evf()->form->get( $id, array( 'cap' => false ) );
689 if ( ! $form ) {
690 return $caps;
691 }
692
693 if ( ! is_a( $form, 'WP_Post' ) ) {
694 return $caps;
695 }
696
697 if ( 'everest_form' !== $form->post_type ) {
698 return $caps;
699 }
700
701 // If the post author is set and the user is the author...
702 if ( $form->post_author && $user_id === (int) $form->post_author ) {
703 $caps = isset( $meta_caps[ $cap ]['own'] ) ? array( $meta_caps[ $cap ]['own'] ) : array( 'do_not_allow' );
704 } else {
705 // The user is trying someone else's form.
706 $caps = isset( $meta_caps[ $cap ]['others'] ) ? array( $meta_caps[ $cap ]['others'] ) : array( 'do_not_allow' );
707 }
708 }
709
710 return $caps;
711 }
712
713 /**
714 * Display action links in the Plugins list table.
715 *
716 * @param array $actions Plugin Action links.
717 * @return array
718 */
719 public static function plugin_action_links( $actions ) {
720 $new_actions = array(
721 'settings' => '<a href="' . admin_url( 'admin.php?page=evf-settings' ) . '" aria-label="' . esc_attr__( 'View Everest Forms Settings', 'everest-forms' ) . '">' . esc_html__( 'Settings', 'everest-forms' ) . '</a>',
722 );
723
724 return array_merge( $new_actions, $actions );
725 }
726
727 /**
728 * Display row meta in the Plugins list table.
729 *
730 * @param array $plugin_meta Plugin Row Meta.
731 * @param string $plugin_file Plugin Row Meta.
732 * @return array
733 */
734 public static function plugin_row_meta( $plugin_meta, $plugin_file ) {
735 if ( EVF_PLUGIN_BASENAME === $plugin_file ) {
736 $new_plugin_meta = array(
737 'docs' => '<a href="' . esc_url( apply_filters( 'everest_forms_docs_url', 'https://docs.everestforms.net/' ) ) . '" aria-label="' . esc_attr__( 'View Everest Forms documentation', 'everest-forms' ) . '">' . esc_html__( 'Docs', 'everest-forms' ) . '</a>',
738 'support' => '<a href="' . esc_url( apply_filters( 'everest_forms_support_url', 'https://wordpress.org/support/plugin/everest-forms/' ) ) . '" aria-label="' . esc_attr__( 'Visit free customer support', 'everest-forms' ) . '">' . esc_html__( 'Free support', 'everest-forms' ) . '</a>',
739 );
740
741 return array_merge( $plugin_meta, $new_plugin_meta );
742 }
743
744 return (array) $plugin_meta;
745 }
746 }
747
748 EVF_Install::init();
749