From 54049c5f41b55a1c6bca5b94eea3cbe37a652c35 Mon Sep 17 00:00:00 2001
From: ryan
Date: Tue, 9 Sep 2008 22:31:22 +0000
Subject: [PATCH] add_settings_section() and add_settings_field(). see #7682
git-svn-id: http://svn.automattic.com/wordpress/trunk@8855 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/includes/template.php | 86 ++++++++++++++++++++++++++++++++-
wp-admin/options-discussion.php | 4 +-
wp-admin/options-general.php | 3 ++
wp-admin/options-misc.php | 5 +-
wp-admin/options-permalink.php | 4 ++
wp-admin/options-privacy.php | 3 ++
wp-admin/options-reading.php | 1 +
wp-admin/options-writing.php | 8 ++-
8 files changed, 110 insertions(+), 4 deletions(-)
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php
index 3661d582a..c599cd76c 100644
--- a/wp-admin/includes/template.php
+++ b/wp-admin/includes/template.php
@@ -1507,7 +1507,6 @@ function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $pri
$wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
}
-// crazyhorse - this can be made simpler
function do_meta_boxes($page, $context, $object) {
global $wp_meta_boxes;
static $already_sorted = false;
@@ -1602,4 +1601,89 @@ function meta_box_prefs($page) {
}
}
}
+
+/**
+ * Add a new section to a settings page
+ *
+ * @since 2.7
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the section
+ * @param string $callback Function that fills the section with the desired content. The function should echo its output.
+ * @param string $page The type of settings page on which to show the section (general, reading, writing, ...)
+ */
+function add_settings_section($id, $title, $callback, $page) {
+ global $wp_settings_sections;
+
+ if ( !isset($wp_settings_sections) )
+ $wp_settings_sections = array();
+ if ( !isset($wp_settings_sections[$page]) )
+ $wp_settings_sections[$page] = array();
+ if ( !isset($wp_settings_sections[$page][$id]) )
+ $wp_settings_sections[$page][$id] = array();
+
+ $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
+}
+
+/**
+ * Add a new field to a settings page
+ *
+ * @since 2.7
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the field
+ * @param string $callback Function that fills the field with the desired content. The function should echo its output.
+ * @param string $page The type of settings page on which to show the field (general, reading, writing, ...)
+ * @param string $section The section of the settingss page in which to show the box (default, ...)
+ * @param array $args Additional arguments
+ */
+function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
+ global $wp_settings_fields;
+
+ if ( !isset($wp_settings_fields) )
+ $wp_settings_fields = array();
+ if ( !isset($wp_settings_fields[$page]) )
+ $wp_settings_fields[$page] = array();
+ if ( !isset($wp_settings_fields[$page][$section]) )
+ $wp_settings_fields[$page][$section] = array();
+
+ $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
+}
+
+function do_settings_sections($page) {
+ global $wp_settings_sections, $wp_settings_fields;
+
+ if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
+ return;
+
+ foreach ( (array) $wp_settings_sections[$page] as $section ) {
+ echo "