Making WordPress.org


Ignore:
Timestamp:
08/01/2024 09:29:33 PM (17 months ago)
Author:
renyot
Message:

Learn: Sync with git WordPress/learn@59cde32

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2024/inc/query.php

    r13911 r13941  
    77
    88add_action( 'pre_get_posts', __NAMESPACE__ . '\add_language_to_archive_queries' );
    9 add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_all_level_query' );
    109add_action( 'pre_get_posts', __NAMESPACE__ . '\add_excluded_to_lesson_archive_query' );
     10add_filter( 'request', __NAMESPACE__ . '\handle_all_level_query' );
    1111
    1212/**
     
    4141        }
    4242    }
    43 
    44     return $query;
    45 }
    46 
    47 /**
    48  * Modify the main query.
    49  * If the 'all' level filter is set in the query, remove it to return all posts.
    50  *
    51  * @param WP_Query $query The main query.
    52  * @return WP_Query
    53  */
    54 function handle_all_level_query( $query ) {
    55     if ( is_admin() || ! $query->is_main_query() ) {
    56         return;
    57     }
    58 
    59     $level = $query->get( 'wporg_lesson_level' );
    60 
    61     if ( 'all' === $level ) {
    62         $query->set( 'wporg_lesson_level', '' );
    63     }
    64 
    65     return $query;
    6643}
    6744
     
    10380    }
    10481}
     82
     83/**
     84 * Modify the request.
     85 *
     86 * Update the query_vars to reset 'all' to an empty string.
     87 *
     88 * @param array $query_vars The array of requested query variables.
     89 *
     90 * @return array
     91 */
     92function handle_all_level_query( $query_vars ) {
     93    if ( is_admin() ) {
     94        return;
     95    }
     96
     97    $level = $query_vars['wporg_lesson_level'] ?? '';
     98
     99    if ( 'all' === $level ) {
     100        $query_vars['wporg_lesson_level'] = '';
     101    }
     102
     103    return $query_vars;
     104}
Note: See TracChangeset for help on using the changeset viewer.