Edit File by line
/home/barbar84/www/wp-inclu.../blocks
File: search.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/search` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Dynamically renders the `core/search` block.
[8] Fix | Delete
*
[9] Fix | Delete
* @param array $attributes The block attributes.
[10] Fix | Delete
*
[11] Fix | Delete
* @return string The search block markup.
[12] Fix | Delete
*/
[13] Fix | Delete
function render_block_core_search( $attributes ) {
[14] Fix | Delete
static $instance_id = 0;
[15] Fix | Delete
[16] Fix | Delete
// Older versions of the Search block defaulted the label and buttonText
[17] Fix | Delete
// attributes to `__( 'Search' )` meaning that many posts contain `<!--
[18] Fix | Delete
// wp:search /-->`. Support these by defaulting an undefined label and
[19] Fix | Delete
// buttonText to `__( 'Search' )`.
[20] Fix | Delete
$attributes = wp_parse_args(
[21] Fix | Delete
$attributes,
[22] Fix | Delete
array(
[23] Fix | Delete
'label' => __( 'Search' ),
[24] Fix | Delete
'buttonText' => __( 'Search' ),
[25] Fix | Delete
)
[26] Fix | Delete
);
[27] Fix | Delete
[28] Fix | Delete
$input_id = 'wp-block-search__input-' . ++$instance_id;
[29] Fix | Delete
$classnames = classnames_for_block_core_search( $attributes );
[30] Fix | Delete
$show_label = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
[31] Fix | Delete
$use_icon_button = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
[32] Fix | Delete
$show_input = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
[33] Fix | Delete
$show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
[34] Fix | Delete
$label_markup = '';
[35] Fix | Delete
$input_markup = '';
[36] Fix | Delete
$button_markup = '';
[37] Fix | Delete
$width_styles = '';
[38] Fix | Delete
[39] Fix | Delete
if ( $show_label ) {
[40] Fix | Delete
if ( ! empty( $attributes['label'] ) ) {
[41] Fix | Delete
$label_markup = sprintf(
[42] Fix | Delete
'<label for="%s" class="wp-block-search__label">%s</label>',
[43] Fix | Delete
$input_id,
[44] Fix | Delete
$attributes['label']
[45] Fix | Delete
);
[46] Fix | Delete
} else {
[47] Fix | Delete
$label_markup = sprintf(
[48] Fix | Delete
'<label for="%s" class="wp-block-search__label screen-reader-text">%s</label>',
[49] Fix | Delete
$input_id,
[50] Fix | Delete
__( 'Search' )
[51] Fix | Delete
);
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
if ( $show_input ) {
[56] Fix | Delete
$input_markup = sprintf(
[57] Fix | Delete
'<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" required />',
[58] Fix | Delete
$input_id,
[59] Fix | Delete
esc_attr( get_search_query() ),
[60] Fix | Delete
esc_attr( $attributes['placeholder'] )
[61] Fix | Delete
);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
if ( $show_button ) {
[65] Fix | Delete
$button_internal_markup = '';
[66] Fix | Delete
$button_classes = '';
[67] Fix | Delete
[68] Fix | Delete
if ( ! $use_icon_button ) {
[69] Fix | Delete
if ( ! empty( $attributes['buttonText'] ) ) {
[70] Fix | Delete
$button_internal_markup = $attributes['buttonText'];
[71] Fix | Delete
}
[72] Fix | Delete
} else {
[73] Fix | Delete
$button_classes .= 'has-icon';
[74] Fix | Delete
$button_internal_markup =
[75] Fix | Delete
'<svg id="search-icon" class="search-icon" viewBox="0 0 24 24" width="24" height="24">
[76] Fix | Delete
<path d="M13.5 6C10.5 6 8 8.5 8 11.5c0 1.1.3 2.1.9 3l-3.4 3 1 1.1 3.4-2.9c1 .9 2.2 1.4 3.6 1.4 3 0 5.5-2.5 5.5-5.5C19 8.5 16.5 6 13.5 6zm0 9.5c-2.2 0-4-1.8-4-4s1.8-4 4-4 4 1.8 4 4-1.8 4-4 4z"></path>
[77] Fix | Delete
</svg>';
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$button_markup = sprintf(
[81] Fix | Delete
'<button type="submit"class="wp-block-search__button ' . $button_classes . '">%s</button>',
[82] Fix | Delete
$button_internal_markup
[83] Fix | Delete
);
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
if ( ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] ) ) {
[87] Fix | Delete
if ( ! empty( $attributes['buttonPosition'] ) && 'button-only' !== $attributes['buttonPosition'] ) {
[88] Fix | Delete
$width_styles = ' style="width: ' . $attributes['width'] . $attributes['widthUnit'] . ';"';
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
$field_markup = sprintf(
[93] Fix | Delete
'<div class="wp-block-search__inside-wrapper"%s>%s</div>',
[94] Fix | Delete
$width_styles,
[95] Fix | Delete
$input_markup . $button_markup
[96] Fix | Delete
);
[97] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
[98] Fix | Delete
[99] Fix | Delete
return sprintf(
[100] Fix | Delete
'<form role="search" method="get" action="%s" %s>%s</form>',
[101] Fix | Delete
esc_url( home_url( '/' ) ),
[102] Fix | Delete
$wrapper_attributes,
[103] Fix | Delete
$label_markup . $field_markup
[104] Fix | Delete
);
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Registers the `core/search` block on the server.
[109] Fix | Delete
*/
[110] Fix | Delete
function register_block_core_search() {
[111] Fix | Delete
register_block_type_from_metadata(
[112] Fix | Delete
__DIR__ . '/search',
[113] Fix | Delete
array(
[114] Fix | Delete
'render_callback' => 'render_block_core_search',
[115] Fix | Delete
)
[116] Fix | Delete
);
[117] Fix | Delete
}
[118] Fix | Delete
add_action( 'init', 'register_block_core_search' );
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Builds the correct top level classnames for the 'core/search' block.
[122] Fix | Delete
*
[123] Fix | Delete
* @param array $attributes The block attributes.
[124] Fix | Delete
*
[125] Fix | Delete
* @return string The classnames used in the block.
[126] Fix | Delete
*/
[127] Fix | Delete
function classnames_for_block_core_search( $attributes ) {
[128] Fix | Delete
$classnames = array();
[129] Fix | Delete
[130] Fix | Delete
if ( ! empty( $attributes['buttonPosition'] ) ) {
[131] Fix | Delete
if ( 'button-inside' === $attributes['buttonPosition'] ) {
[132] Fix | Delete
$classnames[] = 'wp-block-search__button-inside';
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if ( 'button-outside' === $attributes['buttonPosition'] ) {
[136] Fix | Delete
$classnames[] = 'wp-block-search__button-outside';
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ( 'no-button' === $attributes['buttonPosition'] ) {
[140] Fix | Delete
$classnames[] = 'wp-block-search__no-button';
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
if ( 'button-only' === $attributes['buttonPosition'] ) {
[144] Fix | Delete
$classnames[] = 'wp-block-search__button-only';
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if ( isset( $attributes['buttonUseIcon'] ) ) {
[149] Fix | Delete
if ( ! empty( $attributes['buttonPosition'] ) && 'no-button' !== $attributes['buttonPosition'] ) {
[150] Fix | Delete
if ( $attributes['buttonUseIcon'] ) {
[151] Fix | Delete
$classnames[] = 'wp-block-search__icon-button';
[152] Fix | Delete
} else {
[153] Fix | Delete
$classnames[] = 'wp-block-search__text-button';
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
return implode( ' ', $classnames );
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function