Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-inclu.../blocks
File: query-pagination-numbers.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/query-pagination-numbers` 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-pagination-numbers` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.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 Returns the pagination numbers for the Query.
[18] Fix | Delete
*/
[19] Fix | Delete
function render_block_core_query_pagination_numbers( $attributes, $content, $block ) {
[20] Fix | Delete
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
[21] Fix | Delete
$enhanced_pagination = isset( $block->context['enhancedPagination'] ) && $block->context['enhancedPagination'];
[22] Fix | Delete
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
[23] Fix | Delete
$max_page = isset( $block->context['query']['pages'] ) ? (int) $block->context['query']['pages'] : 0;
[24] Fix | Delete
[25] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes();
[26] Fix | Delete
$content = '';
[27] Fix | Delete
global $wp_query;
[28] Fix | Delete
$mid_size = isset( $block->attributes['midSize'] ) ? (int) $block->attributes['midSize'] : null;
[29] Fix | Delete
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
[30] Fix | Delete
// Take into account if we have set a bigger `max page`
[31] Fix | Delete
// than what the query has.
[32] Fix | Delete
$total = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page;
[33] Fix | Delete
$paginate_args = array(
[34] Fix | Delete
'prev_next' => false,
[35] Fix | Delete
'total' => $total,
[36] Fix | Delete
);
[37] Fix | Delete
if ( null !== $mid_size ) {
[38] Fix | Delete
$paginate_args['mid_size'] = $mid_size;
[39] Fix | Delete
}
[40] Fix | Delete
$content = paginate_links( $paginate_args );
[41] Fix | Delete
} else {
[42] Fix | Delete
$block_query = new WP_Query( build_query_vars_from_query_block( $block, $page ) );
[43] Fix | Delete
// `paginate_links` works with the global $wp_query, so we have to
[44] Fix | Delete
// temporarily switch it with our custom query.
[45] Fix | Delete
$prev_wp_query = $wp_query;
[46] Fix | Delete
$wp_query = $block_query;
[47] Fix | Delete
$total = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page;
[48] Fix | Delete
$paginate_args = array(
[49] Fix | Delete
'base' => '%_%',
[50] Fix | Delete
'format' => "?$page_key=%#%",
[51] Fix | Delete
'current' => max( 1, $page ),
[52] Fix | Delete
'total' => $total,
[53] Fix | Delete
'prev_next' => false,
[54] Fix | Delete
);
[55] Fix | Delete
if ( null !== $mid_size ) {
[56] Fix | Delete
$paginate_args['mid_size'] = $mid_size;
[57] Fix | Delete
}
[58] Fix | Delete
if ( 1 !== $page ) {
[59] Fix | Delete
/**
[60] Fix | Delete
* `paginate_links` doesn't use the provided `format` when the page is `1`.
[61] Fix | Delete
* This is great for the main query as it removes the extra query params
[62] Fix | Delete
* making the URL shorter, but in the case of multiple custom queries is
[63] Fix | Delete
* problematic. It results in returning an empty link which ends up with
[64] Fix | Delete
* a link to the current page.
[65] Fix | Delete
*
[66] Fix | Delete
* A way to address this is to add a `fake` query arg with no value that
[67] Fix | Delete
* is the same for all custom queries. This way the link is not empty and
[68] Fix | Delete
* preserves all the other existent query args.
[69] Fix | Delete
*
[70] Fix | Delete
* @see https://developer.wordpress.org/reference/functions/paginate_links/
[71] Fix | Delete
*
[72] Fix | Delete
* The proper fix of this should be in core. Track Ticket:
[73] Fix | Delete
* @see https://core.trac.wordpress.org/ticket/53868
[74] Fix | Delete
*
[75] Fix | Delete
* TODO: After two WP versions (starting from the WP version the core patch landed),
[76] Fix | Delete
* we should remove this and call `paginate_links` with the proper new arg.
[77] Fix | Delete
*/
[78] Fix | Delete
$paginate_args['add_args'] = array( 'cst' => '' );
[79] Fix | Delete
}
[80] Fix | Delete
// We still need to preserve `paged` query param if exists, as is used
[81] Fix | Delete
// for Queries that inherit from global context.
[82] Fix | Delete
$paged = empty( $_GET['paged'] ) ? null : (int) $_GET['paged'];
[83] Fix | Delete
if ( $paged ) {
[84] Fix | Delete
$paginate_args['add_args'] = array( 'paged' => $paged );
[85] Fix | Delete
}
[86] Fix | Delete
$content = paginate_links( $paginate_args );
[87] Fix | Delete
wp_reset_postdata(); // Restore original Post Data.
[88] Fix | Delete
$wp_query = $prev_wp_query;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( empty( $content ) ) {
[92] Fix | Delete
return '';
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
if ( $enhanced_pagination ) {
[96] Fix | Delete
$p = new WP_HTML_Tag_Processor( $content );
[97] Fix | Delete
$tag_index = 0;
[98] Fix | Delete
while ( $p->next_tag(
[99] Fix | Delete
array( 'class_name' => 'page-numbers' )
[100] Fix | Delete
) ) {
[101] Fix | Delete
if ( null === $p->get_attribute( 'data-wp-key' ) ) {
[102] Fix | Delete
$p->set_attribute( 'data-wp-key', 'index-' . $tag_index++ );
[103] Fix | Delete
}
[104] Fix | Delete
if ( 'A' === $p->get_tag() ) {
[105] Fix | Delete
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
[106] Fix | Delete
}
[107] Fix | Delete
}
[108] Fix | Delete
$content = $p->get_updated_html();
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
return sprintf(
[112] Fix | Delete
'<div %1$s>%2$s</div>',
[113] Fix | Delete
$wrapper_attributes,
[114] Fix | Delete
$content
[115] Fix | Delete
);
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Registers the `core/query-pagination-numbers` block on the server.
[120] Fix | Delete
*
[121] Fix | Delete
* @since 5.8.0
[122] Fix | Delete
*/
[123] Fix | Delete
function register_block_core_query_pagination_numbers() {
[124] Fix | Delete
register_block_type_from_metadata(
[125] Fix | Delete
__DIR__ . '/query-pagination-numbers',
[126] Fix | Delete
array(
[127] Fix | Delete
'render_callback' => 'render_block_core_query_pagination_numbers',
[128] Fix | Delete
)
[129] Fix | Delete
);
[130] Fix | Delete
}
[131] Fix | Delete
add_action( 'init', 'register_block_core_query_pagination_numbers' );
[132] Fix | Delete
[133] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function