WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/08/12 04:58:34 (22 months ago)
Author:
koopersmith
Message:

New button styles.

Using the new buttons:

  • Button classes are now stackable.
  • All buttons should use a base class of "button".
  • Buttons default to the gray style (formerly "button-secondary"). Buttons can add a style by adding additional classes. To make a primary button, add the "button-primary" class.
  • Buttons can be rendered in various sizes. In addition to the default size, you can add "button-large", "button-small", or "button-tiny".

For backwards compatibility reasons, "button-primary" and "button-secondary" both work as standalone classes.

get_submit_button() has been adjusted to handle shorthand button classes (i.e. button classes can be passed without the "button-" prefix).

props lessbloat, helenyhou, trepmal, nacin. see #21598.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r21781 r21789  
    555555 
    556556<tr><td colspan="2" class="submit"> 
    557 <?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'newmeta-submit' ) ); ?> 
     557<?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta secondary', 'addmeta', false, array( 'id' => 'newmeta-submit' ) ); ?> 
    558558<?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?> 
    559559</td></tr> 
     
    11161116        if ( $section['title'] ) 
    11171117            echo "<h3>{$section['title']}</h3>\n"; 
    1118          
     1118 
    11191119        if ( $section['callback'] ) 
    11201120            call_user_func( $section['callback'], $section ); 
    1121          
     1121 
    11221122        if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) ) 
    11231123            continue; 
     
    16381638 */ 
    16391639function get_submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) { 
    1640     switch ( $type ) : 
    1641         case 'primary' : 
    1642         case 'secondary' : 
    1643             $class = 'button-' . $type; 
    1644             break; 
    1645         case 'delete' : 
    1646             $class = 'button-secondary delete'; 
    1647             break; 
    1648         default : 
    1649             $class = $type; // Custom cases can just pass in the classes they want to be used 
    1650     endswitch; 
    1651     $text = ( null == $text ) ? __( 'Save Changes' ) : $text; 
     1640    if ( ! is_array( $type ) ) 
     1641        $type = explode( ' ', $type );  
     1642 
     1643    $button_shorthand = array( 'primary', 'tiny', 'small', 'large' ); 
     1644    $classes = array( 'button' ); 
     1645    foreach ( $type as $t ) { 
     1646        if ( 'secondary' === $t || 'button-secondary' === $t ) 
     1647            continue; 
     1648        $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t; 
     1649    } 
     1650    $class = implode( ' ', array_unique( $classes ) ); 
     1651 
     1652    if ( 'delete' === $type ) 
     1653        $class = 'button-secondary delete'; 
     1654 
     1655    $text = $text ? $text : __( 'Save Changes' ); 
    16521656 
    16531657    // Default the id attribute to $name unless an id was specifically provided in $other_attributes 
Note: See TracChangeset for help on using the changeset viewer.