| @@ -1,128 +1,127 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * The installer class | |
| 5 | - * | |
| 6 | - * @since 1.1.0 | |
| 7 | - */ | |
| 8 | -class WeForms_Installer { | |
| 9 | - | |
| 10 | - /** | |
| 11 | - * The installer class | |
| 12 | - * | |
| 13 | - * @return void | |
| 14 | - */ | |
| 15 | - public function install() { | |
| 16 | - $this->create_tables(); | |
| 17 | - $this->maybe_set_default_settings(); | |
| 18 | - $this->create_default_form(); | |
| 19 | - | |
| 20 | - $installed = get_option( 'weforms_installed' ); | |
| 21 | - | |
| 22 | - if ( !$installed ) { | |
| 23 | - update_option( 'weforms_installed', time() ); | |
| 24 | - } | |
| 25 | - | |
| 26 | - set_transient( 'weforms_activation_redirect', true, 30 ); | |
| 27 | - set_transient( 'weforms_prevent_tracker_notice', true, DAY_IN_SECONDS * 7 ); // don't wanna show tracking notice in first 7 days | |
| 28 | - update_option( 'weforms_version', WEFORMS_VERSION ); | |
| 29 | - } | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Create the table schema | |
| 33 | - * | |
| 34 | - * @return void | |
| 35 | - */ | |
| 36 | - public function create_tables() { | |
| 37 | - global $wpdb; | |
| 38 | - | |
| 39 | - $collate = ''; | |
| 40 | - | |
| 41 | - if ( $wpdb->has_cap( 'collation' ) ) { | |
| 42 | - if ( !empty( $wpdb->charset ) ) { | |
| 43 | - $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; | |
| 44 | - } | |
| 45 | - | |
| 46 | - if ( !empty( $wpdb->collate ) ) { | |
| 47 | - $collate .= " COLLATE $wpdb->collate"; | |
| 48 | - } | |
| 49 | - } | |
| 50 | - | |
| 51 | - $table_schema = [ | |
| 52 | - "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entries` ( | |
| 53 | - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 54 | - `form_id` bigint(20) unsigned DEFAULT NULL, | |
| 55 | - `user_id` bigint(20) unsigned DEFAULT NULL, | |
| 56 | - `user_ip` int(11) unsigned DEFAULT NULL, | |
| 57 | - `user_device` varchar(50) DEFAULT NULL, | |
| 58 | - `referer` varchar(255) DEFAULT NULL, | |
| 59 | - `status` varchar(10) DEFAULT 'publish', | |
| 60 | - `created_at` datetime DEFAULT NULL, | |
| 61 | - PRIMARY KEY (`id`), | |
| 62 | - KEY `form_id` (`form_id`) | |
| 63 | - ) $collate;", | |
| 64 | - | |
| 65 | - "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entrymeta` ( | |
| 66 | - `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 67 | - `weforms_entry_id` bigint(20) unsigned DEFAULT NULL, | |
| 68 | - `meta_key` varchar(255) DEFAULT NULL, | |
| 69 | - `meta_value` longtext, | |
| 70 | - PRIMARY KEY (`meta_id`), | |
| 71 | - KEY `meta_key` (`meta_key`), | |
| 72 | - KEY `entry_id` (`weforms_entry_id`) | |
| 73 | - ) $collate;", | |
| 74 | - ]; | |
| 75 | - | |
| 76 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
| 77 | - | |
| 78 | - foreach ( $table_schema as $table ) { | |
| 79 | - dbDelta( $table ); | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Set the required default settings key if not present | |
| 85 | - * | |
| 86 | - * This is required for setting up the component settings data | |
| 87 | - * | |
| 88 | - * @return void | |
| 89 | - */ | |
| 90 | - public function maybe_set_default_settings() { | |
| 91 | - $requires_update = false; | |
| 92 | - $settings = get_option( 'weforms_settings', [] ); | |
| 93 | - $additional_keys = [ | |
| 94 | - 'email_gateway' => 'wordpress', | |
| 95 | - 'credit' => false, | |
| 96 | - 'email_footer' => true, | |
| 97 | - 'recaptcha' => [ 'key' => '', 'secret' => '', 'type' => 'v2' ], | |
| 98 | - ]; | |
| 99 | - | |
| 100 | - foreach ( $additional_keys as $key => $value ) { | |
| 101 | - if ( !isset( $settings[ $key ] ) ) { | |
| 102 | - $settings[ $key ] = $value; | |
| 103 | - | |
| 104 | - $requires_update = true; | |
| 105 | - } | |
| 106 | - } | |
| 107 | - | |
| 108 | - if ( $requires_update ) { | |
| 109 | - update_option( 'weforms_settings', $settings ); | |
| 110 | - } | |
| 111 | - } | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Create a default form | |
| 115 | - * | |
| 116 | - * @return void | |
| 117 | - */ | |
| 118 | - public function create_default_form() { | |
| 119 | - $version = get_option( 'weforms_version' ); | |
| 120 | - | |
| 121 | - // seems like it's already installed | |
| 122 | - if ( $version ) { | |
| 123 | - return; | |
| 124 | - } | |
| 125 | - | |
| 126 | - weforms()->templates->create( 'contact' ); | |
| 127 | - } | |
| 128 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * The installer class | |
| 5 | + * | |
| 6 | + * @since 1.1.0 | |
| 7 | + */ | |
| 8 | +class WeForms_Installer { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * The installer class | |
| 12 | + * | |
| 13 | + * @return void | |
| 14 | + */ | |
| 15 | + public function install() { | |
| 16 | + | |
| 17 | + $this->create_tables(); | |
| 18 | + $this->maybe_set_default_settings(); | |
| 19 | + $this->create_default_form(); | |
| 20 | + | |
| 21 | + $installed = get_option( 'weforms_installed' ); | |
| 22 | + | |
| 23 | + if ( ! $installed ) { | |
| 24 | + update_option( 'weforms_installed', time() ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + set_transient( 'weforms_activation_redirect', true, 30 ); | |
| 28 | + set_transient( 'weforms_prevent_tracker_notice', true, DAY_IN_SECONDS * 7 ); // don't wanna show tracking notice in first 7 days | |
| 29 | + update_option( 'weforms_version', WEFORMS_VERSION ); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Create the table schema | |
| 34 | + * | |
| 35 | + * @return void | |
| 36 | + */ | |
| 37 | + public function create_tables() { | |
| 38 | + global $wpdb; | |
| 39 | + | |
| 40 | + $collate = ''; | |
| 41 | + | |
| 42 | + if ( $wpdb->has_cap( 'collation' ) ) { | |
| 43 | + if ( ! empty($wpdb->charset ) ) { | |
| 44 | + $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; | |
| 45 | + } | |
| 46 | + | |
| 47 | + if ( ! empty($wpdb->collate ) ) { | |
| 48 | + $collate .= " COLLATE $wpdb->collate"; | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + $table_schema = array( | |
| 53 | + "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entries` ( | |
| 54 | + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 55 | + `form_id` bigint(20) unsigned DEFAULT NULL, | |
| 56 | + `user_id` bigint(20) unsigned DEFAULT NULL, | |
| 57 | + `user_ip` int(11) unsigned DEFAULT NULL, | |
| 58 | + `user_device` varchar(50) DEFAULT NULL, | |
| 59 | + `referer` varchar(255) DEFAULT NULL, | |
| 60 | + `status` varchar(10) DEFAULT 'publish', | |
| 61 | + `created_at` datetime DEFAULT NULL, | |
| 62 | + PRIMARY KEY (`id`), | |
| 63 | + KEY `form_id` (`form_id`) | |
| 64 | + ) $collate;", | |
| 65 | + | |
| 66 | + "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entrymeta` ( | |
| 67 | + `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 68 | + `weforms_entry_id` bigint(20) unsigned DEFAULT NULL, | |
| 69 | + `meta_key` varchar(255) DEFAULT NULL, | |
| 70 | + `meta_value` longtext, | |
| 71 | + PRIMARY KEY (`meta_id`), | |
| 72 | + KEY `meta_key` (`meta_key`), | |
| 73 | + KEY `entry_id` (`weforms_entry_id`) | |
| 74 | + ) $collate;", | |
| 75 | + ); | |
| 76 | + | |
| 77 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
| 78 | + foreach ( $table_schema as $table ) { | |
| 79 | + dbDelta( $table ); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Set the required default settings key if not present | |
| 85 | + * | |
| 86 | + * This is required for setting up the component settings data | |
| 87 | + * | |
| 88 | + * @return void | |
| 89 | + */ | |
| 90 | + public function maybe_set_default_settings() { | |
| 91 | + $requires_update = false; | |
| 92 | + $settings = get_option( 'weforms_settings', array() ); | |
| 93 | + $additional_keys = array( | |
| 94 | + 'email_gateway' => 'wordpress', | |
| 95 | + 'credit' => false, | |
| 96 | + 'recaptcha' => array( 'key' => '', 'secret' => '' ) | |
| 97 | + ); | |
| 98 | + | |
| 99 | + foreach ($additional_keys as $key => $value) { | |
| 100 | + if ( ! isset( $settings[ $key ] ) ) { | |
| 101 | + $settings[ $key ] = $value; | |
| 102 | + | |
| 103 | + $requires_update = true; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + if ( $requires_update ) { | |
| 108 | + update_option( 'weforms_settings', $settings ); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Create a default form | |
| 114 | + * | |
| 115 | + * @return void | |
| 116 | + */ | |
| 117 | + public function create_default_form() { | |
| 118 | + $version = get_option( 'weforms_version' ); | |
| 119 | + | |
| 120 | + // seems like it's already installed | |
| 121 | + if ( $version ) { | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + | |
| 125 | + weforms()->templates->create( 'contact' ); | |
| 126 | + } | |
| 127 | +} | |