Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: query-total.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/query-total` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `query-total` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.8.0
[10] Fix | Delete
*
[11] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $attributes Block attributes.
[14] Fix | Delete
* @param string $content Block default content.
[15] Fix | Delete
* @param WP_Block $block Block instance.
[16] Fix | Delete
*
[17] Fix | Delete
* @return string The rendered block content.
[18] Fix | Delete
*/
[19] Fix | Delete
function render_block_core_query_total( $attributes, $content, $block ) {
[20] Fix | Delete
global $wp_query;
[21] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes();
[22] Fix | Delete
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
[23] Fix | Delete
$query_to_use = $wp_query;
[24] Fix | Delete
$current_page = max( 1, (int) get_query_var( 'paged', 1 ) );
[25] Fix | Delete
} else {
[26] Fix | Delete
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
[27] Fix | Delete
$current_page = isset( $_GET[ $page_key ] ) ? (int) $_GET[ $page_key ] : 1;
[28] Fix | Delete
$query_to_use = new WP_Query( build_query_vars_from_query_block( $block, $current_page ) );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
$max_rows = $query_to_use->found_posts;
[32] Fix | Delete
$posts_per_page = (int) $query_to_use->get( 'posts_per_page' );
[33] Fix | Delete
[34] Fix | Delete
// Calculate the range of posts being displayed.
[35] Fix | Delete
$start = ( 0 === $max_rows ) ? 0 : ( ( $current_page - 1 ) * $posts_per_page + 1 );
[36] Fix | Delete
$end = min( $start + $posts_per_page - 1, $max_rows );
[37] Fix | Delete
[38] Fix | Delete
// Prepare the display based on the `displayType` attribute.
[39] Fix | Delete
$output = '';
[40] Fix | Delete
switch ( $attributes['displayType'] ) {
[41] Fix | Delete
case 'range-display':
[42] Fix | Delete
if ( $start === $end ) {
[43] Fix | Delete
$output = sprintf(
[44] Fix | Delete
/* translators: 1: Start index of posts, 2: Total number of posts */
[45] Fix | Delete
__( 'Displaying %1$s of %2$s' ),
[46] Fix | Delete
$start,
[47] Fix | Delete
$max_rows
[48] Fix | Delete
);
[49] Fix | Delete
} else {
[50] Fix | Delete
$output = sprintf(
[51] Fix | Delete
/* translators: 1: Start index of posts, 2: End index of posts, 3: Total number of posts */
[52] Fix | Delete
__( 'Displaying %1$s – %2$s of %3$s' ),
[53] Fix | Delete
$start,
[54] Fix | Delete
$end,
[55] Fix | Delete
$max_rows
[56] Fix | Delete
);
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
break;
[60] Fix | Delete
[61] Fix | Delete
case 'total-results':
[62] Fix | Delete
default:
[63] Fix | Delete
// translators: %d: number of results.
[64] Fix | Delete
$output = sprintf( _n( '%d result found', '%d results found', $max_rows ), $max_rows );
[65] Fix | Delete
break;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
return sprintf(
[69] Fix | Delete
'<div %1$s>%2$s</div>',
[70] Fix | Delete
$wrapper_attributes,
[71] Fix | Delete
$output
[72] Fix | Delete
);
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Registers the `query-total` block.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 6.8.0
[79] Fix | Delete
*/
[80] Fix | Delete
function register_block_core_query_total() {
[81] Fix | Delete
register_block_type_from_metadata(
[82] Fix | Delete
__DIR__ . '/query-total',
[83] Fix | Delete
array(
[84] Fix | Delete
'render_callback' => 'render_block_core_query_total',
[85] Fix | Delete
)
[86] Fix | Delete
);
[87] Fix | Delete
}
[88] Fix | Delete
add_action( 'init', 'register_block_core_query_total' );
[89] Fix | Delete
[90] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function