WordPress函数文档add_settings_field()

注册添加一个设置选项项目 描述 Register a settings field to a settings…

注册添加一个设置选项项目

描述

Register a settings field to a settings page and section.

This is part of the Settings API, which lets you automatically generate wp-admin settings pages by registering your settings and using a few callbacks to control the output.

This function assumes you already know the settings $page and the page $section that the field should be shown on.

You MUST register any options used by this function with register_setting() or they won’t be saved and updated automatically.

The callback function needs to output the appropriate html input and fill it with the old value, the saving will be done behind the scenes.

The html input field’s name attribute must match $option_name in register_setting(), and value can be filled using get_option().

This function can also be used to add extra settings fields to the default WP settings pages like media or general. You can add them to an existing section, or use add_settings_section() to create a new section to add the fields to.

See Settings API for details.

用法

<?php add_settings_field$id$title$callback$page$section$args ); ?>

参数

$id

(string) (必填) String for use in the ‘id’ attribute of tags.

默认值: None

$title

(string) (必填) Title of the field.

默认值: None

$callback

(string) (必填) Function that fills the field with the desired inputs as part of the larger form. Passed a single argument, the $args array. Name and id of the input should match the $id given to this function. The function should echo its output.

默认值: None

$page

(string) (必填) The menu page on which to display this field. Should match $menu_slug from add_theme_page() or from do_settings_sections().

默认值: None

$section

(string) (可选) The section of the settings page in which to show the box (default or a section you added with add_settings_section(), look at the page in the source to see what the existing ones are.)

默认值: default

$args

(array) (可选) Additional arguments that are passed to the $callback function. The ‘label_for’ key/value pair can be used to format the field title like so: <label for=”value”>$title</label>.

默认值: array()

返回值

(void) 

This function does not return a value.

示例

With Label

Adds a setting with id “myprefix_setting-id” to the General Settings page. “myprefix” should be a unique string for your plugin or theme. Sets a label so that the setting title can be clicked on to focus on the field.

历史

添加于 版本: 2.7.0

源文件

add_settings_field() 函数的代码位于 wp-admin/includes/template.php.

相关

Settings API:
register_setting(),
unregister_setting(),
add_settings_field(),
add_settings_section(),
add_settings_error(),
get_settings_errors(),
settings_errors()

  • 原文:http://codex.wordpress.org/Function_Reference/add_settings_field
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT