随笔分类 -  Wordpress

wp plugin -19
摘要:THE SETTINGS APIThe Settings API enables you to handle the simple tasks:Tell WordPress that you are going to use some new options and how you want themdisplayed.Specify a function that will sanitize user inputs.And let WordPress transparently manage for you the cumbersome and repetitive parts:Draw m 阅读全文

posted @ 2012-12-05 18:46 kalintw 阅读(128) 评论(0) 推荐(0)

wp plugin -18
摘要:wp_options tableSaving Optionsadd_option( ‘boj_myplugin_color’, ‘red’ );update_option( ‘boj_myplugin_color’, ‘blue’ );Saving an Array of Options< ?php$options = array(‘color’ = > ‘red’,‘fontsize’ = > ‘120%’,‘border’ = > ‘2px solid red’);update_option( ‘boj_myplugin_options’, $options );? 阅读全文

posted @ 2012-12-05 10:17 kalintw 阅读(95) 评论(0) 推荐(0)

wp plugin -17
摘要:var_dump( $shortcode_tags );remove_shortcode()remove_all_shortcodes()strip_shortcodes()< ?php$content = < < < SSome existing shortcodes: [amazonimage] [gallery]These don’t exist: [bleh] [123]S;echo strip_shortcodes( $content );/* Result:Some existing shortcodes:These don’t exist: [bleh] 阅读全文

posted @ 2012-12-04 19:55 kalintw 阅读(113) 评论(0) 推荐(0)

wp plugin -16
摘要:Register Custom Shortcodesshortcode 在wordpress中的作用与重要性不言而喻。主要从如下的几个方面考虑:不同格式的shortcode不同格式的shortcode: [book]单模式下的shortcode,使用属性闭合模式 [book 属性] content [/book]多种嵌套shortcode针对不同的custom type来应用 shortcode在编辑器中点击即生成shortcode,即非手动嵌套shortcodeadd_action( 'init', 'sanofi_register_shortcodes' ) 阅读全文

posted @ 2012-12-04 19:34 kalintw 阅读(192) 评论(0) 推荐(0)

wp plugin -15
摘要:Creating a Top - Level Menuadd_menu_page( page_title, menu_title, capability, menu_slug, function,icon_url, position );page_title — The title of the page as shown in the <title> tagsmenu_title — The name of your menu displayed on the dashboardcapability — Minimum capability required to view th 阅读全文

posted @ 2012-12-04 14:15 kalintw 阅读(101) 评论(0) 推荐(0)

wp plugin -14
摘要:CREATING CUSTOM HOOKSdo_action()do_action_ref_array()apply_filters()apply_filters_ref_array()Custom Action Hook Example< ?phpadd_action( ‘plugins_loaded’, ‘boj_myplugin_setup’ );function boj_myplugin_setup() {/* Allow actions to fire before anything else. */do_action( ‘boj_myplugin_setup_pre’ );/ 阅读全文

posted @ 2012-12-04 12:22 kalintw 阅读(126) 评论(0) 推荐(0)

wp plugin -13
摘要:Commonly Used Filter Hooksthe_contentthe_titletemplate_includefront_page_templatehome_templatesingle_templatepage_templateattachment_templatearchive_templatecategory_templatetag_templateauthor_templatedate_templatearchive_templatesearch_template404_templateindex_template 阅读全文

posted @ 2012-12-04 10:51 kalintw 阅读(79) 评论(0) 推荐(0)

wp plugin -12
摘要:apply_filters_ref_array( $tag, $args );$tag — The name of the filter hook.$args — An array of arguments to pass to filters registered for the hook.remove_filter( $tag, $function_to_remove, $priority, $accepted_args );$tag — The name of the filter hook to remove a filter from.$function_to_remove — Th 阅读全文

posted @ 2012-12-03 23:32 kalintw 阅读(90) 评论(0) 推荐(0)

wp plugin -11
摘要:apply_filters( $tag, $value );$tag — The name of the filter hook.$value — The parameter passed to any filters added to the hook. The function can alsotake in any number of extraparameters to pass to filters.add_filter( $tag, $function, $priority, $accepted_args );$tag — The name of the hook you want 阅读全文

posted @ 2012-12-03 22:56 kalintw 阅读(140) 评论(0) 推荐(0)

wp plugin -10
摘要:Commonly Used Action Hooks(1)plugins_loaded。一个WP插件应该在此hook做setup。It isfired after most of the WordPress files are loaded but before the pluggable functions and WordPressstarts executing anything;plugins_loaded is executed when all the user’s activated plugins have been loaded by WordPress. Itis also 阅读全文

posted @ 2012-12-03 22:29 kalintw 阅读(127) 评论(0) 推荐(0)

