WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/28/2010 09:56:43 PM (9 years ago)
Author:
markjaquith
Message:

Expand submit_button() capabilities. Replace all (or almost all) manual HTML instances in WP. props sbressler. see #15064

File:
1 edited

Legend:

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

    r15976 r16061  
    496496    $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta[{$entry['meta_id']}][key]'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' />";
    497497
    498     $r .= "\n\t\t<div class='submit'><input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
    499     $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='". esc_attr__( 'Delete' ) ."' />";
    500     $r .= "\n\t\t<input name='updatemeta' type='submit' tabindex='6' value='". esc_attr__( 'Update' ) ."' class='add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta' /></div>";
     498    $r .= "\n\t\t<div class='submit'>";
     499    $r .= get_submit_button( __( 'Delete' ), "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta", "deletemeta[{$entry['meta_id']}]", false, array( 'tabindex' => '6' ) );
     500    $r .= "\n\t\t";
     501    $r .= get_submit_button( __( 'Update' ), "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta" , 'updatemeta', false, array( 'tabindex' => '6' ) );
     502    $r .= "</div>";
    501503    $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
    502504    $r .= "</td>";
     
    558560
    559561<tr><td colspan="2" class="submit">
    560 <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="<?php esc_attr_e( 'Add Custom Field' ) ?>" />
     562<?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'addmetasub', 'tabindex' => '9' ) ); ?>
    561563<?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
    562564</td></tr>
     
    844846<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
    845847</p>
    846 <?php submit_button( __('Upload file and import'), 'secondary' ); ?>
     848<?php submit_button( __('Upload file and import'), 'button' ); ?>
    847849</form>
    848850<?php
     
    13581360        <div class="find-box-buttons">
    13591361            <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
    1360             <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
     1362            <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
    13611363        </div>
    13621364    </div>
     
    18901892    if ( !empty($per_page_label) )
    18911893        $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n";
    1892     $return .= "<input type='submit' class='button' value='" . esc_attr__('Apply') . "' />";
     1894    $return .= get_submit_button( __( 'Apply' ), 'button', '', false );
    18931895    $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
    18941896    $return .= "</div>\n";
     
    20872089
    20882090/**
    2089  * Echos a paragraph-wrapped submit button, with provided text and appropriate class
     2091 * Echos a submit button, with provided text and appropriate class
    20902092 *
    20912093 * @since 3.1.0
     
    20932095 * @param string $text The text of the button (defaults to 'Save Changes')
    20942096 * @param string $type The type of button. One of: primary, secondary, delete
    2095  * @param string $name The HTML name of the submit button. Defaults to "submit"
    2096  */
    2097 function submit_button( $text = NULL, $type = 'primary', $name = 'submit' ) {
    2098     echo get_submit_button( $text, $type, $name );
    2099 }
    2100 
    2101 /**
    2102  * Returns a paragraph-wrapped submit button, with provided text and appropriate class
     2097 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
     2098 *               is given in $other_attributes below, $name will be used as the button's id.
     2099 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
     2100 *             false otherwise. Defaults to true
     2101 * @param array|string $other_attributes Other attributes that should be output with the button,
     2102 *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
     2103 *                     These attributes will be ouput as attribute="value", such as tabindex="1".
     2104 *                     Defaults to no other attributes. Other attributes can also be provided as a
     2105 *                     string such as 'tabindex="1"', though the array format is typically cleaner.
     2106 */
     2107function submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
     2108    echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
     2109}
     2110
     2111/**
     2112 * Returns a submit button, with provided text and appropriate class
    21032113 *
    21042114 * @since 3.1.0
     
    21062116 * @param string $text The text of the button (defaults to 'Save Changes')
    21072117 * @param string $type The type of button. One of: primary, secondary, delete
    2108  * @param string $name The HTML name of the submit button. Defaults to "submit"
    2109  */
    2110 function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit' ) {
     2118 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
     2119 *               is given in $other_attributes below, $name will be used as the button's id.
     2120 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
     2121 *             false otherwise. Defaults to true
     2122 * @param array|string $other_attributes Other attributes that should be output with the button,
     2123 *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
     2124 *                     These attributes will be ouput as attribute="value", such as tabindex="1".
     2125 *                     Defaults to no other attributes. Other attributes can also be provided as a
     2126 *                     string such as 'tabindex="1"', though the array format is typically cleaner.
     2127 */
     2128function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
    21112129    switch ( $type ) :
    21122130        case 'primary' :
     
    21212139    endswitch;
    21222140    $text = ( NULL == $text ) ? __( 'Save Changes' ) : $text;
    2123     return '<p class="submit"><input type="submit" name="' . esc_attr( $name ) . '" class="' . esc_attr( $class ) . '" value="' . esc_attr( $text ) . '" /></p>';
    2124 }
    2125 
     2141   
     2142    $attributes = '';
     2143    if ( is_array( $other_attributes ) ) {
     2144        foreach ( $other_attributes as $attribute => $value ) {
     2145            $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
     2146        }
     2147    } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
     2148        $attributes = $other_attributes;
     2149    }
     2150   
     2151    // Default the id attribute to $name unless an id was specifically provided in $other_attributes
     2152    $id = 'id="' . esc_attr( $name ) . '" ';
     2153    if ( is_array( $other_attributes ) && array_key_exists( 'id', $other_attributes ) ) {
     2154        $id = 'id="' . esc_attr( $other_attributes['id'] ) . '" ';
     2155    }
     2156   
     2157    $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . $id . '" class="' . esc_attr( $class );
     2158    $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
     2159   
     2160    if ( $wrap ) {
     2161        $button = '<p class="submit">' . $button . '</p>';
     2162    }
     2163   
     2164    return $button;
     2165}
     2166
Note: See TracChangeset for help on using the changeset viewer.