A HitchHackers guide through WordPress


Home | Pages | Archives


get_submit_button

February 24, 2011 12:45 pm

Definition:
function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {}

Returns a submit button, with provided text and appropriate class

Parameters

Source code

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;

}

9664

Rate this:

Posted by Thorsten

Categories: /wp-admin/includes/template.php, Documentation, Files, Functions, Functions by letter g

Tags: ,

Leave a Reply



Mobile Site | Full Site


Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.