Index: wp-admin/includes/template.php
===================================================================
--- wp-admin/includes/template.php (revision 20538)
+++ wp-admin/includes/template.php (working copy)
@@ -1596,20 +1596,23 @@
*
* @since 3.1.0
*
+ * Optional $attributes contents:
+ *
+ * - type - The type of button. One of: primary, secondary, delete. Defaults to primary
+ * - name - The HTML name of the submit button. Defaults to "submit". If no id attribute
+ * is given, this parameter will be used as the button's id.
+ * - wrap - True if the output button should be wrapped in a paragraph tag,
+ * false otherwise. Defaults to true
+ *
+ * Any other attribute name/value pairs can be passed to the $attributes argument and they
+ * will be applied to the button.
+ *
* @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.
+ * @param array $attributes Attributes that should be output with the button,
+ * mapping attributes to their values. See above for description.
*/
-function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
- echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
+function submit_button( $text = null, $attributes = array() ) {
+ echo call_user_func_array( 'get_submit_button', func_get_args() );
}
/**
@@ -1617,54 +1620,96 @@
*
* @since 3.1.0
*
+ * Optional $attributes contents:
+ *
+ * - type - The type of button. One of: primary, secondary, delete. Defaults to primary
+ * - name - The HTML name of the submit button. Defaults to "submit". If no id attribute
+ * is given, this parameter will be used as the button's id.
+ * - wrap - True if the output button should be wrapped in a paragraph tag,
+ * false otherwise. Defaults to true
+ *
+ * Any other attribute name/value pairs can be passed to the $attributes argument and they
+ * will be applied to the button.
+ *
* @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.
+ * @param array $attributes Attributes that should be output with the button,
+ * mapping attributes to their values. See above for description.
*/
-function get_submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
- switch ( $type ) :
+function get_submit_button( $text = null, $attributes = array() ) {
+
+ if ( count( ( $args = func_get_args() ) > 2 ) ) {
+
+ _deprecated_argument( __FUNCTION__, 3.4, __( 'Button attributes should be passed to the $attributes
argument as an associative array.' ) );
+
+ $attributes = array(
+ 'type' => $attributes
+ );
+
+ if ( isset( $args[2] ) )
+ $attributes['name'] = $args[2];
+ if ( isset( $args[3] ) )
+ $attributes['wrap'] = $args[3];
+
+ if ( isset( $args[4] ) ) {
+ if ( is_array( $args[4] ) ) {
+ $attributes = wp_parse_args( $args[4], $attributes );
+ } else {
+ $_atts = array();
+ wp_parse_str( $args[4], $_atts ); // Other attributes provided as a string
+ $attributes = wp_parse_args( $_atts, $attributes );
+ }
+ }
+
+ } else if ( !is_array( $attributes ) ) {
+
+ _doing_it_wrong( __FUNCTION__, __( 'Button attributes should be passed to the $attributes
argument as an associative array.' ), 3.4 );
+
+ $attributes = array(
+ 'type' => $attributes
+ );
+
+ }
+
+ $attributes = wp_parse_args( $attributes, array(
+ 'type' => 'primary',
+ 'wrap' => true,
+ 'name' => 'submit',
+ 'value' => ( null == $text ) ? __( 'Save Changes' ) : $text
+ ) );
+
+ switch ( $attributes['type'] ) :
case 'primary' :
case 'secondary' :
- $class = 'button-' . $type;
+ $class = 'button-' . $attributes['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
+ $class = $attributes['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'] );
- }
+ if ( !isset( $attributes['id'] ) )
+ $attributes['id'] = $attributes['name'];
- $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;
- }
+ if ( !isset( $attributes['class'] ) )
+ $attributes['class'] = $class;
- $button = '';
+ $atts = '';
+ $wrap = $attributes['wrap'];
- if ( $wrap ) {
+ unset(
+ $attributes['type'],
+ $attributes['wrap']
+ );
+
+ foreach ( $attributes as $attribute => $value )
+ $atts .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
+
+ $button = '';
+
+ if ( $wrap )
$button = '
' . $button . '
'; - } return $button; }