惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

编程设计 – 云破天开

学习写wordpress插件(三)-云破天开 学习写wordpress插件(二)-云破天开 整理电子书-云破天开 两列数据对比,找出不同数据-云破天开 一个简单实用的网站访客统计PHP源码-云破天开 在线图片处理-云破天开 DOS命令-云破天开 EMLOG头部添加名人名言-云破天开 Emlog实现标题+全文内容搜索方法-云破天开
学习写wordpress插件(一)-云破天开
作者:yptk · 2022-10-22 · via 编程设计 – 云破天开

最近一直想给网站添加一些功能。试用了很多插件都不太满意。无奈打算自己动手。

但是,得先学习。说干就干:

一、插件:插件可以是一个php文件,也可以是一个文件夹。存放在wp-content/plugins 目录。

二、WP识别插件的方法:

插件名字必须唯一
插件标准头信息

/*
Plugin Name:nidaye
Plugin URI: http://www.yptk.cn
Version:V0.1
Author: YPTK
Author URI:http://www.yptk.cn
Description:My first plugin named nidaye
*/

如果要上传到插件库,需要有一个标准的txt

三、Hook(钩子):WordPress提供的,允许你的插件“勾入”WordPress的程序。
插件的核心是两个 function,用来添加 Hooks(中文译为钩子)

add_action ($hookname, $callbackfunction)
add_filter ($hookname,$callbackfunction)

action,条件触发的切入点。
filter,对数据传输过程的一种过滤机制,例如当文章保存到数据库的过程,或者文章从数据库中取出,展现到浏览器中的这个过程。例如:获取文章摘要,就先把整个文章处理成摘要后,再输出。

四、制作一个简单的插件,只包含两部分,说明部分和一个function,功能是输出一段文字。数据库交互还没搞明白,明天再说。

<?php
/*
Plugin Name:nidaye
Plugin URI: http://www.yptk.cn
Version:V0.1
Author: YPTK
Author URI:http://www.yptk.cn
Description:My first plugin named nidaye
*/
?>
<?php
function ni_daye()
{
$content="你大爷,永远是你大爷。";
return $content;
}
add_shortcode('nidaye','ni_daye')
?>

代码上传到服务器,可以正常显示。

我们使用了wordpress的简码。在新文章中插入如下代码即可显示输出值。

[nidaye]

成功。

版权共享,随意转载:云破天开 » 学习写wordpress插件(一)