WordPress不会丢失关于插件停用的表

时间:2017-06-12 22:33:56

标签: wordpress

因此,当我的自定义插件被停用且无法正常工作时,我使此功能删除了一个表。怎么了?它使它成为函数,表名是正确的。

function my_plugin_remove_database() {
    global $wpdb;

    $table_name = $wpdb->prefix . 'makes';
    $sql = "DROP TABLE IF EXISTS $table_name";
    $wpdb->query($sql);
}
register_deactivation_hook( __FILE__, 'my_plugin_remove_database' );

1 个答案:

答案 0 :(得分:0)

function pluginUninstall() {

        global $wpdb;
        $table = $wpdb->prefix."park";

        //Delete any options thats stored also?
    //delete_option('wp_yourplugin_version');

    $wpdb->query("DROP TABLE IF EXISTS $table");
}//end pluginUninstall function

//hook into WordPress when its being deactivated:
register_deactivation_hook( __FILE__, 'pluginUninstall' );`enter code here`