wp plugin -7

Deactivate Is Not Uninstall

Two uninstall methods:

(1) Uninstall.php:

< ?php

// If uninstall not called from WordPress exit

if( !defined( ‘WP_UNINSTALL_PLUGIN’ ) )

exit ();

// Delete option from options table

delete_option( ‘boj_myplugin_options’ );

//remove any additional options and custom tables

? >

(2) uninstall hook。当没有uninstall.php文件时,WP会执行uninstall hook。

register_uninstall_hook( $file, $function );

$file - (string) (required) — Path to the primary plugin file

$function - (string) (required) — The function to be executed when the plugin is uninstalled

例如:

< ?php

register_activation_hook( __FILE__, ‘boj_myplugin_activate’ );

function boj_myplugin_activate() {

//register the uninstall function

register_uninstall_hook( __FILE__, ‘boj_myplugin_uninstaller’ );

}

function boj_myplugin_uninstaller() {

//delete any options, tables, etc the plugin created

delete_option( ‘boj_myplugin_options’ );

}

? >

posted on 2012-12-03 15:49  kalintw  阅读(122)  评论(0)    收藏  举报

导航