WordPress如何写一个插件

9次阅读

共计 859 个字符,预计需要花费 3 分钟才能阅读完成。

今天俺跟大家一起从零开始写一个 wordpress 插件,功能很简单就是在后台页面上显示 ”Let’s fuck the world”。

文件头
所有的 wordpress 插件都需要写注释来说明:插件名称、插件版本、作者等信息。

/*
Plugin Name: fuck the world
Description: 显示 fuck the world!
Author: 创客青年博客
Version: 1.6
Author URI: https://www.pipipi.net/
*/

俺写的文件头如上,所有的插件都需要至少包含一个 Plugin Name 文件头。

action hook
接下来我们需要在特定的 wordpress“生命函数”中调用显示信息的函数就可以了。

显示“Let’s fuck the world!”函数如下:

function fuck_the_world(){echo "<div class='update-message'><p>Let's fuck the world!</p></div>";}

添加 action,代码如下:

add_action('admin_notices','fuck_the_world');

全部的代码如下,我们只需要把这个文件放在 wp-content/plugins/ 下即可,wordpress 会自动识别该文件

<?php
  /*
Plugin Name: fuck the world
Description: 显示 fuck the world!
Author: 创客青年博客
Version: 1.6
Author URI: https://www.pipipi.net/
*/
function fuck_the_world(){echo "<div class='update-message'><p>Let's fuck the world!</p></div>";}
add_action('admin_notices','fuck_the_world');

?>

效果
效果如下:

欢迎大家一起学习讨论,欢迎访问我的博客。

原文链接:https://www.pipipi.net/code/1…

正文完
 0