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
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
idattribute is given in the$other_attributesparameter,$namewill be used as the button'sid. 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 asattribute="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
- Scaling
- Scales with input
- Instructions
- 52–80
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 108.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
is_array($type) && !$name | 52–63 | array_filter(), array_unique(), esc_attr(), esc_attr() |
is_array($type) && !$name | 54–65 | array_filter(), array_unique(), __(), esc_attr(), esc_attr() |
is_array($type) | 57–68 | array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr() |
!is_array($type) && !$name | 57–68 | explode(), array_filter(), array_unique(), esc_attr(), esc_attr() |
is_array($type) | 59–70 | array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr() |
!is_array($type) && !$name | 59–70 | explode(), array_filter(), array_unique(), __(), esc_attr(), esc_attr() |
is_array($type) && $name | 62–73 | array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr(), esc_attr() |
!is_array($type) | 62–73 | explode(), array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr() |
is_array($type) && $name | 64–75 | array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr(), esc_attr() |
!is_array($type) | 64–75 | explode(), array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr() |
!is_array($type) && $name | 67–78 | explode(), array_filter(), array_unique(), esc_attr(), esc_attr(), esc_attr(), esc_attr() |
!is_array($type) && $name | 69–80 | explode(), array_filter(), array_unique(), __(), esc_attr(), esc_attr(), esc_attr(), esc_attr() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 107 | 52–79 | 16 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 108 | 52–80 | 16 | |
| 8.4 | 108 | 52–80 | 16 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 112 | 56–84 | 16 | |
| 8.2 | 112 | 56–84 | 16 | |
| 8.1 | 112 | 56–84 | 16 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 115 | 56–86 | 16 |
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
- _list_meta_row()Outputs a single row of public meta data in the Custom Fields meta box.
- get_media_item()Retrieves HTML form for modifying the image attachment.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
- wp_media_insert_url_form()Creates the form for external url.
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.
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.