Npcink Blog
切换菜单

从零开始,开发 WORDPRESS 插件

开发教程

官方详细信息:查看

参考:WordPress 大学-插件开发教程

我要开发的是一款能在文本编辑器中添加按钮的插件,取名为:Magic Button

我谷歌了一下并在 WordPress 后台查找次名字,没有重名。

我在桌面新建文件夹,取名 Magic Button,

目录结构:

  • /Magic Button — 唯一的插件名称,不要包含空格或者特殊字符
  • Magic Button.php — 唯一的插件名称,插件主文件
  • uninstall.php — 插件的卸载文件
  • /js — JavaScript 文件
  • /css — css 样式表
  • /images — 图片
  • /includes — 存放要包含的 PHP 文件
在 Magic Button.php 里面写入:标准插件信息
<?php
/*
Plugin Name: 插件名称
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: 插件的简单描述
Version: 插件版本号, 例如: 1.0
Author: 插件作者
Author URI: http://URI_Of_The_Plugin_Author作者地址
*/
?>

标准信息头至少要包括插件名称,这样 WordPress 才能识别你的插件。其他信息将显示在控制面板插件管理页面中。标准插件信息对各行顺序没有要求。

版权信息 :写入 GPL 版权信息

<?php
/* Copyright 年份 作者名 (email : 你的邮箱)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
?>

GPL 许可具有“传染性”,我非常喜欢。

此时,插件已经可以使用了,将 Magic Button.php 文件放入 wp-content/plugin 目录,即可使用。

WordPress 代码编辑标准:查看