+
|
@@ -2473,7 +573,7 @@ function meta_form() {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 0.71
*
* @param unknown_type $edit
* @param unknown_type $for_post
@@ -2547,7 +647,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 1.5.0
*
* @param unknown_type $default
*/
@@ -2566,7 +666,7 @@ function page_template_dropdown( $default = '' ) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 1.5.0
*
* @param unknown_type $default
* @param unknown_type $parent
@@ -2602,7 +702,7 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.0.0
*
* @param unknown_type $id
* @return unknown
@@ -2624,7 +724,7 @@ function the_attachment_links( $id = false ) {
|
- |
+ |
@@ -2652,14 +752,11 @@ function the_attachment_links( $id = false ) {
/**
- * Print out ";
else
$r .= "\n\t";
@@ -2680,7 +777,7 @@ function wp_dropdown_roles( $selected = false ) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.3.0
*
* @param unknown_type $size
* @return unknown
@@ -2700,7 +797,7 @@ function wp_convert_hr_to_bytes( $size ) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.3.0
*
* @param unknown_type $bytes
* @return unknown
@@ -2716,7 +813,7 @@ function wp_convert_bytes_to_hr( $bytes ) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.5.0
*
* @return unknown
*/
@@ -2730,7 +827,7 @@ function wp_max_upload_size() {
/**
* Outputs the form used by the importers to accept the data to be imported
*
- * @since 2.0
+ * @since 2.0.0
*
* @param string $action The action attribute for the form.
*/
@@ -2750,9 +847,7 @@ function wp_import_upload_form( $action ) {
-
-
-
+
' . "\n";
- echo '
';
+ echo '
';
echo "{$box['title']}\n";
echo '' . "\n";
call_user_func($box['callback'], $object, $box);
@@ -2905,7 +1000,7 @@ function remove_meta_box($id, $page, $context) {
/**
* {@internal Missing Short Description}}
*
- * @since unknown
+ * @since 2.7.0
*
* @param unknown_type $screen
*/
@@ -2940,7 +1035,7 @@ function meta_box_prefs($screen) {
/**
* Get Hidden Meta Boxes
*
- * @since 2.7
+ * @since 2.7.0
*
* @param string|object $screen Screen identifier
* @return array Hidden Meta Boxes
@@ -2952,8 +1047,13 @@ function get_hidden_meta_boxes( $screen ) {
$hidden = get_user_option( "metaboxhidden_{$screen->id}" );
// Hide slug boxes by default
- if ( !is_array( $hidden ) )
- $hidden = array('slugdiv');
+ if ( !is_array( $hidden ) ) {
+ if ( 'post' == $screen->base || 'page' == $screen->base )
+ $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
+ else
+ $hidden = array( 'slugdiv' );
+ $hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
+ }
return $hidden;
}
@@ -3045,7 +1145,7 @@ function add_settings_field($id, $title, $callback, $page, $section = 'default',
*
* @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
+ * @since 2.7.0
*
* @param string $page The slug name of the page whos settings sections you want to output
*/
@@ -3075,7 +1175,7 @@ function do_settings_sections($page) {
*
* @global $wp_settings_fields Storage array of settings fields and their pages/sections
*
- * @since unknown
+ * @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.
@@ -3112,6 +1212,8 @@ function do_settings_fields($page, $section) {
* 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
@@ -3140,7 +1242,7 @@ function add_settings_error( $setting, $code, $message, $type = '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
+ * 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.
*
@@ -3148,6 +1250,8 @@ function add_settings_error( $setting, $code, $message, $type = 'error' ) {
* 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.
@@ -3165,7 +1269,7 @@ function get_settings_errors( $setting = '', $sanitize = FALSE ) {
// 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') ) {
+ if ( isset($_GET['settings-updated']) && $_GET['settings-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
@@ -3200,14 +1304,15 @@ function get_settings_errors( $setting = '', $sanitize = FALSE ) {
* 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.
- * @return
*/
-function settings_errors ( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
+function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
- if ($hide_on_update AND $_GET['updated']) return;
+ if ($hide_on_update AND $_GET['settings-updated']) return;
$settings_errors = get_settings_errors( $setting, $sanitize );
@@ -3227,35 +1332,7 @@ function settings_errors ( $setting = '', $sanitize = FALSE, $hide_on_update = F
/**
* {@internal Missing Short Description}}
*
- * @since unknown
- *
- * @param unknown_type $page
- */
-function manage_columns_prefs( $page ) {
- $columns = get_column_headers( $page );
- $hidden = get_hidden_columns( $page );
- $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username');
-
- foreach ( $columns as $column => $title ) {
- // Can't hide these or they are special
- if ( in_array( $column, $special ) )
- continue;
- if ( empty( $title ) )
- continue;
-
- if ( 'comments' == $column )
- $title = __( 'Comments' );
- $id = "$column-hide";
- echo '\n";
- }
-}
-
-/**
- * {@internal Missing Short Description}}
- *
- * @since unknown
+ * @since 2.7.0
*
* @param unknown_type $found_action
*/
@@ -3273,7 +1350,7 @@ function find_posts_div($found_action = '') {
-
+
true), 'objects' );
@@ -3289,8 +1366,8 @@ function find_posts_div($found_action = '') {
-
-
+
+
is_user )
+ return;
+
if ( isset($screen->post_type) ) {
$post_type_object = get_post_type_object($screen->post_type);
if ( 'add' != $screen->action )
@@ -3330,58 +1410,69 @@ function favorite_actions( $screen = null ) {
}
if ( !$default_action ) {
- switch ( $screen->id ) {
- case 'upload':
- $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
- break;
- case 'media':
- $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
- break;
- case 'link-manager':
- case 'link':
- if ( 'add' != $screen->action )
- $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
- else
- $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
- break;
- case 'users':
- $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
- break;
- case 'user':
- $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
- break;
- case 'plugins':
- $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
- break;
- case 'plugin-install':
- $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
- break;
- case 'themes':
- $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
- break;
- case 'theme-install':
- $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
- break;
- default:
- $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
- break;
+ if ( $screen->is_network ) {
+ $default_action = array('sites.php' => array( __('Sites'), 'manage_sites'));
+ } else {
+ switch ( $screen->id ) {
+ case 'upload':
+ $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
+ break;
+ case 'media':
+ $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
+ break;
+ case 'link-manager':
+ case 'link':
+ if ( 'add' != $screen->action )
+ $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
+ else
+ $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
+ break;
+ case 'users':
+ $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
+ break;
+ case 'user':
+ $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
+ break;
+ case 'plugins':
+ $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
+ break;
+ case 'plugin-install':
+ $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
+ break;
+ case 'themes':
+ $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
+ break;
+ case 'theme-install':
+ $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
+ break;
+ default:
+ $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
+ break;
+ }
}
}
- $actions = array(
- 'post-new.php' => array(__('New Post'), 'edit_posts'),
- 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
- 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
- 'media-new.php' => array(__('Upload'), 'upload_files'),
- 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
+ if ( !$screen->is_network ) {
+ $actions = array(
+ 'post-new.php' => array(__('New Post'), 'edit_posts'),
+ 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
+ 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
+ 'media-new.php' => array(__('Upload'), 'upload_files'),
+ 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
+ );
+ } else {
+ $actions = array(
+ 'sites.php' => array( __('Sites'), 'manage_sites'),
+ 'users.php' => array( __('Users'), 'manage_network_users')
);
+ }
$default_key = array_keys($default_action);
$default_key = $default_key[0];
if ( isset($actions[$default_key]) )
unset($actions[$default_key]);
$actions = array_merge($default_action, $actions);
- $actions = apply_filters('favorite_actions', $actions);
+ $actions = apply_filters( 'favorite_actions', $actions, $screen );
$allowed_actions = array();
foreach ( $actions as $action => $data ) {
@@ -3415,10 +1506,10 @@ function favorite_actions( $screen = null ) {
* returned.
*
* @since 2.7.0
- * @param int $id The post id. If not supplied the global $post is used.
- *
+ * @param int $post_id The post id. If not supplied the global $post is used.
+ * @return string The post title if set
*/
-function _draft_or_post_title($post_id = 0) {
+function _draft_or_post_title( $post_id = 0 ) {
$title = get_the_title($post_id);
if ( empty($title) )
$title = __('(no title)');
@@ -3436,7 +1527,7 @@ function _draft_or_post_title($post_id = 0) {
*
*/
function _admin_search_query() {
- echo isset($_GET['s']) ? esc_attr( stripslashes( $_GET['s'] ) ) : '';
+ echo isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
}
/**
@@ -3448,7 +1539,11 @@ function _admin_search_query() {
*
*/
function iframe_header( $title = '', $limit_styles = false ) {
-global $hook_suffix;
+ show_admin_bar( false );
+ global $hook_suffix, $current_screen, $current_user, $admin_body_class, $wp_locale;
+ $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
+ $admin_body_class .= ' iframe';
+
?>
>
@@ -3464,14 +1559,28 @@ wp_enqueue_style( 'colors' );
//',
+ 'uid': 'ID; ?>',
+ 'time':''
+ },
+ ajaxurl = '',
+ pagenow = 'id; ?>',
+ typenow = 'post_type) ) echo $current_screen->post_type; ?>',
+ adminpage = '',
+ thousandsSeparator = 'number_format['thousands_sep'] ); ?>',
+ decimalPoint = 'number_format['decimal_point'] ); ?>',
+ isRtl = ;
//]]>
class="no-js ">
@@ -3537,6 +1646,9 @@ function _post_states($post) {
echo "$state$sep";
}
}
+
+ if ( get_post_format( $post->ID ) )
+ echo ' - ' . get_post_format_string( get_post_format( $post->ID ) ) . '';
}
/**
@@ -3548,19 +1660,27 @@ function _post_states($post) {
* @return object An object containing the safe screen name and id
*/
function convert_to_screen( $screen ) {
- $screen = str_replace( array('.php', '-new', '-add' ), '', $screen);
+ $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
+
+ if ( is_network_admin() )
+ $screen .= '-network';
+ elseif ( is_user_admin() )
+ $screen .= '-user';
+
$screen = (string) apply_filters( 'screen_meta_screen', $screen );
$screen = (object) array('id' => $screen, 'base' => $screen);
return $screen;
}
function screen_meta($screen) {
- global $wp_meta_boxes, $_wp_contextual_help, $title;
+ global $wp_meta_boxes, $_wp_contextual_help, $wp_list_table, $wp_current_screen_options;
if ( is_string($screen) )
$screen = convert_to_screen($screen);
- $column_screens = get_column_headers($screen);
+ $columns = get_column_headers( $screen );
+ $hidden = get_hidden_columns( $screen );
+
$meta_screens = array('index' => 'dashboard');
if ( isset($meta_screens[$screen->id]) ) {
@@ -3569,7 +1689,7 @@ function screen_meta($screen) {
}
$show_screen = false;
- if ( !empty($wp_meta_boxes[$screen->id]) || !empty($column_screens) )
+ if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) )
$show_screen = true;
$screen_options = screen_options($screen);
@@ -3587,8 +1707,12 @@ function screen_meta($screen) {
$show_screen = true;
break;
}
- if( ! empty( $settings ) )
+ if ( ! empty( $settings ) )
$show_screen = true;
+
+ if ( !empty($wp_current_screen_options) )
+ $show_screen = true;
+
?>
@@ -3601,10 +1725,27 @@ function screen_meta($screen) {
-
+ if ( ! empty($columns) ) : ?>
+
-
+ $title ) {
+ // Can't hide these for they are special
+ if ( in_array( $column, $special ) )
+ continue;
+ if ( empty( $title ) )
+ continue;
+
+ if ( 'comments' == $column )
+ $title = __( 'Comments' );
+ $id = "$column-hide";
+ echo '\n";
+ }
+?>
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.') . '
-';
-}
-
-function plugins_search_help() {
- return '
- ' . __('Search help') . ' ' .
- '' . __('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.') . '
-';
-}
-
function screen_layout($screen) {
- global $screen_layout_columns;
+ global $screen_layout_columns, $wp_current_screen_options;
if ( is_string($screen) )
$screen = convert_to_screen($screen);
- $columns = array('dashboard' => 4, 'link' => 2);
-
- // Add custom post types
- foreach ( get_post_types( array('show_ui' => true) ) as $post_type )
- $columns[$post_type] = 2;
-
- $columns = apply_filters('screen_layout_columns', $columns, $screen->id, $screen);
+ // Back compat for plugins using the filter instead of add_screen_option()
+ $columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen);
+ if ( !empty($columns) && isset($columns[$screen->id]) )
+ add_screen_option('layout_columns', array('max' => $columns[$screen->id]) );
- if ( !isset($columns[$screen->id]) ) {
+ if ( !isset($wp_current_screen_options['layout_columns']) ) {
$screen_layout_columns = 0;
return '';
- }
+ }
$screen_layout_columns = get_user_option("screen_layout_$screen->id");
- $num = $columns[$screen->id];
+ $num = $wp_current_screen_options['layout_columns']['max'];
- if ( ! $screen_layout_columns )
+ if ( ! $screen_layout_columns ) {
+ if ( isset($wp_current_screen_options['layout_columns']['default']) )
+ $screen_layout_columns = $wp_current_screen_options['layout_columns']['default'];
+ else
$screen_layout_columns = 2;
+ }
$i = 1;
$return = '' . __('Screen Layout') . "\n" . __('Number of Columns:') . "\n";
@@ -3730,54 +1855,45 @@ function screen_layout($screen) {
return $return;
}
+/**
+ * Register and configure an admin screen option
+ *
+ * @since 3.1.0
+ *
+ * @param string $option An option name.
+ * @param mixed $args Option dependent arguments
+ * @return void
+ */
+function add_screen_option( $option, $args = array() ) {
+ global $wp_current_screen_options;
+
+ if ( !isset($wp_current_screen_options) )
+ $wp_current_screen_options = array();
+
+ $wp_current_screen_options[$option] = $args;
+}
+
function screen_options($screen) {
+ global $wp_current_screen_options;
+
if ( is_string($screen) )
$screen = convert_to_screen($screen);
- switch ( $screen->base ) {
- case 'edit':
- case 'edit-pages':
- $post_type = 'post';
- if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) )
- $post_type = $_GET['post_type'];
- $post_type_object = get_post_type_object($post_type);
- $per_page_label = $post_type_object->labels->name;
- break;
- case 'ms-sites':
- $per_page_label = _x( 'Sites', 'sites per page (screen options)' );
- break;
- case 'ms-users':
- $per_page_label = _x( 'Users', 'users per page (screen options)' );
- break;
- case 'edit-comments':
- $per_page_label = _x( 'Comments', 'comments per page (screen options)' );
- break;
- case 'upload':
- $per_page_label = _x( 'Media items', 'items per page (screen options)' );
- break;
- case 'edit-tags':
- global $tax;
- $per_page_label = $tax->labels->name;
- break;
- case 'plugins':
- $per_page_label = _x( 'Plugins', 'plugins per page (screen options)' );
- break;
- default:
- return '';
- }
+ if ( !isset($wp_current_screen_options['per_page']) )
+ return '';
+
+ $per_page_label = $wp_current_screen_options['per_page']['label'];
- $option = str_replace( '-', '_', "{$screen->id}_per_page" );
- if ( 'edit_tags_per_page' == $option ) {
- if ( 'category' == $tax->name )
- $option = 'categories_per_page';
- elseif ( 'post_tag' != $tax->name )
- $option = 'edit_' . $tax->name . '_per_page';
+ if ( empty($wp_current_screen_options['per_page']['option']) ) {
+ $option = str_replace( '-', '_', "{$screen->id}_per_page" );
+ } else {
+ $option = $wp_current_screen_options['per_page']['option'];
}
$per_page = (int) get_user_option( $option );
if ( empty( $per_page ) || $per_page < 1 ) {
- if ( 'plugins' == $screen->id )
- $per_page = 999;
+ if ( isset($wp_current_screen_options['per_page']['default']) )
+ $per_page = $wp_current_screen_options['per_page']['default'];
else
$per_page = 20;
}
@@ -3789,23 +1905,29 @@ function screen_options($screen) {
else
$per_page = apply_filters( $option, $per_page );
+ // Back compat
+ if ( isset( $screen->post_type ) )
+ $per_page = apply_filters( 'edit_posts_per_page', $per_page, $screen->post_type );
+
$return = " \n";
if ( !empty($per_page_label) )
$return .= " \n";
- $return .= "";
+ $return .= get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false );
$return .= "";
$return .= " \n";
return $return;
}
function screen_icon($screen = '') {
- global $current_screen;
+ global $current_screen, $typenow;
if ( empty($screen) )
$screen = $current_screen;
elseif ( is_string($screen) )
$name = $screen;
+ $class = 'icon32';
+
if ( empty($name) ) {
if ( !empty($screen->parent_base) )
$name = $screen->parent_base;
@@ -3814,10 +1936,18 @@ function screen_icon($screen = '') {
if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
$name = 'edit-pages';
+
+ $post_type = '';
+ if ( isset( $screen->post_type ) )
+ $post_type = $screen->post_type;
+ elseif ( $current_screen == $screen )
+ $post_type = $typenow;
+ if ( $post_type )
+ $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
}
?>
-
+
taxonomy = $taxnow;
}
+ $current_screen->is_network = is_network_admin();
+ $current_screen->is_user = is_user_admin();
+
+ if ( $current_screen->is_network ) {
+ $current_screen->base .= '-network';
+ $current_screen->id .= '-network';
+ } elseif ( $current_screen->is_user ) {
+ $current_screen->base .= '-user';
+ $current_screen->id .= '-user';
+ }
+
$current_screen = apply_filters('current_screen', $current_screen);
}
-?>
+/**
+ * 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 ouput 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 ouput 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', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
+ switch ( $type ) :
+ case 'primary' :
+ case 'secondary' :
+ $class = 'button-' . $type;
+ break;
+ case 'delete' :
+ $class = 'button-secondary delete';
+ break;
+ default :
+ $class = $type; // Custom cases can just pass in the classes they want to be used
+ endswitch;
+ $text = ( NULL == $text ) ? __( 'Save Changes' ) : $text;
+
+ // 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 = ' ';
+
+ if ( $wrap ) {
+ $button = ' ' . $button . ' ';
+ }
+
+ return $button;
+}
+
|