Created
May 28, 2020 08:12
-
-
Save alokstha1/029982234c740135f062b81c6f1df7ff to your computer and use it in GitHub Desktop.
Create database on plugin activation hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
register_activation_hook( __FILE__, 'plugin_create_db' ); | |
function plugin_create_db() { | |
// Create DB Here | |
global $wpdb; | |
$charset_collate = $wpdb->get_charset_collate(); | |
$table_name = $wpdb->prefix . 'test_table'; | |
$sql = "CREATE TABLE $table_name ( | |
id mediumint(9) NOT NULL AUTO_INCREMENT, | |
another_ID varchar(255) default NULL, | |
first_name varchar(255) default NULL, | |
import_time datetime NOT NULL default '0000-00-00 00:00:00', | |
import_timestamp longtext, | |
PRIMARY KEY (id), | |
UNIQUE KEY(another_ID) | |
) $charset_collate;"; | |
// is_inserted_wp_users is to check for if is users is inserted with wp_insert_user | |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
dbDelta( $sql ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment