PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.12.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.12.0
2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 All 78 releases
ablocks / includes / database / create-form-table.php

create-form-table.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.12.0, at includes/database/create-form-table.php

65 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Database;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 class CreateFormTable {
9 public static function up( $prefix, $charset_collate ) {
10 global $wpdb;
11 $table_entries = $prefix . ABLOCKS_PLUGIN_SLUG . '_form_entries';
12 $table_meta = $prefix . ABLOCKS_PLUGIN_SLUG . '_form_meta';
13
14 $sql_entries = "CREATE TABLE $table_entries (
15 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
16 form_type VARCHAR(50) NOT NULL,
17
18 post_id VARCHAR(100) NULL, -- for post id
19 ip VARCHAR(100) NULL, -- for user ip
20 is_in_trash VARCHAR(20) DEFAULT 'no',
21 user_agent VARCHAR(250) NULL, -- for user browser agent
22
23 block_id VARCHAR(100) NOT NULL,
24 user_email VARCHAR(100) NOT NULL,
25 status VARCHAR(50) DEFAULT 'unread',
26 is_email_verified VARCHAR(20) DEFAULT 'no',
27 expire INT(20) NULL,
28 email_verification_token VARCHAR(100) NOT NULL,
29 created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
30 updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
31 PRIMARY KEY (id)
32 ) $charset_collate;";
33
34 // SQL to create the custom_form_meta table
35 $sql_meta = "CREATE TABLE $table_meta (
36 meta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
37 entry_id BIGINT(20) UNSIGNED NOT NULL,
38 meta_key VARCHAR(255) NOT NULL,
39 meta_value TEXT NOT NULL,
40 PRIMARY KEY (meta_id),
41 FOREIGN KEY (entry_id) REFERENCES $table_entries(id) ON DELETE CASCADE ON UPDATE CASCADE
42 ) $charset_collate;";
43
44 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
45 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_entries}'" ) !== $table_entries ) {
46 dbDelta( $sql_entries );
47 }
48 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
49 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_meta}'" ) !== $table_meta ) {
50 dbDelta( $sql_meta );
51 }
52
53 }
54 public static function down( $prefix ) {
55 global $wpdb;
56
57 $table_entries = $prefix . ABLOCKS_PLUGIN_SLUG . '_form_entries';
58 $table_meta = $prefix . ABLOCKS_PLUGIN_SLUG . '_form_meta';
59
60 $sql = "DROP TABLE IF EXISTS $table_meta, $table_entries;";
61 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
62 $wpdb->query( $sql );
63 }
64 }
65