WordPress如何写一个插件

今天俺跟大家一起从零开始写一个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');

?>

效果

效果如下:

Wordpress如何写一个插件

(1)
上一篇 2019年8月1日 下午11:31
下一篇 2019年8月12日 下午5:21

相关推荐

发表回复

登录后才能评论