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

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

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

<?php
/**
*Plugin Name: Second Plugins Demo
*Plugin URI: http://www.cnblogs.com/fxmbz/p/4030286.html
*Description: Second Plugins Demo, This plugin shows a line end of welcome information on the content, add the Settings menu button In the Settings men
*Version: 1.0
*Author: Zhangxl
*Author URI: http://www.cnblogs.com/fxmbz
*License: GPL
*Text Domain: 29583035
*/ /**
* add_action funtions not exists exit and prompt
*/
if ( !function_exists( 'add_action' ) ) {
echo 'Hi there! I\'m just a plugin, not much I can do when cwholeed directly.';
exit;
}
/**
* [add_action($hook,$function)]
* [add_css_link add css link]
*/
add_action( 'wp_head','add_css_link' );
function add_css_link() {
$styleUrl = plugin_dir_url( __FILE__ ) . 'css/style.css';
echo "<link rel='stylesheet' href='$styleUrl'>";
} /**
* [register_activation_hook run set_text_options]
*/
register_activation_hook( __FILE__, 'set_text_options' ); /**
* [register_deactivation_hook run del_text_options]
*/
register_deactivation_hook( __FILE__, 'del_text_options' ); /**
* [set_text_options insert data in the options table]
*/
function set_text_options() {
add_option( 'display_text_thearticle', '<p id="display_text_thearticle">Welcome to second plugin testing! This plugin is only added word at the end of the article. author: Zhangxl, Email: 29583035@qq.com</p>' );
} /**
* [del_text_options delete data in the options table]
*/
function del_text_options() {
delete_option( 'display_text_thearticle' );
} /**
* [add_action add text to the content end]
* [display_text is single show content and new add infomation]
* @param [type] $content [the source article content]
* @return [type] [string]
*/
add_action('the_content','display_text');
function display_text($content) {
if ( is_single() ) {
$content = $content . get_option( 'display_text_thearticle' );
return $content;
} else {
return $content;
}
} /**
* is admin page run [add_action($hook,$function) ]
*/
if ( is_admin() ) {
add_action('admin_menu','display_text_menu');
} /**
* [display_text_menu add admin menu settings page]
* @return [type] [description]
*/
function display_text_menu() {
// add_options_page( $page_title, $menu_title, $capability(权限), $menu_slug(URL-friendly name), $function );
add_options_page('Text Settings', 'Text Settings', 'manage_options', 'display_text_thearticle','display_text_html_page');
} /**
* [display_text_html_page settings page form]
* @return [type] [description]
*/
function display_text_html_page() {
?>
<div>
<h2>Settings Version information</h2>
<form method="post" action="options.php">
<!-- 下面这行代码用来保存表单中内容到数据库(官网的方法) -->
<?php wp_nonce_field( 'update-options' ); ?>
<p>
<textarea cols="80" rows="6" name="display_text_thearticle" id="display_text_thearticle" ><?php echo get_option('display_text_thearticle'); ?></textarea>
</p> <!-- 下面这两个隐藏字段为必须,其中第二个字段的值为要修改的字段名(官网的方法) -->
<p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="display_text_thearticle" />
<input type="submit" value="Save Changes" class="button-primary" />
</p>
</form>
</div>
<?php } ?>

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

  1. WordPress插件制作笔记(一)---First Plugins Demo

    1->add_action  HOOK简单说明: http://codex.wordpress.org/Plugin_API/Action_Reference (参考网址) //在后台页脚位置加 ...

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

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

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

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

  4. WordPress插件制作教程概述

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. DoctrineMigrationsBundle

    数据库迁移特征是数据库抽象层的扩展,允许你用编程的方式,安全.方便.标准化实现数据库结构的更新. 安装 首先使用composer安装 $ composer require doctrine/doctr ...

  2. Django QuerySets 里的**kwargs: 动态创建ORM查询

    Django的数据库API查询经常包含关键字参数.例如: bob_stories = Story.objects.filter(title_contains='bob', subtitle_conta ...

  3. NAS4Free 安装配置(二)系统安装

    NAS4Free系统安装 看一看BIOS设置 开机按DEL进BIOS 改日期时间 这里可以设置RAID,因为ZFS的RAID功能更好,所以我们在这里不配置RAID 制作LiveUSB 用软件(USB ...

  4. Here are some of my ideas .

    1:Learning english is very important ,its the very useful for my major studying and my future develo ...

  5. Keil C51必须注意的一些有趣特性

    Keil c51号称作为51系列单片机最好的开发环境,大家一定都很熟悉.它的一些普通的特性大家也都了解,(书上也都说有)如:因为51内的RAM很小,C51的函数并不通过堆栈传递参数(重入函数除外),局 ...

  6. 全局函数的Result一定要每次都初始化,否则上次的结果会被保持到下一次继续使用

    测试半天,原来是因为这个原因.下面例子中,Result:=''必须写,否则其结果会被累计,真是昏倒!! function MyPaths(tache: IXMLTaskType) : String; ...

  7. Smarty 变量使用

    Smarty的标签都是使用定界符括起来. 默认定界符是{ 和 }, 但定界符可以被改变. 比如说在本手册,我们会假定你在使用默认的定界符. 在Smarty看来,任何在定界符之外的内容,都是静态的,或者 ...

  8. UESTC_Dividing Numbers CDOJ 1156

    Dividing Numbers Time Limit: 9000/3000MS (Java/Others)     Memory Limit: 262144/262144KB (Java/Other ...

  9. 认识Ant

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一.            ...

  10. Spark函数详解系列之RDD基本转换

    摘要:   RDD:弹性分布式数据集,是一种特殊集合 ‚ 支持多种来源 ‚ 有容错机制 ‚ 可以被缓存 ‚ 支持并行操作,一个RDD代表一个分区里的数据集   RDD有两种操作算子:         ...