WPBones icon indicating copy to clipboard operation
WPBones copied to clipboard

Rollback migrations on plugin deactivation

Open malijani opened this issue 3 years ago • 2 comments

The down() method was not working in migrations.

PS: It's better to remove up() from Migration class constructor and use direct method call on activation.

malijani avatar Mar 26 '22 10:03 malijani

@malijani Hi, sorry for the delay

I think that the deactivation.php file should be used in a different way. Probably, the best way to add any "down" procedure, for example, any Database tasks in order to remove custom tables and data, would be the uninstall.php file, as mentioned in the WordPress docs.

Let me know wdyt

gfazioli avatar Jun 28 '22 06:06 gfazioli

@malijani In the current wp bones core framework, in the plugin class, you will see

        /*
         * There are many pitfalls to using the uninstall hook. It ’ s a much cleaner, and easier, process to use the
         * uninstall.php method for removing plugin settings and options when a plugin is deleted in WordPress.
         *
         * Using uninstall.php file. This is typically the preferred method because it keeps all your uninstall code in a
         * separate file. To use this method, create an uninstall.php file and place it in the root directory of your
         * plugin. If this file exists WordPress executes its contents when the plugin is deleted from the WordPress
         * Plugins screen page.
         *
         */

        // register_uninstall_hook( $file, array( $this, 'uninstall' ) );

as you can see it's commented atm

gfazioli avatar Jun 28 '22 06:06 gfazioli

Hi @gfazioli , first of all I have to appreciate your good work on wpbones! I made many useful plugins with it 🌷.

Yeah it's absolutely right and I shouldn't rollback migrations on deactivation anyway...

I'll close the pull request cause it's not a standard procedure as you mentioned above.

malijani avatar Sep 06 '22 05:09 malijani