Plugin Uninstall
During the process of developing plug-ins, it is inevitable to create some fields and even tables in the database, or create some timed tasks. When the plug-in is deleted, these things will be left on WordPress and become garbage. As a responsible developer, it is necessary to help users delete the traces we left when deleting the plug-in.
uninstall.php file
There are two ways to do this. Create an uninstall.php file in the root directory of the plug-in. This file will be executed before your plug-in is deleted. But be careful to prevent someone from maliciously accessing this file. We need to determine whether the WP_UNINSTALL_PLUGIN constant is defined. If it is not defined, the program will be ended:
<?php//Prevent people from maliciously accessing this file, so if( !defined( 'WP_UNINSTALL_PLUGIN' ) ) exit(); //You can do something when you want to uninstall, such as deleting some fields and logging out the timing task delete_option( 'endskin_name' ); delete_option( 'endskin_name2' );
Uninstall hook
The second method is called the uninstall hook. WordPress will execute the uninstall hook when there is no uninstall.php file in your root directory.
example:
register_uninstall_hook( __FILE__, 'Bing_uninstall_func' );function Bing_uninstall_func(){ //You can do something when you want to uninstall, such as deleting some fields and logging out the timing task delete_option( 'endskin_name' ); delete_option( 'endskin_name2' ); }These codes can be placed directly in the plug-in file, but the uninstall hook cannot use class functions, otherwise $this will be saved to the database, so if it is not a last resort, please use the uninstall.php file as much as possible.
Remove some components of the custom article type
WordPress custom article types use many components. When we don't need them, we can remove them through the remove_post_type_support() function. Below is a list of components that can be removed:
For example, remove the included "Article" comment function:
/** *Remove the comment function of the article*http://www.endskin.com/remove-post-type-support/*/function Bing_remove_post_type_support(){ remove_post_type_support( 'post', 'comments' );}add_action( 'init', 'Bing_remove_post_type_support' );