文章描述:
WordPress如何创建自定义插件
插件位置:wp-content/plugins
创建插件
文件夹名和文件名一样
welcome/welcome.php
插件信息头
/*
Plugin Name: Your Plugin Name
Plugin URI: Your Plugin Url
Description: Your Plugin Description
Version: 1.0
Author: Author Name
Author URI: Author Url
*/
启动插件
//定义插件启动时候调用的方法
register_activation_hook(__FILE__,\'myplugin_activate\');
function myplugin_activate(){
echo \'<script>alert(\"你启动了自定义插件\");</script>\';
}
add_action( \"wp_head\", \"myplugin_activate\" );
停用插件
//定义插件停用时调用的方法
register_deactivation_hook(__FILE__,\'myplugin_deactivate\');
function myplugin_deactivate(){
}
删除插件
在welcome文件夹里面新建uninstall.php
//如果 uninstall 不是从 WordPress 调用,则退出
if(!defined(\'WP_UNINSTALL_PLUGIN\'))
exit();
© 版权声明
THE END
请登录后查看评论内容