我一直在开发我的第一个插件(调用myplugin)。插件代码的路径是wp-content/plugins/myplugin/myplugin。php。myplugin。php文件基本上如下所示:
<?php
defined( \'ABSPATH\' ) OR exit;
/*
* Plugin Name: My Plugin
*/
function my_plugin_activation() {
global $wpdb;
// SQL code to insert custom database tables
// using CREATE TABLE IF NOT EXISTS tablename....
}
function my_plugin_deactivation() {
// SQL code to update table on deactivation
}
function my_plugin_uninstall() {
global $wpdb;
// SQL code to remove custom database tables
}
register_activation_hook( __FILE__, \'my_plugin_activation\');
register_deactivaction_hook( __FILE__, \'my_plugin_deactivation\');
register_uninstall_hook( __FILE__, \'my_plugin_uninstall\');
?>
当我激活上述插件代码时,my\\u plugin\\u激活例程会成功创建表,插件会被激活(如果完成激活,我会得到一个停用链接),但插件屏幕顶部会显示以下消息:
Plugin could not be activated because it triggered a fatal error.
Fatal error: Cannot redeclare my_plugin_activaction() (previously declared in C:\\xampp\\htdocs\\deve1wp\\wp-content\\plugins\\myplugin\\myplugin.php: 15) in C:\\xampp\\htdocs\\deve1wp\\wp-content\\plugins\\myplugin\\myplugin.php on line 198
第15行是实际的函数定义。第198行是我注册激活挂钩的行。
有什么好处?
提前谢谢。