Make WordPress Core

Ticket #20492: 20492.patch

File 20492.patch, 7.1 KB (added by johnbillion, 14 years ago)
  • wp-admin/includes/template.php

     
    15961596 *
    15971597 * @since 3.1.0
    15981598 *
     1599 * Optional $attributes contents:
     1600 *
     1601 * - type - The type of button. One of: primary, secondary, delete. Defaults to primary
     1602 * - name - The HTML name of the submit button. Defaults to "submit". If no id attribute
     1603 *          is given, this parameter will be used as the button's id.
     1604 * - wrap - True if the output button should be wrapped in a paragraph tag,
     1605 *          false otherwise. Defaults to true
     1606 *
     1607 * Any other attribute name/value pairs can be passed to the $attributes argument and they
     1608 * will be applied to the button.
     1609 *
    15991610 * @param string $text The text of the button (defaults to 'Save Changes')
    1600  * @param string $type The type of button. One of: primary, secondary, delete
    1601  * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
    1602  *               is given in $other_attributes below, $name will be used as the button's id.
    1603  * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
    1604  *                         false otherwise. Defaults to true
    1605  * @param array|string $other_attributes Other attributes that should be output with the button,
    1606  *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
    1607  *                     These attributes will be output as attribute="value", such as tabindex="1".
    1608  *                     Defaults to no other attributes. Other attributes can also be provided as a
    1609  *                     string such as 'tabindex="1"', though the array format is typically cleaner.
     1611 * @param array $attributes Attributes that should be output with the button,
     1612 *              mapping attributes to their values. See above for description.
    16101613 */
    1611 function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
    1612         echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
     1614function submit_button( $text = null, $attributes = array() ) {
     1615        echo call_user_func_array( 'get_submit_button', func_get_args() );
    16131616}
    16141617
    16151618/**
     
    16171620 *
    16181621 * @since 3.1.0
    16191622 *
     1623 * Optional $attributes contents:
     1624 *
     1625 * - type - The type of button. One of: primary, secondary, delete. Defaults to primary
     1626 * - name - The HTML name of the submit button. Defaults to "submit". If no id attribute
     1627 *          is given, this parameter will be used as the button's id.
     1628 * - wrap - True if the output button should be wrapped in a paragraph tag,
     1629 *          false otherwise. Defaults to true
     1630 *
     1631 * Any other attribute name/value pairs can be passed to the $attributes argument and they
     1632 * will be applied to the button.
     1633 *
    16201634 * @param string $text The text of the button (defaults to 'Save Changes')
    1621  * @param string $type The type of button. One of: primary, secondary, delete
    1622  * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
    1623  *               is given in $other_attributes below, $name will be used as the button's id.
    1624  * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
    1625  *                         false otherwise. Defaults to true
    1626  * @param array|string $other_attributes Other attributes that should be output with the button,
    1627  *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
    1628  *                     These attributes will be output as attribute="value", such as tabindex="1".
    1629  *                     Defaults to no other attributes. Other attributes can also be provided as a
    1630  *                     string such as 'tabindex="1"', though the array format is typically cleaner.
     1635 * @param array $attributes Attributes that should be output with the button,
     1636 *              mapping attributes to their values. See above for description.
    16311637 */
    1632 function get_submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
    1633         switch ( $type ) :
     1638function get_submit_button( $text = null, $attributes = array() ) {
     1639
     1640        if ( count( ( $args = func_get_args() ) > 2 ) ) {
     1641
     1642                _deprecated_argument( __FUNCTION__, 3.4, __( 'Button attributes should be passed to the <code>$attributes</code> argument as an associative array.' ) );
     1643
     1644                $attributes = array(
     1645                        'type' => $attributes
     1646                );
     1647
     1648                if ( isset( $args[2] ) )
     1649                        $attributes['name'] = $args[2];
     1650                if ( isset( $args[3] ) )
     1651                        $attributes['wrap'] = $args[3];
     1652
     1653                if ( isset( $args[4] ) ) {
     1654                        if ( is_array( $args[4] ) ) {
     1655                                $attributes = wp_parse_args( $args[4], $attributes );
     1656                        } else {
     1657                                $_atts = array();
     1658                                wp_parse_str( $args[4], $_atts ); // Other attributes provided as a string
     1659                                $attributes = wp_parse_args( $_atts, $attributes );
     1660                        }
     1661                }
     1662
     1663        } else if ( !is_array( $attributes ) ) {
     1664
     1665                _doing_it_wrong( __FUNCTION__, __( 'Button attributes should be passed to the <code>$attributes</code> argument as an associative array.' ), 3.4 );
     1666
     1667                $attributes = array(
     1668                        'type' => $attributes
     1669                );
     1670
     1671        }
     1672
     1673        $attributes = wp_parse_args( $attributes, array(
     1674                'type'  => 'primary',
     1675                'wrap'  => true,
     1676                'name'  => 'submit',
     1677                'value' => ( null == $text ) ? __( 'Save Changes' ) : $text
     1678        ) );
     1679
     1680        switch ( $attributes['type'] ) :
    16341681                case 'primary' :
    16351682                case 'secondary' :
    1636                         $class = 'button-' . $type;
     1683                        $class = 'button-' . $attributes['type'];
    16371684                        break;
    16381685                case 'delete' :
    16391686                        $class = 'button-secondary delete';
    16401687                        break;
    16411688                default :
    1642                         $class = $type; // Custom cases can just pass in the classes they want to be used
     1689                        $class = $attributes['type']; // Custom cases can just pass in the classes they want to be used
    16431690        endswitch;
    1644         $text = ( null == $text ) ? __( 'Save Changes' ) : $text;
    16451691
    1646         // Default the id attribute to $name unless an id was specifically provided in $other_attributes
    1647         $id = $name;
    1648         if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
    1649                 $id = $other_attributes['id'];
    1650                 unset( $other_attributes['id'] );
    1651         }
     1692        if ( !isset( $attributes['id'] ) )
     1693                $attributes['id'] = $attributes['name'];
    16521694
    1653         $attributes = '';
    1654         if ( is_array( $other_attributes ) ) {
    1655                 foreach ( $other_attributes as $attribute => $value ) {
    1656                         $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
    1657                 }
    1658         } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
    1659                 $attributes = $other_attributes;
    1660         }
     1695        if ( !isset( $attributes['class'] ) )
     1696                $attributes['class'] = $class;
    16611697
    1662         $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
    1663         $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
     1698        $atts = '';
     1699        $wrap = $attributes['wrap'];
    16641700
    1665         if ( $wrap ) {
     1701        unset(
     1702                $attributes['type'],
     1703                $attributes['wrap']
     1704        );
     1705
     1706        foreach ( $attributes as $attribute => $value )
     1707                $atts .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
     1708
     1709        $button = '<input type="submit" ' . $atts . '/>';
     1710
     1711        if ( $wrap )
    16661712                $button = '<p class="submit">' . $button . '</p>';
    1667         }
    16681713
    16691714        return $button;
    16701715}