WORDPRESS 博客强大的地方 就在于可以用插件 扩展功能. WORDPRESS有一个专门管理插件的页面 可以很清楚很简单的对每个插件进行 升级, 配置, 开启和关闭等操作.
插件目录
所有插件都存于/wp-content/plugins 目录下. 每个插件都有自己的目录. 目录下必须要有同名的 PHP 文件 作为插件的入口. 比如你创建了文件夹 sample 在里面就必须有 sample.php 作为插件的入口.
插件的描述信息
插件的描述信息需要在 PHP 文件的最顶段 以注释的方式指定, 比如:
1 2 3 4 5 6 7 8 9 10 | <php /* Plugin Name: 插件名称 Description: 插件描述 Version: 0.1 Author: justyy Author URI: https://justyy.com License: Free Text Domain: sample-plugin */ |
<php /* Plugin Name: 插件名称 Description: 插件描述 Version: 0.1 Author: justyy Author URI: https://justyy.com License: Free Text Domain: sample-plugin */
例子 – 第一个插件
之前在 这里 提到用 HTTP_REFERER 来简单有效的过滤垃圾评论的方法. 我们可以简单的把它弄成一个插件 而不是直接修改 functions.php 模板文件.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < ?php /* Plugin Name: Check Comment Flood Description: This Simple Plugin prevents most of the spam comments by checking the HTTP_REFERER variable. No complex configurations just simply activating the plugin will do the job. Version: 0.1 Author: justyy Author URI: https://justyy.com Plugin URI: License: Free Text Domain: check-comment-flood */ function check_referrer() { if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') { wp_die(__('Please do not access this file directly.')); } } add_action('check_comment_flood', 'check_referrer'); |
< ?php /* Plugin Name: Check Comment Flood Description: This Simple Plugin prevents most of the spam comments by checking the HTTP_REFERER variable. No complex configurations just simply activating the plugin will do the job. Version: 0.1 Author: justyy Author URI: https://justyy.com Plugin URI: License: Free Text Domain: check-comment-flood */ function check_referrer() { if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == '') { wp_die(__('Please do not access this file directly.')); } } add_action('check_comment_flood', 'check_referrer');
保存插件文件 然后在WORDPRESS里就能看到了.
这种方式有啥好处?
可以随时对插件 开启或关闭. 把插件功能提取出来可以方便日后对其维护(升级). 升级主题文件或者WORDPRESS版本不会影响插件的功能. 另一个好处就是 如果直接修改 functions.php 改坏了 整个WORDPRESS就不能运行了. 但是如果改坏了 插件, WORDPRESS会把插件禁用了 不会影响到其它的功能的使用, 是个比较安全的做法.
github: https://github.com/DoctorLai/check-comment-flood
英文: WordPress Plugin Tutorial – How to Write First Plugin?
Wordpress博客技术文章
- 为博客Wordpress添加两个显示十大文章的短指令 shortcode
- 添加短代码(Short Code Function)以在 WordPress 帖子或页面中包含任何 PHP 或 HTML 文件
- 给Wordpress提了个BUG得到了一件免费的T-Shirt
- 最简单有效的过滤Wordpress垃圾评论的方法
- 怎么样对你的Wordpress博客进行汉化?
- 怎么样移动Wordpress博客的评论?
- Wordpress 博客使用 AMP 移动加速的技术和技巧
- 怎么样正确的统计WORDPRESS博文的汉字个数?
- 本人提供有偿 WORDPRESS或相关网站 速度SEO优化等服务
- 如何把 隐藏 WORDPRESS 的顶部管理菜单?
- 通过PHP脚本 批量设置 WORDPRESS 博客文件夹属性
- 在WORDPRESS管理员界面上面添加菜单选项
- 开发 Wordpress 插件 教程 - 插件是如何工作的?
- Wordpress 最简单的过滤垃圾评论的方法
- 如何显示缩略图 随机文章 Wordpress?
- 如何在文章最后显示 历史上的今天 [Wordpress]?
- 登陆 Wordpress 之后不显示Adsense广告
- 如何在指定的文章里不显示Adsense广告? Adsense真是矫情
GD Star Rating
loading...
本文一共 376 个汉字, 你数一下对不对.loading...
上一篇: 推荐英国 Holland & Barrett 减肥茶 - Bootea
下一篇: 在WORDPRESS管理员界面上面添加菜单选项
扫描二维码,分享本文到微信朋友圈
