函数原型
add_settings_field( string $id, string $title, callable $callback, string $page, string $section = ‘default’, array $args = array() )
函数描述
Adds a new field to a section of a settings page.
是否弃用
未弃用
函数参数
-
$id
string
Required - Slug-name to identify the field. Used in the
'id'attribute of tags. -
$title
string
Required - Formatted title of the field. Shown as the label for the field during output.
-
$callback
callable
Required - Function that fills the field with the desired form inputs. The function should echo its output.
-
$page
string
Required - The slug-name of the settings page on which to show the section (general, reading, writing, …).
-
$section
string
Optional - The slug-name of the section of the settings page in which to show the box. Default
'default'.Default:
'default' -
$args
array
Optional - Extra arguments that get passed to the callback function.
label_forstringWhen supplied, the setting title will be wrapped in a<label>element, itsforattribute populated with this value.classstringCSS Class to be added to the<tr>element when the field is output.
Default:
array()
函数返回值
无
函数位置
File: wp-admin/includes/template.php.
函数源码
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
global $wp_settings_fields;
if ( 'misc' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.0.0',
sprintf(
/* translators: %s: misc */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'misc'
)
);
$page = 'general';
}
if ( 'privacy' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.5.0',
sprintf(
/* translators: %s: privacy */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'privacy'
)
);
$page = 'reading';
}
$wp_settings_fields[ $page ][ $section ][ $id ] = array(
'id' => $id,
'title' => $title,
'callback' => $callback,
'args' => $args,
);
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.2.0 | The $class argument was added. |
| 2.7.0 | Introduced. |

