+/**
+ * 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 );
+ ?>
+ <div id="side-sortables" class="accordion-container">
+ <ul class="outer-border">
+ <?php
+ $i = 0;
+ $first_open = false;
+ do {
+ if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
+ break;
+
+ foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
+ if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
+ foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
+ if ( false == $box || ! $box['title'] )
+ continue;
+ $i++;
+ $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
+
+ $open_class = '';
+ if ( ! $first_open && empty( $hidden_class ) ) {
+ $first_open = true;
+ $open_class = 'open';
+ }
+ ?>
+ <li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
+ <h3 class="accordion-section-title hndle" tabindex="0" title="<?php echo esc_attr( $box['title'] ); ?>"><?php echo esc_html( $box['title'] ); ?></h3>
+ <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
+ <div class="inside">
+ <?php call_user_func( $box['callback'], $object, $box ); ?>
+ </div><!-- .inside -->
+ </div><!-- .accordion-section-content -->
+ </li><!-- .accordion-section -->
+ <?php
+ }
+ }
+ }
+ } while(0);
+ ?>
+ </ul><!-- .outer-border -->
+ </div><!-- .accordion-container -->
+ <?php
+ return $i;
+}
+
+/**
+ * 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', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
+ $page = 'general';
+ }
+
+ if ( 'privacy' == $page ) {
+ _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
+ $page = 'reading';
+ }
+
+ 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 retrieve 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 settings 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 ( 'privacy' == $page ) {
+ _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
+ $page = 'reading';
+ }
+
+ 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 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 ) || !isset( $wp_settings_sections[$page] ) )
+ return;
+
+ foreach ( (array) $wp_settings_sections[$page] as $section ) {
+ if ( $section['title'] )
+ echo "<h3>{$section['title']}</h3>\n";
+
+ if ( $section['callback'] )
+ 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>';
+ }
+}
+
+/**
+ * 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 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 '<tr valign="top">';
+ if ( !empty($field['args']['label_for']) )
+ echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
+ else
+ echo '<th scope="row">' . $field['title'] . '</th>';
+ echo '<td>';
+ call_user_func($field['callback'], $field['args']);
+ echo '</td>';
+ echo '</tr>';
+ }
+}
+
+/**
+ * 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 <div> and <p>)
+ * @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['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 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
+ 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 add_settings_error()
+ *
+ * Part of the Settings API. Outputs a <div> 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.
+ *
+ * @since 3.0.0
+ *
+ * @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.
+ */
+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';
+ $output .= "<div id='$css_id' class='$css_class'> \n";
+ $output .= "<p><strong>{$details['message']}</strong></p>";
+ $output .= "</div> \n";
+ }
+ echo $output;
+}
+
+/**
+ * {@internal Missing Short Description}}
+ *
+ * @since 2.7.0
+ *
+ * @param unknown_type $found_action
+ */
+function find_posts_div($found_action = '') {
+?>
+ <div id="find-posts" class="find-box" style="display:none;">
+ <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
+ <div class="find-box-inside">
+ <div class="find-box-search">
+ <?php if ( $found_action ) { ?>
+ <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
+ <?php } ?>
+
+ <input type="hidden" name="affected" id="affected" value="" />
+ <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
+ <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
+ <input type="text" id="find-posts-input" name="ps" value="" />
+ <span class="spinner"></span>
+ <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
+ </div>
+ <div id="find-posts-response"></div>
+ </div>
+ <div class="find-box-buttons">
+ <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
+ <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
+ </div>
+ </div>
+<?php
+}
+
+/**
+ * Display the post password.
+ *
+ * The password is passed through {@link esc_attr()} to ensure that it
+ * is safe for placing in an html attribute.
+ *
+ * @uses attr
+ * @since 2.7.0
+ */
+function the_post_password() {
+ $post = get_post();
+ if ( isset( $post->post_password ) )
+ echo esc_attr( $post->post_password );
+}
+
+/**
+ * Get the post title.
+ *
+ * The post title is fetched and if it is blank then a default string is
+ * returned.
+ *
+ * @since 2.7.0
+ * @param mixed $post Post id or object. If not supplied the global $post is used.
+ * @return string The post title if set
+ */
+function _draft_or_post_title( $post = 0 ) {
+ $title = get_the_title( $post );
+ if ( empty( $title ) )
+ $title = __( '(no title)' );
+ return $title;
+}
+
+/**
+ * Display the search query.
+ *
+ * A simple wrapper to display the "s" parameter in a GET URI. This function
+ * should only be used when {@link the_search_query()} cannot.
+ *
+ * @uses attr
+ * @since 2.7.0
+ *
+ */
+function _admin_search_query() {
+ echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
+}
+
+/**
+ * Generic Iframe header for use with Thickbox
+ *
+ * @since 2.7.0
+ * @param string $title Title of the Iframe page.
+ * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
+ *
+ */
+function iframe_header( $title = '', $limit_styles = false ) {
+ show_admin_bar( false );
+ global $hook_suffix, $current_user, $admin_body_class, $wp_locale;
+ $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
+
+ $current_screen = get_current_screen();
+
+ @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
+ _wp_admin_html_begin();
+?>
+<title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title>
+<?php
+wp_enqueue_style( 'colors' );
+?>
+<script type="text/javascript">
+//<![CDATA[
+addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
+function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
+var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
+ pagenow = '<?php echo $current_screen->id; ?>',
+ typenow = '<?php echo $current_screen->post_type; ?>',
+ adminpage = '<?php echo $admin_body_class; ?>',
+ thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
+ decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
+ isRtl = <?php echo (int) is_rtl(); ?>;
+//]]>
+</script>
+<?php
+do_action('admin_enqueue_scripts', $hook_suffix);
+do_action("admin_print_styles-$hook_suffix");
+do_action('admin_print_styles');
+do_action("admin_print_scripts-$hook_suffix");
+do_action('admin_print_scripts');
+do_action("admin_head-$hook_suffix");
+do_action('admin_head');
+
+$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
+?>
+</head>
+<body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin wp-core-ui no-js iframe <?php echo apply_filters( 'admin_body_class', '' ) . ' ' . $admin_body_class; ?>">
+<script type="text/javascript">
+//<![CDATA[
+(function(){
+var c = document.body.className;
+c = c.replace(/no-js/, 'js');
+document.body.className = c;
+})();
+//]]>
+</script>
+<?php
+}
+
+/**
+ * Generic Iframe footer for use with Thickbox
+ *
+ * @since 2.7.0
+ *
+ */
+function iframe_footer() {
+ //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
+ <div class="hidden">
+<?php
+ do_action('admin_footer', '');
+ do_action('admin_print_footer_scripts'); ?>
+ </div>
+<script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
+</body>
+</html>
+<?php
+}
+
+function _post_states($post) {
+ $post_states = array();
+ if ( isset( $_REQUEST['post_status'] ) )
+ $post_status = $_REQUEST['post_status'];
+ else
+ $post_status = '';
+
+ if ( !empty($post->post_password) )
+ $post_states['protected'] = __('Password protected');
+ if ( 'private' == $post->post_status && 'private' != $post_status )
+ $post_states['private'] = __('Private');
+ if ( 'draft' == $post->post_status && 'draft' != $post_status )
+ $post_states['draft'] = __('Draft');
+ if ( 'pending' == $post->post_status && 'pending' != $post_status )
+ /* translators: post state */
+ $post_states['pending'] = _x('Pending', 'post state');
+ if ( is_sticky($post->ID) )
+ $post_states['sticky'] = __('Sticky');
+
+ $post_states = apply_filters( 'display_post_states', $post_states, $post );
+
+ if ( ! empty($post_states) ) {
+ $state_count = count($post_states);
+ $i = 0;
+ echo ' - ';
+ foreach ( $post_states as $state ) {
+ ++$i;
+ ( $i == $state_count ) ? $sep = '' : $sep = ', ';
+ echo "<span class='post-state'>$state$sep</span>";
+ }
+ }
+
+}
+
+function _media_states( $post ) {
+ $media_states = array();
+ $stylesheet = get_option('stylesheet');
+
+ if ( current_theme_supports( 'custom-header') ) {
+ $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
+ if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
+ $media_states[] = __( 'Header Image' );
+ }
+
+ if ( current_theme_supports( 'custom-background') ) {
+ $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
+ if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
+ $media_states[] = __( 'Background Image' );
+ }
+
+ $media_states = apply_filters( 'display_media_states', $media_states );
+
+ if ( ! empty( $media_states ) ) {
+ $state_count = count( $media_states );
+ $i = 0;
+ echo ' - ';
+ foreach ( $media_states as $state ) {
+ ++$i;
+ ( $i == $state_count ) ? $sep = '' : $sep = ', ';
+ echo "<span class='post-state'>$state$sep</span>";
+ }
+ }
+}
+
+/**
+ * Test support for compressing JavaScript from PHP
+ *
+ * Outputs JavaScript that tests if compression from PHP works as expected
+ * and sets an option with the result. Has no effect when the current user
+ * is not an administrator. To run the test again the option 'can_compress_scripts'
+ * has to be deleted.
+ *
+ * @since 2.8.0
+ */
+function compression_test() {
+?>
+ <script type="text/javascript">
+ /* <![CDATA[ */
+ var testCompression = {
+ get : function(test) {
+ var x;
+ if ( window.XMLHttpRequest ) {
+ x = new XMLHttpRequest();
+ } else {
+ try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
+ }
+
+ if (x) {
+ x.onreadystatechange = function() {
+ var r, h;
+ if ( x.readyState == 4 ) {
+ r = x.responseText.substr(0, 18);
+ h = x.getResponseHeader('Content-Encoding');
+ testCompression.check(r, h, test);
+ }
+ }
+
+ x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
+ x.send('');
+ }
+ },
+
+ check : function(r, h, test) {
+ if ( ! r && ! test )
+ this.get(1);
+
+ if ( 1 == test ) {
+ if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
+ this.get('no');
+ else
+ this.get(2);
+
+ return;
+ }
+
+ if ( 2 == test ) {
+ if ( '"wpCompressionTest' == r )
+ this.get('yes');
+ else
+ this.get('no');
+ }
+ }
+ };
+ testCompression.check();
+ /* ]]> */
+ </script>
+<?php
+}
+
+/**
+ * Echos a submit button, with provided text and appropriate class
+ *
+ * @since 3.1.0
+ *
+ * @param string $text The text of the button (defaults to 'Save Changes')
+ * @param string $type The type of button. One of: primary, secondary, delete
+ * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
+ * is given in $other_attributes below, $name will be used as the button's id.
+ * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
+ * false otherwise. Defaults to true
+ * @param array|string $other_attributes Other attributes that should be output with the button,
+ * mapping attributes to their values, such as array( 'tabindex' => '1' ).
+ * These attributes will be output as attribute="value", such as tabindex="1".
+ * Defaults to no other attributes. Other attributes can also be provided as a
+ * string such as 'tabindex="1"', though the array format is typically cleaner.
+ */
+function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
+ echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
+}
+
+/**
+ * Returns a submit button, with provided text and appropriate class
+ *
+ * @since 3.1.0
+ *
+ * @param string $text The text of the button (defaults to 'Save Changes')
+ * @param string $type The type of button. One of: primary, secondary, delete
+ * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
+ * is given in $other_attributes below, $name will be used as the button's id.
+ * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
+ * false otherwise. Defaults to true
+ * @param array|string $other_attributes Other attributes that should be output with the button,
+ * mapping attributes to their values, such as array( 'tabindex' => '1' ).
+ * These attributes will be output as attribute="value", such as tabindex="1".
+ * Defaults to no other attributes. Other attributes can also be provided as a
+ * string such as 'tabindex="1"', though the array format is typically cleaner.
+ */
+function get_submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) {
+ if ( ! is_array( $type ) )
+ $type = explode( ' ', $type );
+
+ $button_shorthand = array( 'primary', 'small', 'large' );
+ $classes = array( 'button' );
+ foreach ( $type as $t ) {
+ if ( 'secondary' === $t || 'button-secondary' === $t )
+ continue;
+ $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
+ }
+ $class = implode( ' ', array_unique( $classes ) );
+
+ if ( 'delete' === $type )
+ $class = 'button-secondary delete';
+
+ $text = $text ? $text : __( 'Save Changes' );
+
+ // Default the id attribute to $name unless an id was specifically provided in $other_attributes
+ $id = $name;
+ if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
+ $id = $other_attributes['id'];
+ unset( $other_attributes['id'] );
+ }
+
+ $attributes = '';
+ if ( is_array( $other_attributes ) ) {
+ foreach ( $other_attributes as $attribute => $value ) {
+ $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
+ }
+ } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
+ $attributes = $other_attributes;
+ }
+
+ $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
+ $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
+
+ if ( $wrap ) {
+ $button = '<p class="submit">' . $button . '</p>';
+ }
+
+ return $button;
+}
+
+function _wp_admin_html_begin() {
+ $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';