1->add_action  HOOK简单说明: http://codex.wordpress.org/Plugin_API/Action_Reference (参考网址)

//在后台页脚位置加载(执行)函数 add_str 为自定义的函数名
add_action('admin_footer','add_str'); //在后台头部位置加载(执行)函数
add_action('admin_head','add_str'); //在wp加载之前加载(执行)函数
add_action('wp_loaded','add_str'); //当每加载一篇文章的时候加载(执行)函数
add_action('the_post','add_str'); //当更新文章的时候加载(执行)函数
add_action('save_post','add_str'); function add_str() {
echo '<h1>Welcome to the plugin (xaiolong production)</h1>';
}

2->add_filter()  HOOK简单说明  http://codex.wordpress.org/Plugin_API/Filter_Reference  (参考网址)

//给每个文章标题,后面加上id编号,和一个自定义的字符串
add_filter('the_title','write_title',10,2);
function write_title($title,$id){
return $title.'---'.$id.'---create by xiaolong';
} //给每个文章内容后面加上一个自定义的字符串
add_filter('the_content','write_content',10,1);
function write_content($content) {
return $content.'---create by xiaolong';

3->插件演示代码:下载地址:http://pan.baidu.com/s/1mg3JpVy

在 wordpress/wp-content/plugins/ 目录下 新建一个文件夹取名为first_plugins_demo(或自己定义),在新建的first_plugins_demo目录下新建first_plugins_demo.php(自定义.php但要求与父级目录名一直)文件,将以下代码拷贝到first_plugins_demo.php文件中保存,刷新wordpress后台-插件菜单-已安装的插件,启用First plugins Demo 插件即可

目录示例:*/wordpress/wp-content/plugins/first_plugins_demo/first_plugins_demo.php

<?php
/*
Plugin Name: First Plugins Demo
Plugin URI: http://www.cnblogs.com/fxmbz/p/4030286.html
Description: First Plugins Demo, admin head add a line information, add the Settings menu button In the Settings menu
Version: 1.0
Author: xiaolong
Author URI: http://www.cnblogs.com/fxmbz/
License: GPL
Text Domain: 29583035
*/ /**
* [register_activation_hook run set_color_options]
*/
register_activation_hook( __FILE__, 'set_color_options' ); /**
* [register_deactivation_hook run del_color_options]
*/
register_deactivation_hook( __FILE__, 'del_color_options' ); /**
* [set_color_options options表插入数据]
*/
function set_color_options() {
// options表插入数据 参数:('$option_name','$option_value')
add_option( 'color','red' );
} /**
* [del_color_options 删除options表数据]
*/
function del_color_options() {
// 删除options表数据 参数:('$option_name')
delete_option( 'color' );
} /**
* [add_action 在wp后台头部位置加载(执行)函数 add_acton('$hook', '$function')]
* [add_str 输出字符串, get_option('color') 获得options表中option_name为color的option_value的值]
*/
add_action( 'admin_head', 'add_str' );
function add_str() {
echo '<h2 style="color:' . get_option( 'color' ) . '">Welcome to first plugins demo! author: Zhangxl, Email: 29583035@qq.com</h2>';
} /**
* [add_action 在后台菜单位置添加一个页面 add_acton('$hook', '$function')]
* [create_admin_page 配置增加页面的title, 菜单栏的title, 权限, slug, $function]
*/
add_action( 'admin_menu', 'create_admin_page' );
function create_admin_page() {
// add_options_page() http://codex.wordpress.org/Function_Reference/add_options_page(参考网址)
// add_options_page( $page_title, $menu_title, $capability(权限), $menu_slug(URL-friendly name), $function );
add_options_page( 'First Plugins Demo Setting','First Plugins Settings','manage_options','firstplugindemo','wp_options_page' );
} /**
* [wp_options_page 输出页面模板]
* @return [type] [description]
*/
function wp_options_page() {
?>
<div class="wrap">
<h2>First Plugins Settings</h2>
<!-- 更新options表的数据 -->
<?php update_color_option(); ?>
<form action="" method="post">
Color: <input type="text" name="color" value="<?php echo get_option( 'color' );?>" />
<input type="submit" name="submit" value="submit" />
</form>
</div>
<?php
} /**
* [update_color_option 更新options表的数据]
* @return [type] [string]
*/
function update_color_option() {
$color = $_POST[ 'color' ];
$rule = "/[a-z]|#([0-9a-zA-Z])/";
// 正则匹配客户输入的颜色代码,为纯字母,或者是#开头的16进制代码
$result = preg_match($rule, $color); if ( $_POST[ 'submit' ] ) {
if ( $result ) {
update_option( 'color', $color );
echo "<p style='color: green; font-size: 18px;'>Update Success Full !</p>";
} else {
echo "<p style='color: red; font-size: 18px;'>Some Thing Wrong ! Please check the Color Name spelling, or a Color input format for 'red' or #aabbcc (Hexadecimal color ode).</p>";
}
} }

http://codex.wordpress.org/Template_Tags  (参考网址)

https://codex.wordpress.org/Function_Reference (参考网址)

http://codex.wordpress.org/Plugin_API/Filter_Reference (参考网址)

http://codex.wordpress.org/Plugin_API/Action_Reference (参考网址)

WordPress插件制作笔记(一)---First Plugins Demo的更多相关文章

  1. WordPress插件制作笔记(二)---Second Plugins Demo

    1->插件演示代码:下载地址:http://pan.baidu.com/s/1gd1lFlL 在 wordpress/wp-content/plugins/ 目录下 新建一个文件夹取名为seco ...

  2. WordPress插件制作笔记(三)---Stars Comments Article

    wp 文章星级评价 插件 下载地址4:http://pan.baidu.com/s/1eQnGIGU [articles_star_vote_score_optiontable_serialize_c ...

  3. WordPress插件制作教程(一): 如何创建一个插件

    上一篇还是按照之前的教程流程,写了一篇WordPress插件制作教程概述,从这一篇开始就为大家具体讲解WordPress插件制作的内容.这一篇主要说一下插件的创建方法. 相信大家都知道插件的安装文件在 ...

  4. WordPress插件制作教程(八): 最后总结

    WordPress插件教程最后一篇,还是为大家简单的做下总结.这次插件制作教程讲的内容和知识点个人觉得不是很多,因为插件制作不单单是这些内容,它涉及的知识很多很多,不是说你会一些函数就可以做出一个好的 ...

  5. WordPress插件制作教程概述

    接下来的一段时间里,开始为大家讲解WordPress插件制作系列教程,这篇主要是对WordPress插件的一些介绍和说明,还有一些我们需要注意的地方,以及需要掌握的知识. WordPress插件允许你 ...

  6. WordPress插件制作教程(二): 编写一个简单的插件

    上一篇说到了如何创建一个插件,我想大家看了之后一定会有所收获,这一篇简单给大家写一个插件样例,让大家有一个基本的印象.这个插件的样例就是当你激活这个插件后会在你的每篇文章中插入一段自己定义好的内容,比 ...

  7. WordPress插件制作教程(六): 插件函数之动作(Actions)函数

    这一篇为大家说一下WordPress插件函数吧,要制作插件,了解这些函数是非常有必要的 WordPress插件函数分为“动作”(Actions)和过滤器”(Filters),WordPress 使用这 ...

  8. WordPress插件制作教程(七): 插件函数之过滤器(Filter)函数

    上一篇对插件函数之动作(Action)函数做了下介绍,这篇在介绍下过滤器(Filters). 过滤器是一类函数,WordPress执行传递和处理数据的过程中,在针对这些数据做出某些动作之前的特定运行( ...

  9. WordPress插件制作教程(三): 添加菜单的方法

    上一篇编写了一个简单的插件,让大家对插件的简单制作有个了解,这一篇我们在更深一步,当我们激活插件后后台会显示菜单出来,然后通过单击菜单显示自己定义好的信息.激活之后会在WordPress后台显示一个菜 ...

随机推荐

  1. Struts2 文件的上传与下载

    1. Struts2的文件上传需要Apache的commons-io-Version.jar和commons-fileupload-Version.jar两个jar包.2. 页面中的<s:fil ...

  2. Spring Boot + Elasticsearch

    spring data elasticsearch elasticsearch 2.0.0.RELEASE 2.2.0 1.4.0.M1 1.7.3 1.3.0.RELEASE 1.5.2 1.2.0 ...

  3. ehci符合USB2.0,uhci,ohci,

    uhci   ohci   ehci他们都是主机控制器的规格,OHCI主要为非PC系统上以及带有SiShe ALi芯片组的 PC主板上的USB芯片,UHCI大多为Intel和Via主板上的USB控制器 ...

  4. POJ1080 Human Gene Functions(LCS)

    题目链接. 分析: 和 LCS 差不多. #include <iostream> #include <cstdio> #include <cstdlib> #inc ...

  5. 【转】android去掉EditView的默认焦点问题

    原文网址:http://www.111cn.net/sj/android/54680.htm 做一个输入框时发现android中EditView的默认焦点了,这种问题如果是在输入框还好,但在搜索页面或 ...

  6. cf701B Cells Not Under Attack

    Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya ...

  7. Objective-C中变量采用@property的各个属性值的含义

    我们在OC中定义变量,可以自己来定义变量的setter方法来设置变量值,用getter方法来获取变量值.但是当变量数量增多时,还采用手动添加setter/getter方法来操作变量,就会使得程序代码量 ...

  8. 一、进程与信号之exec函数system函数

    exec函数: 子进程调用exec函数执行另一个程序,exec函数进程完全由新程序代替,替换原有程序正文,数据,堆,栈段 #include <unistd.h> extern char * ...

  9. 705 - Slash Maze

    By filling a rectangle with slashes (/) and backslashes ( ), you can generate nice little mazes. Her ...

  10. 获取CPU使用情况信息(转)

    获取了内存使用情况,也可以使用PHP的 getrusage()获取CPU使用情况,该方法在windows下不可用.    print_r(getrusage()); /* 输出 Array ( [ru ...