$create = "CRETA TABLE ".$table_name." ( "
可能应阅读:
$create = "CREATE TABLE ".$table_name." ( "
您确实应该使用dbDelta()函数,因为WordPress将有助于将来的表升级/编辑。否则,您将不得不手动处理数据库升级。不好玩。
您的最终代码将如下所示:
register_activation_hook(__FILE__, \'rating_install\');
function rating_install(){
//Funcion que genera la instalacion del plugin
global $wpdb;
require_once( ABSPATH . \'wp-admin/includes/upgrade.php\' );
$table_name = $wpdb->prefix .\'rating\';
$create =
"CREATE TABLE ".$table_name." (
`id` INT NOT NULL AUTO_INCREMENT,
`url` TINYTEXT NOT NULL,
`descripcion` TINYTEXT NOT NULL,
PRIMARY KEY (`id`));";
dbDelta($create);
}
此外,当你卸载插件时,你真的应该把所有这些都放到卸载中。php文件保存在插件目录中。这是卸载插件的正确方法:
http://codex.wordpress.org/Function_Reference/register_uninstall_hook<?php
// uninstall.php
//if uninstall not called from WordPress exit
if ( !defined( \'WP_UNINSTALL_PLUGIN\' ) )
exit();
$option_name = \'any added option name\';
delete_option( $option_name );
// For site options in multisite
delete_site_option( $option_name );
//drop a custom db table
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS {$wpbd->prefix}rating" );