aboutsummaryrefslogtreecommitdiff
path: root/srcs/wordpress/wp-includes/blocks/search.php
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-07 13:06:14 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-07 13:06:14 +0100
commit7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 (patch)
treef7453d7dd5cbaaab246e23810b02d3edf1e451be /srcs/wordpress/wp-includes/blocks/search.php
parentc59bdcf77c50cbe89b4a93782cdd6d9e7532080e (diff)
downloadft_server-7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8.tar.gz
ft_server-7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8.tar.bz2
ft_server-7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8.zip
Added wordpress
Diffstat (limited to 'srcs/wordpress/wp-includes/blocks/search.php')
-rw-r--r--srcs/wordpress/wp-includes/blocks/search.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/srcs/wordpress/wp-includes/blocks/search.php b/srcs/wordpress/wp-includes/blocks/search.php
new file mode 100644
index 0000000..6cd909f
--- /dev/null
+++ b/srcs/wordpress/wp-includes/blocks/search.php
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Server-side rendering of the `core/search` block.
+ *
+ * @package WordPress
+ */
+
+/**
+ * Dynamically renders the `core/search` block.
+ *
+ * @param array $attributes The block attributes.
+ *
+ * @return string The search block markup.
+ */
+function render_block_core_search( $attributes ) {
+ static $instance_id = 0;
+
+ $input_id = 'wp-block-search__input-' . ++$instance_id;
+ $label_markup = '';
+ $button_markup = '';
+
+ if ( ! empty( $attributes['label'] ) ) {
+ $label_markup = sprintf(
+ '<label for="%s" class="wp-block-search__label">%s</label>',
+ $input_id,
+ $attributes['label']
+ );
+ }
+
+ $input_markup = sprintf(
+ '<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" />',
+ $input_id,
+ esc_attr( get_search_query() ),
+ esc_attr( $attributes['placeholder'] )
+ );
+
+ if ( ! empty( $attributes['buttonText'] ) ) {
+ $button_markup = sprintf(
+ '<button type="submit" class="wp-block-search__button">%s</button>',
+ $attributes['buttonText']
+ );
+ }
+
+ $class = 'wp-block-search';
+ if ( isset( $attributes['className'] ) ) {
+ $class .= ' ' . $attributes['className'];
+ }
+
+ if ( isset( $attributes['align'] ) ) {
+ $class .= ' align' . $attributes['align'];
+ }
+
+ return sprintf(
+ '<form class="%s" role="search" method="get" action="%s">%s</form>',
+ $class,
+ esc_url( home_url( '/' ) ),
+ $label_markup . $input_markup . $button_markup
+ );
+}
+
+/**
+ * Registers the `core/search` block on the server.
+ */
+function register_block_core_search() {
+ register_block_type(
+ 'core/search',
+ array(
+ 'attributes' => array(
+ 'align' => array(
+ 'type' => 'string',
+ 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
+ ),
+ 'className' => array(
+ 'type' => 'string',
+ ),
+ 'label' => array(
+ 'type' => 'string',
+ 'default' => __( 'Search' ),
+ ),
+ 'placeholder' => array(
+ 'type' => 'string',
+ 'default' => '',
+ ),
+ 'buttonText' => array(
+ 'type' => 'string',
+ 'default' => __( 'Search' ),
+ ),
+ ),
+ 'render_callback' => 'render_block_core_search',
+ )
+ );
+}
+add_action( 'init', 'register_block_core_search' );