Skip to content

Instantly share code, notes, and snippets.

@jandrodev
Last active October 5, 2015 09:13
Show Gist options
  • Save jandrodev/02373136fecffdf58082 to your computer and use it in GitHub Desktop.
Save jandrodev/02373136fecffdf58082 to your computer and use it in GitHub Desktop.
Crear tabla con insert al activar Wordpress plugin
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