返回介绍

get_submit_button()

发布于 2017-09-11 00:15:44 字数 4727 浏览 1277 评论 0 收藏 0

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

Returns a submit button, with provided text and appropriate class


description


参数

$text

(string) (Optional) The text of the button. Default 'Save Changes'.

Default value: ''

$type

(string) (Optional) The type and CSS class(es) of the button. Core values include 'primary', 'small', and 'large'.

Default value: 'primary large'

$name

(string) (Optional) 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.

Default value: 'submit'

$wrap

(bool) (Optional) True if the output button should be wrapped in a paragraph tag, false otherwise.

Default value: true

$other_attributes

(array|string) (Optional) 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". Other attributes can also be provided as a string such as tabindex="1", though the array format is typically cleaner.

Default value: ''


返回值

(string) Submit button HTML.


源代码

File: wp-admin/includes/template.php

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' );
	$classes = array( 'button' );
	foreach ( $type as $t ) {
		if ( 'secondary' === $t || 'button-secondary' === $t )
			continue;
		$classes[] = in_array( $t, $button_shorthand ) ? '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;
}

更新日志

Versiondescription
3.1.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: esc_attr()

Used By

  • wp-admin/includes/template.php: submit_button()
  • wp-admin/includes/template.php: _list_meta_row()
  • wp-admin/includes/media.php: wp_media_insert_url_form()
  • wp-admin/includes/media.php: get_media_item()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文