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 } ?>

最新文章

  1. :after和:before的作用及使用方法
  2. MJPhotoBrowser BUG修复
  3. linker command failed with exit code 1 (use -v to see invocation)
  4. dig理解dns主备 - 阿权的书房
  5. 万年历---java版
  6. 利用NTFS交换数据流隐藏文件
  7. Linux复制指定目录及子目录下特定类型的文件
  8. redis的文件事件处理器
  9. Linux磁盘空间爆满,MySQL无法启动
  10. C#多线程(上) 分类: C# 线程 2015-03-09 10:35 174人阅读 评论(0) 收藏
  11. 阅读&amp;lt;反欺骗的艺术&amp;gt;思考
  12. GCD教程(四):完结
  13. windows7 64bit下mvn命令后提示‘cmd’不是内部或外部命令,也不是可执行程序或批处理文件
  14. Python爬虫学习之使用beautifulsoup爬取招聘网站信息
  15. Sql Server的艺术(七) SQL 数据插入操作
  16. 从壹开始 [ Id4 ] 之二║ 基础知识集合 &amp; 项目搭建一
  17. Android深入四大组件(九)Content Provider的启动过程
  18. 【非专业前端】使用vue2.5.17+element2.4.5
  19. 解决ftp客户端连接验证报错Server sent passive reply with unroutable address. Using server address instead
  20. ThinkPHP5模型操作中的自动时间戳总结

热门文章

  1. 利用JavaScript 的formdata 进行无刷新上传文件
  2. php的一些小笔记--时间函数
  3. some logo.
  4. 递归实现全排列序列C语言实现
  5. 什么是REST架构 - z
  6. [POJ] 2785 4 Values whose Sum is 0(双向搜索)
  7. [TYVJ] P1027 木瓜地
  8. hdu 3832 Earth Hour
  9. UVa156.Ananagrams
  10. SoftLayerDebug