Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: query-title.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/query-title` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/query-title` block on the server.
[8] Fix | Delete
* For now it supports Archive title, Search title, and Post Type Label,
[9] Fix | Delete
* using queried object information
[10] Fix | Delete
*
[11] Fix | Delete
* @since 5.8.0
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $attributes Block attributes.
[14] Fix | Delete
* @param array $_content Block content.
[15] Fix | Delete
* @param object $block Block instance.
[16] Fix | Delete
*
[17] Fix | Delete
* @return string Returns the query title based on the queried object.
[18] Fix | Delete
*/
[19] Fix | Delete
function render_block_core_query_title( $attributes, $content, $block ) {
[20] Fix | Delete
$type = isset( $attributes['type'] ) ? $attributes['type'] : null;
[21] Fix | Delete
$is_archive = is_archive();
[22] Fix | Delete
$is_search = is_search();
[23] Fix | Delete
$post_type = isset( $block->context['query']['postType'] ) ? $block->context['query']['postType'] : get_post_type();
[24] Fix | Delete
[25] Fix | Delete
if ( ! $type ||
[26] Fix | Delete
( 'archive' === $type && ! $is_archive ) ||
[27] Fix | Delete
( 'search' === $type && ! $is_search ) ||
[28] Fix | Delete
( 'post-type' === $type && ! $post_type )
[29] Fix | Delete
) {
[30] Fix | Delete
return '';
[31] Fix | Delete
}
[32] Fix | Delete
$title = '';
[33] Fix | Delete
if ( $is_archive ) {
[34] Fix | Delete
$show_prefix = isset( $attributes['showPrefix'] ) ? $attributes['showPrefix'] : true;
[35] Fix | Delete
if ( ! $show_prefix ) {
[36] Fix | Delete
add_filter( 'get_the_archive_title_prefix', '__return_empty_string', 1 );
[37] Fix | Delete
$title = get_the_archive_title();
[38] Fix | Delete
remove_filter( 'get_the_archive_title_prefix', '__return_empty_string', 1 );
[39] Fix | Delete
} else {
[40] Fix | Delete
$title = get_the_archive_title();
[41] Fix | Delete
}
[42] Fix | Delete
}
[43] Fix | Delete
if ( $is_search ) {
[44] Fix | Delete
$title = __( 'Search results' );
[45] Fix | Delete
[46] Fix | Delete
if ( isset( $attributes['showSearchTerm'] ) && $attributes['showSearchTerm'] ) {
[47] Fix | Delete
$title = sprintf(
[48] Fix | Delete
/* translators: %s is the search term. */
[49] Fix | Delete
__( 'Search results for: "%s"' ),
[50] Fix | Delete
get_search_query()
[51] Fix | Delete
);
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
if ( 'post-type' === $type ) {
[55] Fix | Delete
$post_type_object = get_post_type_object( $post_type );
[56] Fix | Delete
[57] Fix | Delete
if ( ! $post_type_object ) {
[58] Fix | Delete
return '';
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
$post_type_name = $post_type_object->labels->singular_name;
[62] Fix | Delete
$show_prefix = isset( $attributes['showPrefix'] ) ? $attributes['showPrefix'] : true;
[63] Fix | Delete
[64] Fix | Delete
if ( $show_prefix ) {
[65] Fix | Delete
$title = sprintf(
[66] Fix | Delete
/* translators: %s is the post type name. */
[67] Fix | Delete
__( 'Post Type: "%s"' ),
[68] Fix | Delete
$post_type_name
[69] Fix | Delete
);
[70] Fix | Delete
} else {
[71] Fix | Delete
$title = $post_type_name;
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
$level = isset( $attributes['level'] ) ? (int) $attributes['level'] : 1;
[76] Fix | Delete
$tag_name = 0 === $level ? 'p' : 'h' . (int) $attributes['level'];
[77] Fix | Delete
[78] Fix | Delete
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
[79] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
[80] Fix | Delete
return sprintf(
[81] Fix | Delete
'<%1$s %2$s>%3$s</%1$s>',
[82] Fix | Delete
$tag_name,
[83] Fix | Delete
$wrapper_attributes,
[84] Fix | Delete
$title
[85] Fix | Delete
);
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Registers the `core/query-title` block on the server.
[90] Fix | Delete
*
[91] Fix | Delete
* @since 5.8.0
[92] Fix | Delete
*/
[93] Fix | Delete
function register_block_core_query_title() {
[94] Fix | Delete
register_block_type_from_metadata(
[95] Fix | Delete
__DIR__ . '/query-title',
[96] Fix | Delete
array(
[97] Fix | Delete
'render_callback' => 'render_block_core_query_title',
[98] Fix | Delete
)
[99] Fix | Delete
);
[100] Fix | Delete
}
[101] Fix | Delete
add_action( 'init', 'register_block_core_query_title' );
[102] Fix | Delete
[103] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function