WordPress如何写一个插件

今天俺跟你们一块儿从零开始写一个wordpress插件,功能很简单就是在后台页面上显示"Let's fuck the world"。php

文件头
全部的wordpress插件都须要写注释来讲明:插件名称、插件版本、做者等信息。html

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

俺写的文件头如上,全部的插件都须要至少包含一个Plugin Name文件头。wordpress

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,代码以下:spa

add_action('admin_notices','fuck_the_world');

所有的代码以下,咱们只须要把这个文件放在wp-content/plugins/下便可,wordpress会自动识别该文件.net

<?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');

?>

效果
效果以下:插件

clipboard.png

欢迎你们一块儿学习讨论,欢迎访问个人博客。code

原文连接:https://www.pipipi.net/code/1...htm

相关文章
相关标签/搜索