Make WordPress Core


Ignore:
Timestamp:
10/24/2023 08:49:38 AM (15 months ago)
Author:
Bernhard Reiter
Message:

Blocks: Fix layout support to be compatible with enhanced pagination.

Make layout support compatible with enhanced pagination by ensuring that generated class names are stable across pagination, even when the number of rendered posts is different.

With the previous implementation of enhanced pagination, the CSS corresponding to each block was not detected. Therefore, for enhanced pagination to work correctly, the CSS of the blocks present in the Post Template must be stable on all pages.

The number of posts rendered by the Query block is always the same, except in the last page, where it can be only a fraction. If any of the blocks rendered by the Post Template used the wp_unique_id function, the ID (which is incremental) would have been different than in the previous pages and the class names would have varied.

This is remediated by this changeset by replacing the usage of wp_unique_id in the layout support (which is used by the Query block) with an implementation that uses IDs that are incremental only for that block. That way, the generated class names are never affected by the number of times wp_unique_id runs.

Props luisherranz, andrewserong, isabel_brison, costdev, mukesh27, cbravobernal, hellofromTonya, jorbin.
Fixes #59681.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r56809 r56994  
    78327832
    78337833/**
     7834 * Generates an incremental ID that is independent per each different prefix.
     7835 *
     7836 * It is similar to `wp_unique_id`, but each prefix has its own internal ID
     7837 * counter to make each prefix independent from each other. The ID starts at 1
     7838 * and increments on each call. The returned value is not universally unique,
     7839 * but it is unique across the life of the PHP process and it's stable per
     7840 * prefix.
     7841 *
     7842 * @since 6.4.0
     7843 *
     7844 * @param string $prefix Optional. Prefix for the returned ID. Default empty string.
     7845 * @return string Incremental ID per prefix.
     7846 */
     7847function wp_unique_prefixed_id( $prefix = '' ) {
     7848    static $id_counters = array();
     7849
     7850    if ( ! is_string( $prefix ) ) {
     7851        wp_trigger_error(
     7852            __FUNCTION__,
     7853            sprintf( 'The prefix must be a string. "%s" data type given.', gettype( $prefix ) )
     7854        );
     7855        $prefix = '';
     7856    }
     7857
     7858    if ( ! isset( $id_counters[ $prefix ] ) ) {
     7859        $id_counters[ $prefix ] = 0;
     7860    }
     7861
     7862    $id = ++$id_counters[ $prefix ];
     7863
     7864    return $prefix . (string) $id;
     7865}
     7866
     7867/**
    78347868 * Gets last changed date for the specified cache group.
    78357869 *
Note: See TracChangeset for help on using the changeset viewer.