我可以在本地主机上安装插件,但不能在服务器上安装

时间:2014-09-29 作者:Marcos

嗯,我在WordPress中完成了我的第一个插件,但我有一个小问题。

我的插件有下一个代码

add_action(\'my-plugin/my-plugin.php\',\'rating_install\');
add_action(\'admin_menu\',\'rating_add_option\');

function rating_install(){        
    global $wpdb;
    $table_name = $wpdb->prefix."rating";
    $create = "CRETA TABLE ".$table_name." ( "
            . "id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
            . "url TINYTEXT NOT NULL, "
            . "descripcion TINYTEXT NOT NULL ) ";    
    $wpdb->query($create);
}

function rating_uninstall(){
    global $wpdb;
    $table_name = $wpdb->prefix."rating";
    $drop = "DROP TABLE IF EXISTS ".$table_name;
    $wpdb->query($drop);
}

add_action(\'activa_rating/my-plugin.php\',\'rating_install\');
add_action(\'desactiva_rating/my-plugin.php\',\'rating_uninstall\');
当我激活插件时,它在localhost中工作,但当我将插件上传到服务器时,这段代码不工作,就像它不存在一样。不要在数据库中创建我的表。

我在数据库中看到权限,我拥有所有权限。

1 个回复
SO网友:Zammuuz

Use this code

register_activation_hook(__FILE__, \'rating_install\');
register_deactivation_hook(__FILE__, \'rating_uninstall\');

function rating_install(){        
    global $wpdb;
    $table_name = $wpdb->prefix."rating";
    $create = "CRETA TABLE ".$table_name." ( "
            . "id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
            . "url TINYTEXT NOT NULL, "
            . "descripcion TINYTEXT NOT NULL ) ";    
    $wpdb->query($create);
}

function rating_uninstall(){
    global $wpdb;
    $table_name = $wpdb->prefix."rating";
    $drop = "DROP TABLE IF EXISTS ".$table_name;
    $wpdb->query($drop);
}
结束

相关推荐

为什么激活插件在REGISTER_ACTIVATION_HOOK中不起作用

我试图在激活第一个插件的同时自动激活第二个插件。register_activation_hook(__FILE__, \'example_activation\' ); function example_activation() { include_once(ABSPATH .\'/wp-admin/includes/plugin.php\'); activate_plugin(\'hello.php\'); } 它在registe