Making WordPress.org

Changeset 13254


Ignore:
Timestamp:
02/29/2024 11:40:41 PM (14 months ago)
Author:
coffee2code
Message:

Photo Directory, Random: Add body class to indicate when queue is shown randomized.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/random.php

    r13253 r13254  
    3737     */
    3838    public static function init() {
     39        // Add 'random' URL endpoint to front-end.
    3940        add_action( 'init',              [ __CLASS__, 'add_rewrite_rule' ] );
    4041        add_filter( 'query_vars',        [ __CLASS__, 'add_query_var' ] );
     
    4243        add_action( 'template_redirect', [ __CLASS__, 'redirect_if_random' ] );
    4344        add_filter( 'wp_robots',         [ __CLASS__, 'noindex' ] );
     45
     46        // Accommodate randomization of queue.
     47        add_filter( 'admin_body_class',  [ __CLASS__, 'random_in_admin_body_class' ] );
    4448    }
    4549
     
    136140    }
    137141
     142    /**
     143     * Determines if the current query is for an admin listing of photos
     144     * that should be randomly ordered.
     145     *
     146     * @return bool True if the query is for an admin listing of photos that should be
     147     *              randomly ordered, else false.
     148     */
     149    public static function is_random_admin_listing() {
     150        return (
     151            is_admin()
     152        &&
     153            is_main_query()
     154        &&
     155            Registrations::get_post_type() === ( $_GET['post_type'] ?? false )
     156        &&
     157            'pending' === ( $_GET['post_status'] ?? '' )
     158        );
     159    }
     160
     161    /**
     162     * Adds class denoting a random listing of photos when appropriate.
     163     *
     164     * @param string $classes Space-separated list of CSS classes.
     165     * @return string[]
     166     */
     167    public static function random_in_admin_body_class( $classes ) {
     168        if ( self::is_random_admin_listing() ) {
     169            $classes .= ' photos-random';
     170        }
     171
     172        return trim( $classes );
     173    }
     174
    138175}
    139176
Note: See TracChangeset for help on using the changeset viewer.