Options API 是 WordPress 中用于在数据库中存储数据的标准化接口,支持增删改查操作,数据存储在 wp_options 表中。本文档提供了技术参考,包括函数列表、代码示例和按类别分类的默认选项详情。
// 创建选项到数据库
add_option( $option, $value = , $deprecated = , $autoload = 'yes' );
// 按名称删除选项
delete_option( $option );
// 获取已保存的选项
get_option( $option, $default = false );
// 更新已添加选项的值
update_option( $option, $newvalue ); The Options API is a simple and standardized way of storing data in the database. The API makes it easy to create, access, update, and delete options. All the data is stored in the wp_options table under a given custom name.
This page contains the technical documentation needed to use the Options API. A list of default options can be found in the Option Reference (link to Codex version, waiting for content migration to HelpHub).
Note that the _site_ functions are essentially the same as their counterparts. The only differences occur for WP Multisite, when the options apply network-wide and the data is stored in the wp_sitemeta table under the given custom name.
Add/Delete Option:
Get/Update Option:
// Create an option to the database
add_option( $option, $value = , $deprecated = , $autoload = 'yes' );
// Removes option by name.
delete_option( $option );
// Fetch a saved option
get_option( $option, $default = false );
// Update the value of an option that was already added.
update_option( $option, $newvalue );
blacklist_keys: When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be marked as spam. One word or IP per line. It will match inside words, so “press” will match “WordPress.”comment_max_links: Hold a comment in the queue if it contains the value of this option or more.comment_moderation: Before a comment appears, an administrator must always approve the comment.comments_notify: E-mail me when anyone posts a comment.default_comment_status: Allow comments (can be overridden with individual posts)default_ping_status: Allow link notifications from other blogs (pingbacks and trackbacks).default_pingback_flag: Attempt to notify any blogs linked to from the article (slows down posting).moderation_keys: When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be held in the moderation queue. One word or IP per line. It will match inside words, so “press” will match “WordPress.”moderation_notify: E-mail me when a comment is held for moderation.require_name_email: Before a comment appears, the comment author must fill out his/her name and email.thread_comments: Enable WP-native threaded (nested) comments.thread_comments_depth: Set the number of threading levels for comments.show_avatars: Avatar Displayavatar_rating: Maximum Ratingavatar_default: Default Avatarclose_comments_for_old_posts: Automatically close comments on old articlesclose_comments_days_old: Automatically close comments on articles older than x daysshow_comments_cookies_opt_in: Show the cookies opt-in checkbox on the comment form and enable comment cookiespage_comments: Break comments into pagescomments_per_page:default_comments_page:comment_order:comment_whitelist: Comment author must have a previously approved commentadmin_email: Administrator emailblogdescription: Blog taglineblogname: Blog titlecomment_registration: Users must be registered and logged in to commentdate_format: Default date formatdefault_role: The default role of users who register at the blog.gmt_offset: Times in the blog should differ by this value.home: Blog address (URL)siteurl: WordPress address (URL)wp_guess_url()start_of_week: The starting day of the week.time_format: Default time formattimezone_string: Timezoneusers_can_register: Anyone can registerlinks_updated_date_format:__('F j, Y g:i a')links_recently_updated_prepend:links_recently_updated_appendlinks_recently_updated_timethumbnail_size_w:thumbnail_size_h:thumbnail_crop: Crop thumbnail to exact dimensions (normally thumbnails are proportional)medium_size_w: medium_size_hlarge_size_wlarge_size_hembed_autourls: Attempt to automatically embed all plain text URLsembed_size_wembed_size_hhack_file: Use legacy my-hacks.php file supporthtml_type: Default MIME type for blog pages (text/html, text/xml+html, etc.)secret: Secret value created during installation used with salting, etc.upload_path: Store uploads in this folder (relative to the WordPress root)upload_url_path: URL path to upload folder (will be blank by default – Editable in “All Settings” Screen.uploads_use_yearmonth_folders: Organize my uploads into month- and year-based foldersuse_linksupdate: Track links’ update timespermalink_structure: The desired structure of your blog’s permalinks. Some examples:/%year%/%monthnum%/%day%/%postname%/: Date and name based/archives/%post_id%/: Numeric/%postname%/: Post name-basedcategory_base: The default category base of your blog categories permalink.tag_base: The default tag base for your blog tags permalink.blog_public:blog_charset: Encoding for pages and feeds. The character encoding you write your blog in (UTF-8 is recommended).UTF-8gzipcompression: WordPress should compress articles (with gzip) if browsers ask for them.page_on_front: The ID of the page that should be displayed on the front page. Requires show_on_front‘s value to be page.page_for_posts: The ID of the page that displays posts. Useful when show_on_front‘s value is page.posts_per_page: Show at most x many posts on blog pages.posts_per_rss: Show at most x many posts in RSS feeds.rss_language: Language for RSS feeds (metadata purposes only)enrss_use_excerpt: Show an excerpt instead of the full text of a post in RSS feedsshow_on_front: What to show on the front pagetemplate: The slug of the currently activated theme (how it is accessed by path, ex. /wp-content/themes/my-theme (my-theme would be the value of this option).stylesheet: The slug of the currently activated stylesheet (style.css) (how it is accessed by path, ex. /wp-content/themes/my-style (my-style would be the value of this option)default_category: ID of the category that posts will be put in by defaultdefault_email_category: ID of the category that posts will be put in by default when written via e-maildefault_link_category: ID of the category that links will be put in by defaultdefault_post_edit_rows: Size of the post box (in lines)mailserver_login: Mail server username for posting to WordPress by e-mailmailserver_pass: Mail server password for posting to WordPress by e-mailmailserver_port: Mail server port for posting to WordPress by e-mailmailserver_url: Mail server for posting to WordPress by e-mailping_sites: When you publish a new post, WordPress automatically notifies the following site update services. For more about this, see Update Services. Separate multiple service URLs with line breaks. Requires blog_public to have a value of 1.use_balanceTags: Correct invalidly-nested XHTML automaticallyuse_smilies: Convert emoticons like :-) and :P to graphics when displayeduse_trackback: Enable sending and receiving of trackbacksenable_app: Enable the Atom Publishing Protocolenable_xmlrpc: Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocolsactive_plugins: Returns an array of strings containing the path of the main php file of the plugin. The path is relative to the plugins folder. An example of path in the array : /mainpage.php.advanced_edit: recently_edited: image_default_link_type: image_default_size: image_default_align: sidebars_widgets: Returns array of sidebar states (list of active and inactive widgets).sticky_posts: widget_categories:widget_text:widget_rss:WordPress 3.0 removed Settings > Miscellaneous screen and some of the options cannot be reached (e.g. upload_url_path). You may use the All Settings Screen to view and change almost all options listed above. It is accessible by visiting /wp-admin/options.php
