辛星浅析WordPress中的get_option
来源:互联网 发布:淘宝卖小样的正品店 编辑:程序博客网 时间:2024/05/17 09:36
WordPress使用get_option()来获取通过option表单设置值的方法,如果数据库中不存在该选项,或者改选项的值为空,那么将会返回一个false。
通过get_option获得的值通常都可以在后台的"菜单"->"常规"中获得。而且它们内容如下:
admin_email 管理员的email地址
blogname 网站title标题
blogscription 网站描述
blog_charset 网站编码,一般都是utf-8
date_format 日期格式
default_category 文章默认分类
home 网站地址
siteurl WordPress的web地址
template 当前主题名称
start_of-week 星期开始设置
upload_path 上传默认目录
posts_per_page 文章分页每页显示的数量
posts_per_rss rss聚合显示的最新文章数量
需要注意的是该函数可以接受两个参数,如果查询的第一个参数不存在时,就会返回第二个参数。
如果只写一个参数,那么当查询的第一个参数不存在时,将会返回false。
get-option()位于wp-includes/option.php文件中,其函数的源代码部分(3.9版本)如下:
/** * Option API * * @package WordPress * @subpackage Option *//** * Retrieve option value based on name of option. * * If the option does not exist or does not have a value, then the return value * will be false. This is useful to check whether you need to install an option * and is commonly used during installation of plugin options and to test * whether upgrading is required. * * If the option was serialized then it will be unserialized when it is returned. * * @since 1.5.0 * * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. * @param mixed $default Optional. Default value to return if the option does not exist. * @return mixed Value set for the option. */function get_option( $option, $default = false ) {global $wpdb;$option = trim( $option );if ( empty( $option ) )return false;/** * Filter the value of an existing option before it is retrieved. * * The dynamic portion of the hook name, $option, refers to the option name. * * Passing a truthy value to the filter will short-circuit retrieving * the option value, returning the passed value instead. * * @since 1.5.0 * * @param bool|mixed $pre_option Value to return instead of the option value. * Default false to skip it. */$pre = apply_filters( 'pre_option_' . $option, false );if ( false !== $pre )return $pre;if ( defined( 'WP_SETUP_CONFIG' ) )return false;if ( ! defined( 'WP_INSTALLING' ) ) {// prevent non-existent options from triggering multiple queries$notoptions = wp_cache_get( 'notoptions', 'options' );if ( isset( $notoptions[$option] ) )/** * Filter the default value for an option. * * The dynamic portion of the hook name, $option, refers * to the option name. * * @since 3.4.0 * * @param mixed $default The default value to return if the option * does not exist in the database. */return apply_filters( 'default_option_' . $option, $default );$alloptions = wp_load_alloptions();if ( isset( $alloptions[$option] ) ) {$value = $alloptions[$option];} else {$value = wp_cache_get( $option, 'options' );if ( false === $value ) {$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );// Has to be get_row instead of get_var because of funkiness with 0, false, null valuesif ( is_object( $row ) ) {$value = $row->option_value;wp_cache_add( $option, $value, 'options' );} else { // option does not exist, so we must cache its non-existence$notoptions[$option] = true;wp_cache_set( 'notoptions', $notoptions, 'options' );/** This filter is documented in wp-includes/option.php */return apply_filters( 'default_option_' . $option, $default );}}}} else {$suppress = $wpdb->suppress_errors();$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );$wpdb->suppress_errors( $suppress );if ( is_object( $row ) ) {$value = $row->option_value;} else {/** This filter is documented in wp-includes/option.php */return apply_filters( 'default_option_' . $option, $default );}}// If home is not set use siteurl.if ( 'home' == $option && '' == $value )return get_option( 'siteurl' );if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )$value = untrailingslashit( $value );/** * Filter the value of an existing option. * * The dynamic portion of the hook name, $option, refers to the option name. * * @since 1.5.0 As 'option_' . $setting * @since 3.0.0 * * @param mixed $value Value of the option. If stored serialized, it will be * unserialized prior to being returned. */return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );}
0 0
- 辛星浅析WordPress中的get_option
- 辛星浅析WordPress中的别名
- wordpress 函数详解 add_option delete_option update_option get_option
- 辛星浅析WordPress的主题文件的调用机制
- 辛星浅析Linux中的inode
- 辛星浅析Linux中的信号
- 辛星浅析Redis中的有序集合
- 辛星浅析Redis中的配置文件
- 辛星浅析Redis中的字符串类型
- 辛星浅析Redis中的服务器管理
- 辛星浅析Redis中的主从复制
- 辛星浅析Linux中的GCC
- 辛星浅析Linux中的crond
- 辛星浅析Linux中的电源管理
- 辛星浅析Linux中的lib
- 辛星浅析Linux中的postfix
- 辛星浅析linux中的日志
- 辛星浅析linux中的last命令
- HashMap实现原理
- Relay:一种内核到用户空间的高效数据传输技术
- Android 入门 (五) android的模拟器定制
- iPhone开发工具篇-利用xcode profile和analyze进行性能优化
- 解决拖动无标题窗口时无法同时响应ButtonDown和ButtonUp消息的问题
- 辛星浅析WordPress中的get_option
- MIT《Introduction to Computer Science and Programming》: Testing and Debugging
- POJ 2296 Map Labeler(二分边长+2-sat判解)(经典题)
- Truck History
- java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和联系
- MFC - EXCEL表格
- MemStore刷写线程—MemStoreFlusher源代码分析
- struts2上传图片后并显示图片
- 在本地部署Metro应用程序的方法