wppaste
WordPress

get_submit_button( string $text = '', string $type = 'primary large', string $name = 'submit', bool $wrap = true, array|string $other_attributes = '' ): string

Since
3.1.0
Source
wp-admin/includes/template.php:2600
Returns a submit button, with provided text and appropriate class.

Compatibility

WordPress
since 3.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$textstringoptional
The text of the button. Defaults to 'Save Changes'.Default: ''
$typestringoptional
The type and CSS class(es) of the button. Core values include 'primary', 'small', 'compact' and 'large'. Default 'primary large'.Default: 'primary large'
$namestringoptional
The HTML name of the submit button. If no id attribute is given in the $other_attributes parameter, $name will be used as the button's id. Default 'submit'.Default: 'submit'
$wrapbooloptional
True if the output button should be wrapped in a paragraph tag, false otherwise. Default true.Default: true
$other_attributesarray|stringoptional
Other attributes that should be output with the button, mapping attributes to their values, e.g. array( 'id' => 'search-submit' ).
These key/value attribute pairs will be output as attribute="value", where attribute is the key. Attributes can also be provided as a string, e.g. id="search-submit", though the array format is generally preferred.
Default empty string.Default: ''

Return value

string
Submit button HTML.

Performance profile

How much work a call to get_submit_button() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
52–80

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 108.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below get_submit_button()

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 12 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_submit_button() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
is_array($type) && !$name52–63array_filter(), array_unique(), esc_attr(), esc_attr()
is_array($type) && !$name54–65array_filter(), array_unique(), __(), esc_attr(), esc_attr()
is_array($type)57–68array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr()
!is_array($type) && !$name57–68explode(), array_filter(), array_unique(), esc_attr(), esc_attr()
is_array($type)59–70array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr()
!is_array($type) && !$name59–70explode(), array_filter(), array_unique(), __(), esc_attr(), esc_attr()
is_array($type) && $name62–73array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
!is_array($type)62–73explode(), array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr()
is_array($type) && $name64–75array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
!is_array($type)64–75explode(), array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr()
!is_array($type) && $name67–78explode(), array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr(), esc_attr()
!is_array($type) && $name69–80explode(), array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr(), esc_attr()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10752–79161 fewer instruction than PHP 8.5
8.510852–8016
8.410852–80164 fewer instructions than PHP 8.3
8.311256–8416
8.211256–8416
8.111256–84163 fewer instructions than PHP 7.4
7.411556–8616

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 2

  • __()Retrieves the translation of $text.
  • esc_attr()Escaping for HTML attributes.

Used by · 4

Source code

function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) {	if ( ! is_array( $type ) ) {		$type = explode( ' ', $type );	} 	$button_shorthand = array( 'primary', 'small', 'large', 'compact' );	$classes          = array( 'button' ); 	foreach ( $type as $t ) {		if ( 'secondary' === $t || 'button-secondary' === $t ) {			continue;		} 		$classes[] = in_array( $t, $button_shorthand, true ) ? 'button-' . $t : $t;	} 	// Remove empty items, remove duplicate items, and finally build a string.	$class = implode( ' ', array_unique( array_filter( $classes ) ) ); 	$text = $text ? $text : __( 'Save Changes' ); 	// 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.		}	} elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string.		$attributes = $other_attributes;	} 	// Don't output empty name and id attributes.	$name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : '';	$id_attr   = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 	$button  = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr( $class );	$button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; 	if ( $wrap ) {		$button = '<p class="submit">' . $button . '</p>';	} 	return $button;}

Changelog

Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.