mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
add_settings_section() and add_settings_field(). see #7682
git-svn-id: http://svn.automattic.com/wordpress/trunk@8855 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2c9f0abe4d
commit
54049c5f41
@ -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 "<h3>{$section['title']}</h3>\n";
|
||||
call_user_func($section['callback'], $section);
|
||||
if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
|
||||
continue;
|
||||
echo '<table class="form-table">';
|
||||
do_settings_fields($page, $section['id']);
|
||||
echo '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
function do_settings_fields($page, $section) {
|
||||
global $wp_settings_fields;
|
||||
|
||||
if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
|
||||
return;
|
||||
|
||||
foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
|
||||
echo '<tr valign="top">';
|
||||
if ( !empty($field['args']['label_for']) )
|
||||
echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
|
||||
else
|
||||
echo '<th scope="row">' . $field['title'] . '</th>';
|
||||
echo '<td>';
|
||||
call_user_func($field['callback']);
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -83,6 +83,7 @@ include('admin-header.php');
|
||||
</p>
|
||||
</fieldset></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('discussion', 'default'); ?>
|
||||
</table>
|
||||
|
||||
<h3><?php _e('Avatars') ?></h3>
|
||||
@ -154,9 +155,10 @@ echo apply_filters('default_avatar_select', $avatar_list);
|
||||
|
||||
</fieldset></td>
|
||||
</tr>
|
||||
|
||||
<?php do_settings_fields('discussion', 'avatars'); ?>
|
||||
</table>
|
||||
|
||||
<?php do_settings_sections('discussion'); ?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name="action" value="update" />
|
||||
|
@ -117,8 +117,11 @@ endfor;
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('general', 'default'); ?>
|
||||
</table>
|
||||
|
||||
<?php do_settings_sections('general'); ?>
|
||||
|
||||
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
|
||||
<input type="hidden" name="action" value="update" />
|
||||
</p>
|
||||
|
@ -45,6 +45,7 @@ include('admin-header.php');
|
||||
</label>
|
||||
</th>
|
||||
</tr>
|
||||
<?php do_settings_fields('misc', 'default'); ?>
|
||||
</table>
|
||||
|
||||
<h3><?php _e('Image sizes') ?></h3>
|
||||
@ -130,7 +131,7 @@ include('admin-header.php');
|
||||
?>
|
||||
</fieldset></td>
|
||||
</tr>
|
||||
|
||||
<?php do_settings_fields('misc', 'images'); ?>
|
||||
</table>
|
||||
|
||||
|
||||
@ -157,6 +158,8 @@ include('admin-header.php');
|
||||
|
||||
</table>
|
||||
|
||||
<?php do_settings_sections('misc'); ?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" class="button" />
|
||||
|
@ -191,7 +191,11 @@ $structures = array(
|
||||
<th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
|
||||
<td><input name="tag_base" id="tag_base" type="text" class="code" value="<?php echo attribute_escape($tag_base); ?>" size="30" /></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('permalink', 'optional'); ?>
|
||||
</table>
|
||||
|
||||
<?php do_settings_sections('permalink'); ?>
|
||||
|
||||
<p class="submit"><input type="submit" name="submit" class="button" value="<?php _e('Save Changes') ?>" /></p>
|
||||
</form>
|
||||
<?php if ( $permalink_structure && !$usingpi && !$writable ) : ?>
|
||||
|
@ -31,8 +31,11 @@ include('./admin-header.php');
|
||||
<?php do_action('blog_privacy_selector'); ?>
|
||||
</fieldset></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('privacy', 'default'); ?>
|
||||
</table>
|
||||
|
||||
<?php do_settings_sections('privacy'); ?>
|
||||
|
||||
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
|
||||
<input type="hidden" name="action" value="update" />
|
||||
</p>
|
||||
|
@ -72,6 +72,7 @@ include('admin-header.php');
|
||||
<td><input name="blog_charset" type="text" id="blog_charset" value="<?php form_option('blog_charset'); ?>" size="20" class="code" /><br />
|
||||
<?php _e('The character encoding you write your blog in (UTF-8 is <a href="http://developer.apple.com/documentation/macos8/TextIntlSvcs/TextEncodingConversionManager/TEC1.5/TEC.b0.html">recommended</a>)') ?></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('reading', 'default'); ?>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="hidden" name="action" value="update" />
|
||||
|
@ -63,6 +63,7 @@ endforeach;
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('writing', 'default'); ?>
|
||||
</table>
|
||||
|
||||
<h3><?php _e('Remote Publishing') ?></h3>
|
||||
@ -83,7 +84,9 @@ endforeach;
|
||||
<input name="enable_xmlrpc" type="checkbox" id="enable_xmlrpc" value="1" <?php checked('1', get_option('enable_xmlrpc')); ?> />
|
||||
<?php _e('Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.') ?></label><br />
|
||||
</fieldset></td>
|
||||
</tr></table>
|
||||
</tr>
|
||||
<?php do_settings_fields('writing', 'remote_publishing'); ?>
|
||||
</table>
|
||||
|
||||
<h3><?php _e('Post via e-mail') ?></h3>
|
||||
<p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it’s a good idea to keep this address very secret. Here are three random strings you could use: <code>%s</code>, <code>%s</code>, <code>%s</code>.'), wp_generate_password(8, false), wp_generate_password(8, false), wp_generate_password(8, false)) ?></p>
|
||||
@ -120,6 +123,7 @@ endforeach;
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
<?php do_settings_fields('writing', 'post_via_email'); ?>
|
||||
</table>
|
||||
|
||||
<h3><?php _e('Update Services') ?></h3>
|
||||
@ -136,6 +140,8 @@ endforeach;
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php do_settings_sections('writing'); ?>
|
||||
|
||||
<p class="submit">
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
|
||||
|
Loading…
Reference in New Issue
Block a user