$template";
- endforeach;
+ foreach ( array_keys( $templates ) as $template ) {
+ $selected = selected( $default, $templates[ $template ], false );
+ echo "\n\t";
+ }
}
+/**
+ * Print out option HTML elements for the page parents drop-down.
+ *
+ * @since 1.5.0
+ *
+ * @global wpdb $wpdb
+ *
+ * @param int $default Optional. The default page ID to be pre-selected. Default 0.
+ * @param int $parent Optional. The parent page ID. Default 0.
+ * @param int $level Optional. Page depth level. Default 0.
+ *
+ * @return null|false Boolean False if page has no children, otherwise print out html elements
+ */
function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
- global $wpdb, $post_ID;
+ global $wpdb;
+ $post = get_post();
$items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
if ( $items ) {
foreach ( $items as $item ) {
// A page cannot be its own parent.
- if (!empty ( $post_ID ) ) {
- if ( $item->ID == $post_ID ) {
- continue;
- }
- }
+ if ( $post && $post->ID && $item->ID == $post->ID )
+ continue;
+
$pad = str_repeat( ' ', $level * 3 );
- if ( $item->ID == $default)
- $current = ' selected="selected"';
- else
- $current = '';
+ $selected = selected( $default, $item->ID, false );
- echo "\n\t";
+ echo "\n\t";
parent_dropdown( $default, $item->ID, $level +1 );
}
} else {
@@ -1027,215 +879,250 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
}
}
-function browse_happy() {
- $getit = __( 'WordPress recommends a better browser' );
- echo '
-
- ';
-}
-
-if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
- add_action( 'in_admin_footer', 'browse_happy' );
-
-function the_attachment_links( $id = false ) {
- $id = (int) $id;
- $post = & get_post( $id );
-
- if ( $post->post_type != 'attachment' )
- return false;
+/**
+ * Print out option html elements for role selectors.
+ *
+ * @since 2.1.0
+ *
+ * @param string $selected Slug for the role that should be already selected.
+ */
+function wp_dropdown_roles( $selected = '' ) {
+ $p = '';
+ $r = '';
- $icon = get_attachment_icon( $post->ID );
- $attachment_data = wp_get_attachment_metadata( $id );
- $thumb = isset( $attachment_data['thumb'] );
-?>
-
-role_names as $role => $name ) {
- $name = translate_with_context($name);
- if ( $default == $role ) // Make default first in list
- $p = "\n\t";
+ foreach ( $editable_roles as $role => $details ) {
+ $name = translate_user_role($details['name'] );
+ if ( $selected == $role ) // preselect specified role
+ $p = "\n\t";
else
- $r .= "\n\t";
+ $r .= "\n\t";
}
echo $p . $r;
}
-function wp_convert_hr_to_bytes( $size ) {
- $size = strtolower($size);
- $bytes = (int) $size;
- if ( strpos($size, 'k') !== false )
- $bytes = intval($size) * 1024;
- elseif ( strpos($size, 'm') !== false )
- $bytes = intval($size) * 1024 * 1024;
- elseif ( strpos($size, 'g') !== false )
- $bytes = intval($size) * 1024 * 1024 * 1024;
- return $bytes;
-}
-
-function wp_convert_bytes_to_hr( $bytes ) {
- $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
- $log = log( $bytes, 1024 );
- $power = (int) $log;
- $size = pow(1024, $log - $power);
- return $size . $units[$power];
-}
-
-function wp_max_upload_size() {
- $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
- $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
- $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
- return $bytes;
-}
-
+/**
+ * Outputs the form used by the importers to accept the data to be imported
+ *
+ * @since 2.0.0
+ *
+ * @param string $action The action attribute for the form.
+ */
function wp_import_upload_form( $action ) {
+
+ /**
+ * Filter the maximum allowed upload size for import files.
+ *
+ * @since 2.3.0
+ *
+ * @see wp_max_upload_size()
+ *
+ * @param int $max_upload_size Allowed upload size. Default 1 MB.
+ */
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
- $size = wp_convert_bytes_to_hr( $bytes );
+ $size = size_format( $bytes );
+ $upload_dir = wp_upload_dir();
+ if ( ! empty( $upload_dir['error'] ) ) :
+ ?>
+
-
post_name); // just in case
- if ( strlen($name) )
- echo '';
+ endif;
}
/**
- * add_meta_box() - Add a meta box to an edit form
+ * Add a meta box to an edit form.
+ *
+ * @since 2.5.0
*
- * @since 2.5
+ * @global array $wp_meta_boxes
*
- * @param string $id String for use in the 'id' attribute of tags.
- * @param string $title Title of the meta box
- * @param string $callback Function that fills the box with the desired content. The function should echo its output.
- * @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')
- * @param string $priority The priority within the context where the boxes should show ('high', 'low')
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the meta box.
+ * @param callback $callback Function that fills the box with the desired content.
+ * The function should echo its output.
+ * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
+ * type, 'link', or 'comment'). Default is the current screen.
+ * @param string $context Optional. The context within the screen where the boxes
+ * should display. Available contexts vary from screen to
+ * screen. Post edit screen contexts include 'normal', 'side',
+ * and 'advanced'. Comments screen contexts include 'normal'
+ * and 'side'. Menus meta boxes (accordion sections) all use
+ * the 'side' context. Global default is 'advanced'.
+ * @param string $priority Optional. The priority within the context where the boxes
+ * should show ('high', 'low'). Default 'default'.
+ * @param array $callback_args Optional. Data that should be set as the $args property
+ * of the box array (which is the second parameter passed
+ * to your callback). Default null.
*/
-function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') {
+function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
global $wp_meta_boxes;
-
- if ( !isset($wp_meta_boxes) )
+ if ( empty( $screen ) )
+ $screen = get_current_screen();
+ elseif ( is_string( $screen ) )
+ $screen = convert_to_screen( $screen );
+
+ $page = $screen->id;
+
+ 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 $a_priority ) {
- if ( !isset($wp_meta_boxes[$page][$context][$a_priority][$id]) )
- continue;
- // If a core box was previously added or removed by a plugin, don't add.
- if ( 'core' == $priority ) {
- // If core box previously deleted, don't add
- if ( false === $wp_meta_boxes[$page][$context][$a_priority][$id] )
+ foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
+ foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
+ if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
+ continue;
+
+ // If a core box was previously added or removed by a plugin, don't add.
+ if ( 'core' == $priority ) {
+ // If core box previously deleted, don't add
+ if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
+ return;
+
+ /*
+ * If box was added with default priority, give it core priority to
+ * maintain sort order.
+ */
+ if ( 'default' == $a_priority ) {
+ $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
+ unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
+ }
return;
- // If box was added with default priority, give it core priority to maintain sort order
- if ( 'default' == $a_priority ) {
- $wp_meta_boxes[$page][$context]['core'][$id] = $wp_meta_boxes[$page][$context]['default'][$id];
- unset($wp_meta_boxes[$page][$context]['default'][$id]);
}
- return;
+ // If no priority given and id already present, use existing priority.
+ if ( empty($priority) ) {
+ $priority = $a_priority;
+ /*
+ * Else, if we're adding to the sorted priority, we don't know the title
+ * or callback. Grab them from the previously added context/priority.
+ */
+ } elseif ( 'sorted' == $priority ) {
+ $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
+ $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
+ $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
+ }
+ // An id can be in only one priority and one context.
+ if ( $priority != $a_priority || $context != $a_context )
+ unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
}
- // If no priority given and id already present, use existing priority
- if ( empty($priority) )
- $priority = $a_priority;
- // An id can be in only one priority
- if ( $priority != $a_priority )
- unset($wp_meta_boxes[$page][$context][$a_priority][$id]);
}
if ( empty($priority) )
- $priority = low;
+ $priority = 'low';
if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
$wp_meta_boxes[$page][$context][$priority] = array();
- $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
+ $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
}
-function do_meta_boxes($page, $context, $object) {
+/**
+ * Meta-Box template function
+ *
+ * @since 2.5.0
+ *
+ * @global array $wp_meta_boxes
+ *
+ * @staticvar bool $already_sorted
+ * @param string|WP_Screen $screen Screen identifier
+ * @param string $context box context
+ * @param mixed $object gets passed to the box callback function as first parameter
+ * @return int number of meta_boxes
+ */
+function do_meta_boxes( $screen, $context, $object ) {
global $wp_meta_boxes;
+ static $already_sorted = false;
- do_action('do_meta_boxes', $page, $context, $object);
+ if ( empty( $screen ) )
+ $screen = get_current_screen();
+ elseif ( is_string( $screen ) )
+ $screen = convert_to_screen( $screen );
- if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
- return;
+ $page = $screen->id;
- foreach ( array('high', 'core', 'default', 'low') as $priority ) {
- foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
- if ( false === $box )
- continue;
- echo '
";
+
+ return $i;
+
}
/**
- * remove_meta_box() - Remove a meta box from an edit form
+ * Remove a meta box from an edit form.
+ *
+ * @since 2.6.0
*
- * @since 2.6
+ * @global array $wp_meta_boxes
*
- * @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')
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string|object $screen The screen 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) {
+function remove_meta_box($id, $screen, $context) {
global $wp_meta_boxes;
- if ( !isset($wp_meta_boxes) )
+ if ( empty( $screen ) )
+ $screen = get_current_screen();
+ elseif ( is_string( $screen ) )
+ $screen = convert_to_screen( $screen );
+
+ $page = $screen->id;
+
+ if ( !isset($wp_meta_boxes) )
$wp_meta_boxes = array();
if ( !isset($wp_meta_boxes[$page]) )
$wp_meta_boxes[$page] = array();
@@ -1246,4 +1133,1124 @@ function remove_meta_box($id, $page, $context) {
$wp_meta_boxes[$page][$context][$priority][$id] = false;
}
-?>
+/**
+ * Meta Box Accordion Template Function
+ *
+ * Largely made up of abstracted code from {@link do_meta_boxes()}, this
+ * function serves to build meta boxes as list items for display as
+ * a collapsible accordion.
+ *
+ * @since 3.6.0
+ *
+ * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
+ *
+ * @param string|object $screen The screen identifier.
+ * @param string $context The meta box context.
+ * @param mixed $object gets passed to the section callback function as first parameter.
+ * @return int number of meta boxes as accordion sections.
+ */
+function do_accordion_sections( $screen, $context, $object ) {
+ global $wp_meta_boxes;
+
+ wp_enqueue_script( 'accordion' );
+
+ if ( empty( $screen ) )
+ $screen = get_current_screen();
+ elseif ( is_string( $screen ) )
+ $screen = convert_to_screen( $screen );
+
+ $page = $screen->id;
+
+ $hidden = get_hidden_meta_boxes( $screen );
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $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 retrieve existing
+ * values to show.
+ *
+ * @since 2.7.0
+ * @since 4.2.0 The `$class` argument was added.
+ *
+ * @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 Optional. The slug-name of the section of the settings page
+ * in which to show the box. Default 'default'.
+ * @param array $args {
+ * Optional. Extra arguments used when outputting the field.
+ *
+ * @type string $label_for When supplied, the setting title will be wrapped
+ * in a `` element, its `for` attribute populated
+ * with this value.
+ * @type string $class CSS Class to be added to the `
` element when the
+ * field is output.
+ * }
+ */
+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 ( 'privacy' == $page ) {
+ _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
+ $page = 'reading';
+ }
+
+ $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 2.7.0
+ *
+ * @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[$page] ) )
+ return;
+
+ foreach ( (array) $wp_settings_sections[$page] as $section ) {
+ if ( $section['title'] )
+ 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 2.7.0
+ *
+ * @param string $page Slug title of the admin page who's settings fields you want to show.
+ * @param string $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[$page][$section] ) )
+ return;
+
+ foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
+ $class = '';
+
+ if ( ! empty( $field['args']['class'] ) ) {
+ $class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
+ }
+
+ 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.
+ *
+ * @since 3.0.0
+ *
+ * @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 `
` tags).
+ * @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
+ * Default 'error'.
+ */
+function add_settings_error( $setting, $code, $message, $type = 'error' ) {
+ global $wp_settings_errors;
+
+ $wp_settings_errors[] = array(
+ 'setting' => $setting,
+ 'code' => $code,
+ 'message' => $message,
+ 'type' => $type
+ );
+}
+
+/**
+ * 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['settings-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)
+ *
+ * @since 3.0.0
+ *
+ * @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 sanitization 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.
+ if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
+ $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
+ delete_transient( 'settings_errors' );
+ }
+
+ // Check global in case errors have been added on this pageload.
+ if ( ! count( $wp_settings_errors ) )
+ return array();
+
+ // Filter the results to those of a specific setting if one was set.
+ if ( $setting ) {
+ $setting_errors = array();
+ foreach ( (array) $wp_settings_errors as $key => $details ) {
+ if ( $setting == $details['setting'] )
+ $setting_errors[] = $wp_settings_errors[$key];
+ }
+ return $setting_errors;
+ }
+
+ return $wp_settings_errors;
+}
+
+/**
+ * Display settings errors registered by {@see add_settings_error()}.
+ *
+ * Part of the Settings API. Outputs a div for each error retrieved by
+ * {@see 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 {@see register_setting()}
+ *
+ * The $sanitize option is passed into {@see 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.
+ *
+ * @since 3.0.0
+ *
+ * @param string $setting Optional slug title of a specific setting who's errors you want.
+ * @param bool $sanitize Whether to re-sanitize the setting value before returning errors.
+ * @param bool $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
+ */
+function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
+
+ if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
+ return;
+
+ $settings_errors = get_settings_errors( $setting, $sanitize );
+
+ if ( empty( $settings_errors ) )
+ return;
+
+ $output = '';
+ foreach ( $settings_errors as $key => $details ) {
+ $css_id = 'setting-error-' . $details['code'];
+ $css_class = $details['type'] . ' settings-error notice is-dismissible';
+ $output .= "