add_settings_section()

add_settings_section()函数是Wordpress函数,将新分区添加到设置页。

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

将新分区添加到设置页。
Add a new section to a settings page.

说明(Description)

设置API的一部分。使用此选项可为管理页定义新的设置节。使用do_settings_sections()在管理页回调函数中显示设置节。使用Add_settings_field()将设置字段添加到分区中。

$callback参数应该是一个函数的名称,该函数在实际字段之前回显要显示在设置部分顶部的任何内容。如果你想的话,它什么也不能输出。


参数(Parameters)

参数类型必填说明
$id(string)必需用于标识节的段塞名称。用于标记的“id”属性中。
$title(string)必需节的格式化标题。显示为该节的标题。
$callback(callable)必需在节的顶部(在标题和字段之间)回显任何内容的函数。
$page(string)必需显示节的设置页的slug名称。内置页面包括“常规”、“阅读”、“写作”、“讨论”、“媒体”等。使用add_options_page()创建自己的页面;

返回(Return)

无返回值


源码(Source)

  1. /**
  2. * Add a new section to a settings page.
  3. *
  4. * Part of the Settings API. Use this to define new settings sections for an admin page.
  5. * Show settings sections in your admin page callback function with do_settings_sections().
  6. * Add settings fields to your section with add_settings_field()
  7. *
  8. * The $callback argument should be the name of a function that echoes out any
  9. * content you want to show at the top of the settings section before the actual
  10. * fields. It can output nothing if you want.
  11. *
  12. * @since 2.7.0
  13. *
  14. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  15. *
  16. * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
  17. * @param string $title Formatted title of the section. Shown as the heading for the section.
  18. * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
  19. * @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();
  20. */
  21. function add_settings_section($id, $title, $callback, $page) {
  22. global $wp_settings_sections;
  23. if ( 'misc' == $page ) {
  24. _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
  25. $page = 'general';
  26. }
  27. if ( 'privacy' == $page ) {
  28. _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
  29. $page = 'reading';
  30. }
  31. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
  32. }
更新版本源码位置使用被使用
2.7.0wp-admin/includes/template.php:150902

笔记(Notes)

示例用法
php类的add_settings_部分示例

0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
私信列表
搜索