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-install.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-install.php
747 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
169 do_action( 'everest_forms_flush_rewrite_rules' );
170 do_action( 'everest_forms_installed' );
171 }
172
173 /**
174 * Reset any notices added to admin.
175 */
176 private static function remove_admin_notices() {
177 include_once __DIR__ . '/admin/class-evf-admin-notices.php';
178 EVF_Admin_Notices::remove_all_notices();
179 }
180
181 /**
182 * Setup EVF environment - post types, taxonomies, endpoints.
183 */
184 private static function setup_environment() {
185 EVF_Post_Types::register_post_types();
186 }
187
188 /**
189 * Is this a brand new EVF install?
190 *
191 * @return boolean
192 */
193 private static function is_new_install() {
194 return is_null( get_option( 'everest_forms_version', null ) ) && is_null( get_option( 'everest_forms_db_version', null ) );
195 }
196
197 /**
198 * Is a DB update needed?
199 *
200 * @return boolean
201 */
202 public static function needs_db_update() {
203 $current_db_version = get_option( 'everest_forms_db_version', null );
204 $updates = self::get_db_update_callbacks();
205 $update_versions = array_keys( $updates );
206 usort( $update_versions, 'version_compare' );
207
208 return ! is_null( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' );
209 }
210
211 /**
212 * See if we need to set redirect transients for activation or not.
213 */
214 private static function maybe_set_activation_transients() {
215 if ( self::is_new_install() ) {
216 set_transient( '_evf_activation_redirect', 1, 30 );
217 }
218 }
219
220 /**
221 * See if we need to show or run database updates during install.
222 */
223 private static function maybe_update_db_version() {
224 if ( self::needs_db_update() ) {
225 if ( apply_filters( 'everest_forms_enable_auto_update_db', false ) ) {
226 self::init_background_updater();
227 self::update();
228 } else {
229 EVF_Admin_Notices::add_notice( 'update' );
230 }
231 } else {
232 self::update_db_version();
233 }
234 }
235
236 /**
237 * Store the initial plugin activation date during install.
238 */
239 private static function maybe_add_activated_date() {
240 $activated_date = get_option( 'everest_forms_activated', '' );
241
242 if ( empty( $activated_date ) ) {
243 update_option( 'everest_forms_activated', time() );
244 }
245 }
246
247 /**
248 * Update EVF version to current.
249 */
250 private static function update_evf_version() {
251 delete_option( 'everest_forms_version' );
252 add_option( 'everest_forms_version', evf()->version );
253 }
254
255 /**
256 * Get list of DB update callbacks.
257 *
258 * @return array
259 */
260 public static function get_db_update_callbacks() {
261 return self::$db_updates;
262 }
263
264 /**
265 * Push all needed DB updates to the queue for processing.
266 */
267 private static function update() {
268 $current_db_version = get_option( 'everest_forms_db_version' );
269 $logger = evf_get_logger();
270 $update_queued = false;
271
272 foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) {
273 if ( version_compare( $current_db_version, $version, '<' ) ) {
274 foreach ( $update_callbacks as $update_callback ) {
275 $logger->info(
276 sprintf( 'Queuing %s - %s', $version, $update_callback ),
277 array( 'source' => 'evf_db_updates' )
278 );
279 self::$background_updater->push_to_queue( $update_callback );
280 $update_queued = true;
281 }
282 }
283 }
284
285 if ( $update_queued ) {
286 self::$background_updater->save()->dispatch();
287 }
288 }
289
290 /**
291 * Update DB version to current.
292 *
293 * @param string|null $version New EverestForms DB version or null.
294 */
295 public static function update_db_version( $version = null ) {
296 delete_option( 'everest_forms_db_version' );
297 add_option( 'everest_forms_db_version', is_null( $version ) ? evf()->version : $version );
298 }
299
300 /**
301 * Add more cron schedules.
302 *
303 * @param array $schedules List of WP scheduled cron jobs.
304 * @return array
305 */
306 public static function cron_schedules( $schedules ) {
307 $schedules['monthly'] = array(
308 'interval' => 2635200,
309 'display' => __( 'Monthly', 'everest-forms' ),
310 );
311 return $schedules;
312 }
313
314 /**
315 * Create cron jobs (clear them first).
316 */
317 private static function create_cron_jobs() {
318 wp_clear_scheduled_hook( 'everest_forms_cleanup_logs' );
319 wp_clear_scheduled_hook( 'everest_forms_cleanup_sessions' );
320 wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'everest_forms_cleanup_logs' );
321 wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'everest_forms_cleanup_sessions' );
322 }
323
324 /**
325 * Default options.
326 *
327 * Sets up the default options used on the settings page.
328 */
329 private static function create_options() {
330 // Include settings so that we can run through defaults.
331 include_once __DIR__ . '/admin/class-evf-admin-settings.php';
332
333 $settings = EVF_Admin_Settings::get_settings_pages();
334
335 foreach ( $settings as $section ) {
336 if ( ! method_exists( $section, 'get_settings' ) ) {
337 continue;
338 }
339 $subsections = array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) );
340
341 foreach ( $subsections as $subsection ) {
342 foreach ( $section->get_settings( $subsection ) as $value ) {
343 if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
344 $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
345 add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
346 }
347 }
348 }
349 }
350 }
351
352 /**
353 * Set up the database tables which the plugin needs to function.
354 */
355 private static function create_tables() {
356 global $wpdb;
357
358 $wpdb->hide_errors();
359
360 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
361
362 /**
363 * Before updating with DBDELTA, add fields column to entries table schema.
364 */
365 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}evf_entries';" ) ) {
366 if ( ! $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}evf_entries` LIKE 'fields';" ) ) {
367 $wpdb->query( "ALTER TABLE {$wpdb->prefix}evf_entries ADD `fields` longtext NULL AFTER `referer`;" );
368 }
369 }
370
371 /**
372 * Change wp_evf_sessions schema to use a bigint auto increment field
373 * instead of char(32) field as the primary key. Doing this change primarily
374 * as it should reduce the occurrence of deadlocks, but also because it is
375 * not a good practice to use a char(32) field as the primary key of a table.
376 */
377 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}evf_sessions'" ) ) {
378 if ( ! $wpdb->get_var( "SHOW KEYS FROM {$wpdb->prefix}evf_sessions WHERE Key_name = 'PRIMARY' AND Column_name = 'session_id'" ) ) {
379 $wpdb->query(
380 "ALTER TABLE `{$wpdb->prefix}evf_sessions` DROP PRIMARY KEY, DROP KEY `session_id`, ADD PRIMARY KEY(`session_id`), ADD UNIQUE KEY(`session_key`)"
381 );
382 }
383 }
384
385 dbDelta( self::get_schema() );
386 }
387
388 /**
389 * Get Table schema.
390 *
391 * When adding or removing a table, make sure to update the list of tables in EVF_Install::get_tables().
392 *
393 * @return string
394 */
395 private static function get_schema() {
396 global $wpdb;
397
398 $charset_collate = '';
399
400 if ( $wpdb->has_cap( 'collation' ) ) {
401 $charset_collate = $wpdb->get_charset_collate();
402 }
403
404 $tables = "
405 CREATE TABLE {$wpdb->prefix}evf_entries (
406 entry_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
407 form_id BIGINT UNSIGNED NOT NULL,
408 user_id BIGINT UNSIGNED NOT NULL,
409 user_device varchar(100) NOT NULL,
410 user_ip_address VARCHAR(100) NULL DEFAULT '',
411 referer text NOT NULL,
412 fields longtext NULL,
413 status varchar(20) NOT NULL,
414 viewed tinyint(1) NOT NULL DEFAULT '0',
415 starred tinyint(1) NOT NULL DEFAULT '0',
416 date_created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
417 PRIMARY KEY (entry_id),
418 KEY form_id (form_id)
419 ) $charset_collate;
420 CREATE TABLE {$wpdb->prefix}evf_entrymeta (
421 meta_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
422 entry_id BIGINT UNSIGNED NOT NULL,
423 meta_key varchar(255) default NULL,
424 meta_value longtext NULL,
425 PRIMARY KEY (meta_id),
426 KEY entry_id (entry_id),
427 KEY meta_key (meta_key(32))
428 ) $charset_collate;
429 CREATE TABLE {$wpdb->prefix}evf_sessions (
430 session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
431 session_key char(32) NOT NULL,
432 session_value longtext NOT NULL,
433 session_expiry BIGINT UNSIGNED NOT NULL,
434 PRIMARY KEY (session_id),
435 UNIQUE KEY session_key (session_key)
436 ) $charset_collate;
437 ";
438
439 return $tables;
440 }
441
442 /**
443 * Return a list of EverestForms tables. Used to make sure all UM tables are dropped when uninstalling the plugin
444 * in a single site or multi site environment.
445 *
446 * @return array UM tables.
447 */
448 public static function get_tables() {
449 global $wpdb;
450
451 $tables = array(
452 "{$wpdb->prefix}evf_entries",
453 "{$wpdb->prefix}evf_entrymeta",
454 "{$wpdb->prefix}evf_sessions",
455 );
456
457 return $tables;
458 }
459
460 /**
461 * Drop EverestForms tables.
462 */
463 public static function drop_tables() {
464 global $wpdb;
465
466 $tables = self::get_tables();
467
468 foreach ( $tables as $table ) {
469 $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
470 }
471 }
472
473 /**
474 * Uninstall tables when MU blog is deleted.
475 *
476 * @param array $tables List of tables that will be deleted by WP.
477 * @return string[]
478 */
479 public static function wpmu_drop_tables( $tables ) {
480 return array_merge( $tables, self::get_tables() );
481 }
482
483 /**
484 * Create roles and capabilities.
485 */
486 public static function create_roles() {
487 global $wp_roles;
488
489 if ( ! class_exists( 'WP_Roles' ) ) {
490 return;
491 }
492
493 if ( ! isset( $wp_roles ) ) {
494 $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
495 }
496
497 $capabilities = self::get_core_capabilities();
498
499 foreach ( $capabilities as $cap_group ) {
500 foreach ( $cap_group as $cap ) {
501 $wp_roles->add_cap( 'administrator', $cap );
502 }
503 }
504 }
505
506 /**
507 * Get the core capabilities.
508 *
509 * Core capabilities are assigned to admin during installation or reset.
510 *
511 * @since 1.0.0
512 * @since 1.7.5 Removed unused post type capabilities and added supported ones.
513 *
514 * @return array $capabilities Core capabilities.
515 */
516 private static function get_core_capabilities() {
517 $capabilities = array();
518
519 $capabilities['core'] = array(
520 'manage_everest_forms',
521 );
522
523 $capability_types = array( 'forms', 'entries' );
524
525 foreach ( $capability_types as $capability_type ) {
526 if ( 'forms' === $capability_type ) {
527 $capabilities[ $capability_type ][] = "everest_forms_create_{$capability_type}";
528 }
529
530 foreach ( array( 'view', 'edit', 'delete' ) as $context ) {
531 $capabilities[ $capability_type ][] = "everest_forms_{$context}_{$capability_type}";
532 $capabilities[ $capability_type ][] = "everest_forms_{$context}_others_{$capability_type}";
533 }
534 }
535
536 return $capabilities;
537 }
538
539 /**
540 * Get the meta capabilities.
541 *
542 * @since 1.7.5
543 *
544 * @param string $cap Capability name to get.
545 * @return array $meta_caps Meta capabilities.
546 */
547 private static function get_meta_caps( $cap = '' ) {
548 $meta_caps = array();
549 $meta_cap_types = array( 'form', 'form_entries', 'entry' );
550
551 foreach ( $meta_cap_types as $meta_cap_type ) {
552 if ( $cap && $cap !== $meta_cap_type ) {
553 continue;
554 }
555
556 foreach ( array( 'view', 'edit', 'delete' ) as $context ) {
557 $meta_caps[ "everest_forms_{$context}_{$meta_cap_type}" ] = array(
558 'own' => 'form' === $meta_cap_type ? "everest_forms_{$context}_forms" : "everest_forms_{$context}_entries",
559 'others' => 'form' === $meta_cap_type ? "everest_forms_{$context}_others_forms" : "everest_forms_{$context}_others_entries",
560 );
561 }
562 }
563
564 return $meta_caps;
565 }
566
567 /**
568 * Remove EverestForms roles.
569 */
570 public static function remove_roles() {
571 global $wp_roles;
572
573 if ( ! class_exists( 'WP_Roles' ) ) {
574 return;
575 }
576
577 if ( ! isset( $wp_roles ) ) {
578 $wp_roles = new WP_Roles(); // @codingStandardsIgnoreLine
579 }
580
581 $capabilities = self::get_core_capabilities();
582
583 foreach ( $capabilities as $cap_group ) {
584 foreach ( $cap_group as $cap ) {
585 $wp_roles->remove_cap( 'administrator', $cap );
586 }
587 }
588 }
589
590 /**
591 * Create default contact form.
592 */
593 public static function create_forms() {
594 $forms_count = wp_count_posts( 'everest_form' );
595
596 if ( empty( $forms_count->publish ) ) {
597 include_once __DIR__ . '/templates/contact.php';
598
599 // Create a form.
600 $form_id = wp_insert_post(
601 array(
602 'post_title' => esc_html__( 'Contact Form', 'everest-forms' ),
603 'post_status' => 'publish',
604 'post_type' => 'everest_form',
605 'post_content' => '{}',
606 )
607 );
608
609 if ( $form_id ) {
610 wp_update_post(
611 array(
612 'ID' => $form_id,
613 'post_content' => evf_encode( array_merge( array( 'id' => $form_id ), $form_template['contact'] ) ),
614 )
615 );
616 }
617
618 update_option( 'everest_forms_default_form_page_id', $form_id );
619 }
620 }
621
622 /**
623 * Create files/directories.
624 */
625 private static function create_files() {
626 // Bypass if filesystem is read-only and/or non-standard upload system is used.
627 if ( apply_filters( 'everest_forms_install_skip_create_files', false ) ) {
628 return;
629 }
630
631 // Install files and folders for uploading files and prevent hotlinking.
632 $files = array(
633 array(
634 'base' => EVF_LOG_DIR,
635 'file' => '.htaccess',
636 'content' => 'deny from all',
637 ),
638 array(
639 'base' => EVF_LOG_DIR,
640 'file' => 'index.html',
641 'content' => '',
642 ),
643 );
644
645 foreach ( $files as $file ) {
646 if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
647 $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
648 if ( $file_handle ) {
649 fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
650 fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
651 }
652 }
653 }
654 }
655
656 /**
657 * Filter user's capabilities for the given primitive or meta capability.
658 *
659 * @since 1.7.5
660 *
661 * @param string[] $caps Array of the user's capabilities.
662 * @param string $cap Capability being checked.
663 * @param int $user_id The user ID.
664 * @param array $args Adds context to the capability check, typically the object ID.
665 *
666 * @return string[] Array of required capabilities for the requested action.
667 */
668 public static function filter_map_meta_cap( $caps, $cap, $user_id, $args ) {
669 $meta_caps = self::get_meta_caps();
670 $entry_caps = self::get_meta_caps( 'entry' );
671
672 // Check if meta cap is valid to proceed.
673 if ( in_array( $cap, array_keys( $meta_caps ), true ) ) {
674 $id = isset( $args[0] ) ? (int) $args[0] : 0;
675
676 // Check if meta cap requires form ID from entry.
677 if ( in_array( $cap, array_keys( $entry_caps ), true ) ) {
678 $entry = evf_get_entry( $id, false, array( 'cap' => false ) );
679 if ( ! $entry ) {
680 return $caps;
681 }
682
683 $id = isset( $entry->form_id ) ? (int) $entry->form_id : 0;
684 }
685
686 $form = evf()->form->get( $id, array( 'cap' => false ) );
687 if ( ! $form ) {
688 return $caps;
689 }
690
691 if ( ! is_a( $form, 'WP_Post' ) ) {
692 return $caps;
693 }
694
695 if ( 'everest_form' !== $form->post_type ) {
696 return $caps;
697 }
698
699 // If the post author is set and the user is the author...
700 if ( $form->post_author && $user_id === (int) $form->post_author ) {
701 $caps = isset( $meta_caps[ $cap ]['own'] ) ? array( $meta_caps[ $cap ]['own'] ) : array( 'do_not_allow' );
702 } else {
703 // The user is trying someone else's form.
704 $caps = isset( $meta_caps[ $cap ]['others'] ) ? array( $meta_caps[ $cap ]['others'] ) : array( 'do_not_allow' );
705 }
706 }
707
708 return $caps;
709 }
710
711 /**
712 * Display action links in the Plugins list table.
713 *
714 * @param array $actions Plugin Action links.
715 * @return array
716 */
717 public static function plugin_action_links( $actions ) {
718 $new_actions = array(
719 '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>',
720 );
721
722 return array_merge( $new_actions, $actions );
723 }
724
725 /**
726 * Display row meta in the Plugins list table.
727 *
728 * @param array $plugin_meta Plugin Row Meta.
729 * @param string $plugin_file Plugin Row Meta.
730 * @return array
731 */
732 public static function plugin_row_meta( $plugin_meta, $plugin_file ) {
733 if ( EVF_PLUGIN_BASENAME === $plugin_file ) {
734 $new_plugin_meta = array(
735 '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>',
736 '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>',
737 );
738
739 return array_merge( $plugin_meta, $new_plugin_meta );
740 }
741
742 return (array) $plugin_meta;
743 }
744 }
745
746 EVF_Install::init();
747