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. Spring Boot集成Jasypt安全框架

    Jasypt安全框架提供了Spring的集成,主要是实现 PlaceholderConfigurerSupport类或者其子类. 在Sring 3.1之后,则推荐使用PropertySourcesPl ...

  2. 【转】Eclipse导入library的时候报:Found 2 versions of android-support-v4.jar in the dependency list

    原文网址:http://www.07net01.com/2015/03/779691.html 错误类型:Eclipse导入library的时候报:Found 2 versions of androi ...

  3. 【转】Linux I2C设备驱动编写(二)

    原文网址:http://www.cnblogs.com/biglucky/p/4059582.html 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_drive ...

  4. 首届京东自有品牌科技周“京东点亮生活”圆满成功 - 课程公告板 - 京东内部论坛 - Powered by Discuz!

    首届京东自有品牌科技周"京东点亮生活"圆满成功 - 课程公告板 - 京东内部论坛 - Powered by Discuz! 首届京东自有品牌科技周"京东点亮生活" ...

  5. 如何计算Java对象占用了多少空间?

    在Java中没有sizeof运算符,所以没办法知道一个对象到底占用了多大的空间,但是在分配对象的时候会有一些基本的规则,我们根据这些规则大致能判断出来对象大小. 对象头 对象的头部至少有两个WORD, ...

  6. linux内核--自旋锁的理解

    http://blog.chinaunix.net/uid-20543672-id-3252604.html 自旋锁:如果内核配置为SMP系统,自旋锁就按SMP系统上的要求来实现真正的自旋等待,但是对 ...

  7. java在windows下加载dll

    java在类中加载动态链接库文件. 类文件中: static { System.loadLibrary("dll文件"); } dll文件在工程的包路径下.例如:pro/bin/h ...

  8. python学习笔记(集合的使用)

    集合 集合(set):把不同的元素组成一起形成集合,是python基本的数据类型. 集合元素(set elements):组成集合的成员 为什么需要集合? 集合的作用 1 .列表去重复数据 按照现有知 ...

  9. Heritrix的安装与配置 (最新版 已测试通过)

    本教程,结合本人亲身实践,不仅适合于最新版本Heritrix 1.14.4,更适合其他任何版本.Heritrix具体下载地址如下:      http://sourceforge.net/projec ...

  10. tomcat安全配置之禁用Directory Listing

    什么是Directory Listing?通俗点讲,就是在webapp的目录下如果没有放置index.html或者类似的文件,如果从IE或者其它浏览器文章这个路径时,会惊喜的发现这个目录下的文件列表被 ...