add_settings_section()添加一个设置选项单元

目录

描述

Settings Sections are the groups of settings you see on WordPress settings pages with a shared heading. In your plugin you can add new sections to existing settings pages rather than creating a whole new page. This makes your plugin simpler to maintain and creates less new pages for users to learn. You just tell them to change your setting on the relevant existing page.

add_settings_section() 描述

用法

<?php add_settings_section$id$title$callback$page ); ?>

add_settings_section() 用法

参数

$id

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

默认值: None

$title

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

默认值: None

$callback

(string) (必填) Function that fills the section with the desired content. The function should echo its output.

默认值: None

$page

(string) (必填) The menu page on which to display this section. Should match $menu_slug from Function Reference/add theme page

默认值: None

add_settings_section() 参数

返回值

(void) 

This function does not return a value.

add_settings_section() 返回值

注意

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

add_settings_section(
	'eg_setting_section',
	'Example settings section in reading',
	'eg_setting_section_callback_function',
	'reading'
);
function eg_setting_section_callback_function( $arg ) {
	// echo section intro text here
	echo '<p>id: ' . $arg['id'] . '</p>';             // id: eg_setting_section
	echo '<p>title: ' . $arg['title'] . '</p>';       // title: Example settings section in reading
	echo '<p>callback: ' . $arg['callback'] . '</p>'; // callback: eg_setting_section_callback_function
}

add_settings_section() 注意

历史

添加于 版本: 2.7.0

add_settings_section() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Add a new section to a settings page.
 *
 * 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.
 *
 * @since 2.7.0
 *
 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
 *
 * @param string $id       Slug-name to identify the section. Used in the 'id' attribute of tags.
 * @param string $title    Formatted title of the section. Shown as the heading for the section.
 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
 * @param string $page     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();
 */
function add_settings_section($id, $title, $callback, $page) {
	global $wp_settings_sections;

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

	if ( 'privacy' == $page ) {
		_deprecated_argument( __FUNCTION__, '3.5', 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);
}

add_settings_section() 源文件

相关