Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_submit_button [ WordPress Function ]

get_submit_button ( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null )
Parameters:
  • (string) $text The text of the button (defaults to 'Save Changes')
  • (string) $type The type of button. One of: primary, secondary, delete
  • (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.
  • (bool) $wrap True if the output button should be wrapped in a paragraph tag, false otherwise. Defaults to true
  • (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.
Defined at:



Returns a submit button, with provided text and appropriate class

Source


<?php
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 '<input type="submit" name="' esc_attr$name ) . '" id="' esc_attr$id ) . '" class="' esc_attr$class );
    
$button    .= '" value="' esc_attr$text ) . '" ' $attributes ' />';

    if ( 
$wrap ) {
        
$button '<p class="submit">' $button '</p>';
    }

    return 
$button;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics