classnames_for_block_core_search

函数
classnames_for_block_core_search ( $attributes )
参数
  • (array) $attributes The block attributes.
    Required:
返回值
  • (string) The classnames used in the block.
定义位置
相关方法
styles_for_block_core_searchget_color_classes_for_block_core_searchget_typography_classes_for_block_core_searchget_border_color_classes_for_block_core_searchregister_block_core_search
引入
-
弃用
-

classnames_for_block_core_search: 这个函数生成Gutenberg编辑器中的搜索块所使用的CSS类。

为’core/search’区块建立正确的顶层类名。

function classnames_for_block_core_search( $attributes ) {
	$classnames = array();

	if ( ! empty( $attributes['buttonPosition'] ) ) {
		if ( 'button-inside' === $attributes['buttonPosition'] ) {
			$classnames[] = 'wp-block-search__button-inside';
		}

		if ( 'button-outside' === $attributes['buttonPosition'] ) {
			$classnames[] = 'wp-block-search__button-outside';
		}

		if ( 'no-button' === $attributes['buttonPosition'] ) {
			$classnames[] = 'wp-block-search__no-button';
		}

		if ( 'button-only' === $attributes['buttonPosition'] ) {
			$classnames[] = 'wp-block-search__button-only';
		}
	}

	if ( isset( $attributes['buttonUseIcon'] ) ) {
		if ( ! empty( $attributes['buttonPosition'] ) && 'no-button' !== $attributes['buttonPosition'] ) {
			if ( $attributes['buttonUseIcon'] ) {
				$classnames[] = 'wp-block-search__icon-button';
			} else {
				$classnames[] = 'wp-block-search__text-button';
			}
		}
	}

	return implode( ' ', $classnames );
}

常见问题

FAQs
查看更多 >