Last active
October 5, 2015 09:13
-
-
Save jandrodev/02373136fecffdf58082 to your computer and use it in GitHub Desktop.
Crear tabla con insert al activar Wordpress plugin
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
function create_plugin_table() { | |
global $wpdb; | |
$table_name = $wpdb->prefix .'info'; | |
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { | |
$query_create = 'CREATE TABLE ' . $table_name . ' ( | |
id mediumint(9) NOT NULL AUTO_INCREMENT, | |
info VARCHAR(255) NOT NULL, | |
PRIMARY KEY (id) | |
);'; | |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
dbDelta($query_create); | |
$query_insert = 'INSERT INTO '.$table_name.'(info) VALUES("Luke... yo soy tu padre");'; | |
dbDelta($query_insert); | |
} | |
} | |
register_activation_hook(__FILE__,'create_plugin_table'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment