我正在更新我的插件,以便与Wordpress 3.5版兼容。以下是我的重要插件文件:
按标题对\\u SearchResult\\u排序。php:
<?php
if(!class_exists(\'Class_Sortsearchresults\'))
{
require_once(\'Class_Sortsearchresults.php\');
}
if(!isset($Class_Sortsearchresults))
{
$Class_Sortsearchresults = new Class_Sortsearchresults;
}
?>
Class\\u排序搜索结果。php:
<?php
class Class_Sortsearchresults
{
function __construct()
{
//Register activation hook
register_activation_hook(__FILE__,array(&$this,\'sortresult_install\'));
//Add menu hook
add_action( \'admin_menu\', array(&$this,\'sort_searchresults_menu\'));
//Update function hook
add_action(\'plugins_loaded\', array(&$this,\'sortsearchtitle_update_db_check\'));
//Register deactivation hook
register_deactivation_hook(__FILE__, array(&$this,\'sortresult_uninstall\'));
//Run the search function
add_action(\'pre_get_posts\',array(&$this,\'sort_searchresult_by_title\'));
}
function sortresult_uninstall()
{
//This function is not working or executed
global $wpdb;
$sortsearchtitle_db_version = \'1.0\';
$table = $wpdb->prefix."sortsearchresult";
$wpdb->query("DROP TABLE IF EXISTS $table");
delete_option(\'sortsearchtitle_db_version\');
}
function sortresult_install()
{
//install function
}
function sort_searchresults_menu()
{
//function for creating menu
}
function sortsearchtitle_update_db_check()
{
//function for update
}
function settings_page()
{
//function for settings form
}
function sortingguide($opt_val)
{
//sorting options
}
function sort_searchresult_by_title($k)
{
//function to run customized search
}
}
?>
看来除了卸载功能外,我一切都很好。有什么线索说明这不起作用吗?谢谢
最合适的回答,由SO网友:RRikesh 整理而成
register_deactivation_hook() 当插件停用时启动。对于插件卸载,有register_uninstall_hook().
Wordpress插件也可以有一个名为uninstall.php
每当卸载插件时都会运行。为了防止uninstall.php
文件直接触发,常量的状态称为WP_UNINSTALL_PLUGIN
应在启动卸载代码之前进行检查。
你的uninstall.php
可能是:
<?php
//if uninstall not called from WordPress exit
if ( !defined( \'WP_UNINSTALL_PLUGIN\' ) )
exit ();
global $wpdb;
$sortsearchtitle_db_version = \'1.0\';
$table = $wpdb->prefix."sortsearchresult";
$wpdb->query("DROP TABLE IF EXISTS $table");
delete_option(\'sortsearchtitle_db_version\');