diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:56:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:56:49 +0000 |
commit | a415c29efee45520ae252d2aa28f1083a521cd7b (patch) | |
tree | f4ade4b6668ecc0765de7e1424f7c1427ad433ff /wp-includes/blocks/query-title | |
parent | Initial commit. (diff) | |
download | wordpress-a415c29efee45520ae252d2aa28f1083a521cd7b.tar.xz wordpress-a415c29efee45520ae252d2aa28f1083a521cd7b.zip |
Adding upstream version 6.4.3+dfsg1.upstream/6.4.3+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | wp-includes/blocks/query-title.php | 72 | ||||
-rw-r--r-- | wp-includes/blocks/query-title/block.json | 60 | ||||
-rw-r--r-- | wp-includes/blocks/query-title/style-rtl.css | 3 | ||||
-rw-r--r-- | wp-includes/blocks/query-title/style-rtl.min.css | 1 | ||||
-rw-r--r-- | wp-includes/blocks/query-title/style.css | 3 | ||||
-rw-r--r-- | wp-includes/blocks/query-title/style.min.css | 1 |
6 files changed, 140 insertions, 0 deletions
diff --git a/wp-includes/blocks/query-title.php b/wp-includes/blocks/query-title.php new file mode 100644 index 0000000..29793e5 --- /dev/null +++ b/wp-includes/blocks/query-title.php @@ -0,0 +1,72 @@ +<?php +/** + * Server-side rendering of the `core/query-title` block. + * + * @package WordPress + */ + +/** + * Renders the `core/query-title` block on the server. + * For now it only supports Archive title, + * using queried object information + * + * @param array $attributes Block attributes. + * + * @return string Returns the query title based on the queried object. + */ +function render_block_core_query_title( $attributes ) { + $type = isset( $attributes['type'] ) ? $attributes['type'] : null; + $is_archive = is_archive(); + $is_search = is_search(); + if ( ! $type || + ( 'archive' === $type && ! $is_archive ) || + ( 'search' === $type && ! $is_search ) + ) { + return ''; + } + $title = ''; + if ( $is_archive ) { + $show_prefix = isset( $attributes['showPrefix'] ) ? $attributes['showPrefix'] : true; + if ( ! $show_prefix ) { + add_filter( 'get_the_archive_title_prefix', '__return_empty_string', 1 ); + $title = get_the_archive_title(); + remove_filter( 'get_the_archive_title_prefix', '__return_empty_string', 1 ); + } else { + $title = get_the_archive_title(); + } + } + if ( $is_search ) { + $title = __( 'Search results' ); + + if ( isset( $attributes['showSearchTerm'] ) && $attributes['showSearchTerm'] ) { + $title = sprintf( + /* translators: %s is the search term. */ + __( 'Search results for: "%s"' ), + get_search_query() + ); + } + } + + $tag_name = isset( $attributes['level'] ) ? 'h' . (int) $attributes['level'] : 'h1'; + $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); + return sprintf( + '<%1$s %2$s>%3$s</%1$s>', + $tag_name, + $wrapper_attributes, + $title + ); +} + +/** + * Registers the `core/query-title` block on the server. + */ +function register_block_core_query_title() { + register_block_type_from_metadata( + __DIR__ . '/query-title', + array( + 'render_callback' => 'render_block_core_query_title', + ) + ); +} +add_action( 'init', 'register_block_core_query_title' ); diff --git a/wp-includes/blocks/query-title/block.json b/wp-includes/blocks/query-title/block.json new file mode 100644 index 0000000..2db349e --- /dev/null +++ b/wp-includes/blocks/query-title/block.json @@ -0,0 +1,60 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "core/query-title", + "title": "Query Title", + "category": "theme", + "description": "Display the query title.", + "textdomain": "default", + "attributes": { + "type": { + "type": "string" + }, + "textAlign": { + "type": "string" + }, + "level": { + "type": "number", + "default": 1 + }, + "showPrefix": { + "type": "boolean", + "default": true + }, + "showSearchTerm": { + "type": "boolean", + "default": true + } + }, + "supports": { + "align": [ "wide", "full" ], + "html": false, + "color": { + "gradients": true, + "__experimentalDefaultControls": { + "background": true, + "text": true + } + }, + "spacing": { + "margin": true, + "padding": true + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalFontStyle": true, + "__experimentalFontWeight": true, + "__experimentalLetterSpacing": true, + "__experimentalTextTransform": true, + "__experimentalTextDecoration": true, + "__experimentalDefaultControls": { + "fontSize": true, + "fontAppearance": true, + "textTransform": true + } + } + }, + "style": "wp-block-query-title" +} diff --git a/wp-includes/blocks/query-title/style-rtl.css b/wp-includes/blocks/query-title/style-rtl.css new file mode 100644 index 0000000..9371ffa --- /dev/null +++ b/wp-includes/blocks/query-title/style-rtl.css @@ -0,0 +1,3 @@ +.wp-block-query-title{ + box-sizing:border-box; +}
\ No newline at end of file diff --git a/wp-includes/blocks/query-title/style-rtl.min.css b/wp-includes/blocks/query-title/style-rtl.min.css new file mode 100644 index 0000000..13d9b6d --- /dev/null +++ b/wp-includes/blocks/query-title/style-rtl.min.css @@ -0,0 +1 @@ +.wp-block-query-title{box-sizing:border-box}
\ No newline at end of file diff --git a/wp-includes/blocks/query-title/style.css b/wp-includes/blocks/query-title/style.css new file mode 100644 index 0000000..9371ffa --- /dev/null +++ b/wp-includes/blocks/query-title/style.css @@ -0,0 +1,3 @@ +.wp-block-query-title{ + box-sizing:border-box; +}
\ No newline at end of file diff --git a/wp-includes/blocks/query-title/style.min.css b/wp-includes/blocks/query-title/style.min.css new file mode 100644 index 0000000..13d9b6d --- /dev/null +++ b/wp-includes/blocks/query-title/style.min.css @@ -0,0 +1 @@ +.wp-block-query-title{box-sizing:border-box}
\ No newline at end of file |