返回介绍

add_settings_section()

发布于 2017-09-10 21:21:01 字数 3967 浏览 1626 评论 0 收藏 0

add_settings_section( string $id,  string $title,  callable $callback,  string $page )

Add a new section to a settings page.


description

Part of the Settings API. Use this to define new settings sections for an admin page. Show settings sections in your admin page callback function with do_settings_sections(). Add settings fields to your section with add_settings_field()

The $callback argument should be the name of a function that echoes out any content you want to show at the top of the settings section before the actual fields. It can output nothing if you want.


参数

$id

(string) (Required) Slug-name to identify the section. Used in the 'id' attribute of tags.

$title

(string) (Required) Formatted title of the section. Shown as the heading for the section.

$callback

(callable) (Required) Function that echos out any content at the top of the section (between heading and fields).

$page

(string) (Required) The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();


源代码

File: wp-admin/includes/template.php

function add_settings_section($id, $title, $callback, $page) {
	global $wp_settings_sections;

	if ( 'misc' == $page ) {
		_deprecated_argument( __FUNCTION__, '3.0.0',
			/* translators: %s: misc */
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
				'misc'
			)
		);
		$page = 'general';
	}

	if ( 'privacy' == $page ) {
		_deprecated_argument( __FUNCTION__, '3.5.0',
			/* translators: %s: privacy */
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
				'privacy'
			)
		);
		$page = 'reading';
	}

	$wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: __()
  • wp-includes/functions.php: _deprecated_argument()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Ivan Shulev

    Example usage
    The callback function receives a single optional argument, which is an array with three elements.

    
    
    add_settings_section(
    	'eg_setting_section',
    	__( 'Example settings section in reading', 'textdomain' ),
    	'wpdocs_setting_section_callback_function',
    	'reading'
    );
    
    /**
     * Settings section display callback.
     *
     * @param array $args Display arguments.
     */ 
    function wpdocs_setting_section_callback_function( $args ) {
    	// echo section intro text here
    	echo '<p>id: ' . esc_html( $args['id'] ) . '</p>';                         // id: eg_setting_section
    	echo '<p>title: ' . apply_filters( 'the_title', $args['title'] ) . '</p>'; // title: Example settings section in reading
    	echo '<p>callback: ' . esc_html( $args['callback'] ) . '</p>';             // callback: eg_setting_section_callback_function
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文