";
+
+ return $i;
+
+}
+
+/**
+ * Remove a meta box from an edit form.
+ *
+ * @since 2.6.0
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $page The type of edit page on which to show the box (post, page, link).
+ * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
+ */
+function remove_meta_box($id, $page, $context) {
+ global $wp_meta_boxes;
+
+ if ( !isset($wp_meta_boxes) )
+ $wp_meta_boxes = array();
+ if ( !isset($wp_meta_boxes[$page]) )
+ $wp_meta_boxes[$page] = array();
+ if ( !isset($wp_meta_boxes[$page][$context]) )
+ $wp_meta_boxes[$page][$context] = array();
+
+ foreach ( array('high', 'core', 'default', 'low') as $priority )
+ $wp_meta_boxes[$page][$context][$priority][$id] = false;
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since unknown
+ *
+ * @param unknown_type $screen
+ */
+function meta_box_prefs($screen) {
+ global $wp_meta_boxes;
+
+ if ( is_string($screen) )
+ $screen = convert_to_screen($screen);
+
+ if ( empty($wp_meta_boxes[$screen->id]) )
+ return;
+
+ $hidden = get_hidden_meta_boxes($screen);
+
+ foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
+ foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
+ foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
+ if ( false == $box || ! $box['title'] )
+ continue;
+ // Submit box cannot be hidden
+ if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
+ continue;
+ $box_id = $box['id'];
+ echo '';
+ echo '';
+ echo "{$box['title']}\n";
+ }
+ }
+ }
+}
+
+/**
+ * Get Hidden Meta Boxes
+ *
+ * @since 2.7
+ *
+ * @param string|object $screen Screen identifier
+ * @return array Hidden Meta Boxes
+ */
+function get_hidden_meta_boxes( $screen ) {
+ if ( is_string( $screen ) )
+ $screen = convert_to_screen( $screen );
+
+ $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
+
+ // Hide slug boxes by default
+ if ( !is_array( $hidden ) )
+ $hidden = array('slugdiv');
+
+ return $hidden;
+}
+
+/**
+ * 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', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
+ $page = 'general';
+ }
+
+ 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 section of a settings page
+ *
+ * Part of the Settings API. Use this to define a settings field that will show
+ * as part of a settings section inside a settings page. The fields are shown using
+ * do_settings_fields() in do_settings-sections()
+ *
+ * The $callback argument should be the name of a function that echoes out the
+ * html input tags for this setting field. Use get_option() to retrive existing
+ * values to show.
+ *
+ * @since 2.7.0
+ *
+ * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
+ *
+ * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
+ * @param string $title Formatted title of the field. Shown as the label for the field during output.
+ * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
+ * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
+ * @param string $section The slug-name of 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 ( 'misc' == $page ) {
+ _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
+ $page = 'general';
+ }
+
+ 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);
+}
+
+/**
+ * Prints out all settings sections added to a particular settings page
+ *
+ * Part of the Settings API. Use this in a settings page callback function
+ * to output all the sections and fields that were added to that $page with
+ * add_settings_section() and add_settings_field()
+ *
+ * @global $wp_settings_sections Storage array of all settings sections added to admin pages
+ * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
+ * @since unknown
+ *
+ * @param string $page The slug name of the page whos settings sections you want to output
+ */
+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 "
';
+ }
+}
+
+/**
+ * Print out the settings fields for a particular settings section
+ *
+ * Part of the Settings API. Use this in a settings page to output
+ * a specific section. Should normally be called by do_settings_sections()
+ * rather than directly.
+ *
+ * @global $wp_settings_fields Storage array of settings fields and their pages/sections
+ *
+ * @since unknown
+ *
+ * @param string $page Slug title of the admin page who's settings fields you want to show.
+ * @param section $section Slug title of the settings section who's fields you want to show.
+ */
+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 '
';
+ if ( !empty($field['args']['label_for']) )
+ echo '
';
+ }
+}
+
+/**
+ * Register a settings error to be displayed to the user
+ *
+ * Part of the Settings API. Use this to show messages to users about settings validation
+ * problems, missing settings or anything else.
+ *
+ * Settings errors should be added inside the $sanitize_callback function defined in
+ * register_setting() for a given setting to give feedback about the submission.
+ *
+ * By default messages will show immediately after the submission that generated the error.
+ * Additional calls to settings_errors() can be used to show errors even when the settings
+ * page is first accessed.
+ *
+ * @global array $wp_settings_errors Storage array of errors registered during this pageload
+ *
+ * @param string $setting Slug title of the setting to which this error applies
+ * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
+ * @param string $message The formatted message text to display to the user (will be shown inside styled
and
)
+ * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
+ */
+function add_settings_error( $setting, $code, $message, $type = 'error' ) {
+ global $wp_settings_errors;
+
+ if ( !isset($wp_settings_errors) )
+ $wp_settings_errors = array();
+
+ $new_error = array(
+ 'setting' => $setting,
+ 'code' => $code,
+ 'message' => $message,
+ 'type' => $type
+ );
+ $wp_settings_errors[] = $new_error;
+}
+
+/**
+ * Fetch settings errors registered by add_settings_error()
+ *
+ * Checks the $wp_settings_errors array for any errors declared during the current
+ * pageload and returns them.
+ *
+ * If changes were just submitted ($_GET['updated']) and settings errors were saved
+ * to the 'settings_errors' transient then those errors will be returned instead. This
+ * is used to pass errors back across pageloads.
+ *
+ * Use the $sanitize argument to manually re-sanitize the option before returning errors.
+ * This is useful if you have errors or notices you want to show even when the user
+ * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
+ *
+ * @global array $wp_settings_errors Storage array of errors registered during this pageload
+ *
+ * @param string $setting Optional slug title of a specific setting who's errors you want.
+ * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
+ * @return array Array of settings errors
+ */
+function get_settings_errors( $setting = '', $sanitize = FALSE ) {
+ global $wp_settings_errors;
+
+ // If $sanitize is true, manually re-run the sanitizisation for this option
+ // This allows the $sanitize_callback from register_setting() to run, adding
+ // any settings errors you want to show by default.
+ if ( $sanitize )
+ sanitize_option( $setting, get_option($setting));
+
+ // If settings were passed back from options.php then use them
+ // Ignore transients if $sanitize is true, we dont' want the old values anyway
+ if ( isset($_GET['updated']) && $_GET['updated'] && get_transient('settings_errors') ) {
+ $settings_errors = get_transient('settings_errors');
+ delete_transient('settings_errors');
+ // Otherwise check global in case validation has been run on this pageload
+ } elseif ( count( $wp_settings_errors ) ) {
+ $settings_errors = $wp_settings_errors;
+ } else {
+ return;
+ }
+
+ // Filter the results to those of a specific setting if one was set
+ if ( $setting ) {
+ foreach ( (array) $settings_errors as $key => $details )
+ if ( $setting != $details['setting'] )
+ unset( $settings_errors[$key] );
+ }
+ return $settings_errors;
+}
+
+/**
+ * Display settings errors registered by add_settings_error()
+ *
+ * Part of the Settings API. Outputs a
for each error retrieved by get_settings_errors().
+ *
+ * This is called automatically after a settings page based on the Settings API is submitted.
+ * Errors should be added during the validation callback function for a setting defined in register_setting()
+ *
+ * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
+ * on its current value.
+ *
+ * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
+ * if the user has already saved new values it will be hidden to avoid repeating messages already
+ * shown in the default error reporting after submission. This is useful to show general errors like missing
+ * settings when the user arrives at the settings page.
+ *
+ * @param string $setting Optional slug title of a specific setting who's errors you want.
+ * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
+ * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
+ * @return
+ */
+function settings_errors ( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
+
+ if ($hide_on_update AND $_GET['updated']) return;
+
+ $settings_errors = get_settings_errors( $setting, $sanitize );
+
+ if ( !is_array($settings_errors) ) return;
+
+ $output = '';
+ foreach ( $settings_errors as $key => $details ) {
+ $css_id = 'setting-error-' . $details['code'];
+ $css_class = $details['type'] . ' settings-error';
+ $output .= "
post_name); // just in case
- if ( strlen($name) )
- echo '';
+/**
+ * Add contextual help text for a page
+ *
+ * @since 2.7.0
+ *
+ * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
+ * @param string $help Arbitrary help text
+ */
+function add_contextual_help($screen, $help) {
+ global $_wp_contextual_help;
+
+ if ( is_string($screen) )
+ $screen = convert_to_screen($screen);
+
+ if ( !isset($_wp_contextual_help) )
+ $_wp_contextual_help = array();
+
+ $_wp_contextual_help[$screen->id] = $help;
+}
+
+function drag_drop_help() {
+ return '
+
' . __('Most of the modules on this screen can be moved. If you hover your mouse over the title bar of a module you’ll notice the 4 arrow cursor appears to let you know it is movable. Click on it, hold down the mouse button and start dragging the module to a new location. As you drag the module, notice the dotted gray box that also moves. This box indicates where the module will be placed when you release the mouse button.') . '
+
' . __('The same modules can be expanded and collapsed by clicking once on their title bar and also completely hidden from the Screen Options tab.') . '
' . __('You may search based on 3 criteria:') . ' ' .
+ __('Term: Searches theme names and descriptions for the specified term.') . ' ' .
+ __('Tag: Searches for themes tagged as such.') . ' ' .
+ __('Author: Searches for themes created by the Author, or which the Author contributed to.') . '