wp plugin -9
摘要:do_action_ref_array( $tag, $args );$tag — The name of the action hook.$args — An array of arguments passed to actions registered for the hook. Generally, thiswould be an object that actions can change.< ?phpdo_action_ref_array( ‘pre_get_posts’, array( & $this ) );add_action( ‘pre_get_posts’, 阅读全文

posted @ 2012-12-03 21:01 kalintw 阅读(116) 评论(0) 推荐(0)

wp plugin -8
摘要:do_action( $tag, $arg = ‘’ );$tag — The name of the action hook.$arg — Value(s) passed to registered actions. It looks like a single parameter, but this isn ’ talways the case. Action hooks have the option to pass any number of parameters or noparameters at all. You need to check the WordPress sourc 阅读全文

posted @ 2012-12-03 18:10 kalintw 阅读(98) 评论(0) 推荐(0)

wp plugin -7
摘要:Deactivate Is Not UninstallTwo uninstall methods:(1) Uninstall.php:< ?php// If uninstall not called from WordPress exitif( !defined( ‘WP_UNINSTALL_PLUGIN’ ) )exit ();// Delete option from options tabledelete_option( ‘boj_myplugin_options’ );//remove any additional options and custom tables? >( 阅读全文

posted @ 2012-12-03 15:49 kalintw 阅读(119) 评论(0) 推荐(0)

wp plugin -6
摘要:Deactivation:Deactivation时会触发register_deactivation_hook()。register_ deactivation_hook( $file, $function )$file - (string) (required) — Path to the primary plugin fi le$function - (string) (required) — The function to be executed when the plugin is activated例如:< ?phpregister_deactivation_hook( __F 阅读全文

posted @ 2012-12-03 13:19 kalintw 阅读(140) 评论(0) 推荐(0)

wp plugin -5
摘要:options激活时可以设置option:< ?phpregister_activation_hook( __FILE__, ‘boj_install’ );function boj_install() {$boj_myplugin_options = array(‘view’ = > ‘grid’,‘food’ = > ‘bacon’,‘mode’ = > ‘zombie’);update_option( ‘boj_myplugin_options’, $boj_myplugin_options );}? > 阅读全文

posted @ 2012-12-03 13:12 kalintw 阅读(95) 评论(0) 推荐(0)

wp plugin -4
摘要:plugin激活插件激活时,plugin activation function将会被触发。register_activation_hook()。主要用于设置默认options、检测版本兼容等。register_activation_hook( $file, $function );$file - (string) (required) — Path to the primary plugin file$function - (string) (required) — The function to be executed when the plugin is activated例如:< 阅读全文

posted @ 2012-12-03 13:06 kalintw 阅读(103) 评论(0) 推荐(0)

wp plugin -3
摘要:PathsLocal path:plugin_dir_path( __FILE__ );plugin_dir_path( __FILE__ ) .’js/scripts.js’;URL path:plugins_url(),Full plugins directory URL, example:http://example.com/wp-content/pluginsincludes_url(),http://example.com/wp-includescontent_url(), http://example.com/wp-contentadmin_url(), http://exampl 阅读全文

posted @ 2012-12-03 12:46 kalintw 阅读(172) 评论(0) 推荐(0)

wp plugin -2
摘要:Sanity practices:(1)命名前缀。plugin范围内,变量、函数名、文件名加一个唯一前缀。(2)文件组织。至少应该有两个文件:主要的php文件和一个uninstall.php。主要的php可以细分为更多的小文件,便于update和性能。(3)目录结构。example:primary.phpuninstall.php/js/css/includes/imagesHeader:< ?php/*Plugin Name: My PluginPlugin URI: http://example.com/wordpress-plugins/my-pluginDescription: 阅读全文

posted @ 2012-12-03 12:06 kalintw 阅读(120) 评论(0) 推荐(0)

wp plugin -1
摘要:plugin本质上就是写一个函数并使用hook注册plugin consists of:(1) header(2) functionregister_activation_hook( $file, $function )register_deactivation_hook($file, $function) 阅读全文

posted @ 2012-12-02 22:31 kalintw 阅读(128) 评论(0) 推荐(0)

short code
摘要:允许非编程人员直接使用的功能函数,并且可以添加属性等,类似标签( from v2.5 on) 1 <?php 2 /* 3 Plugin Name: Map plugin using shortcode 4 Plugin URI: http://www.falkonproductions.com/shortcodeMaps/ 5 Description: This plugin will get a map of whatever parameter is passed. 6 Author: Drew Falkman 7 Version: 1.0 8 Author URI: http:/ 阅读全文

posted @ 2012-08-30 23:16 kalintw 阅读(244) 评论(0) 推荐(0)

导航