Changeset 13171
- Timestamp:
- 02/05/2024 10:01:30 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/admin.php
r12957 r13171 80 80 // Force the default editor to be the HTML editor. 81 81 add_filter( 'wp_default_editor', [ __CLASS__, 'force_text_editor' ], 99 ); 82 83 // Randomize the queue. 84 add_filter( 'query_vars', [ __CLASS__, 'add_query_var_for_random' ] ); 85 add_action( 'pre_get_posts', [ __CLASS__, 'randomize_the_queue' ] ); 82 86 } 83 87 … … 1480 1484 } 1481 1485 1486 /** 1487 * Adds 'random' as a custom query variable for photo queue listings. 1488 * 1489 * @param string[] $vars The array of allowed query variable names. 1490 * @return string[] 1491 */ 1492 public static function add_query_var_for_random( $vars ) { 1493 if ( 1494 is_admin() 1495 && 1496 is_main_query() 1497 && 1498 Registrations::get_post_type() === ( $_GET['post_type'] ?? false ) 1499 && 1500 'pending' === ( $_GET['post_status'] ?? '' ) 1501 ) { 1502 $vars[] = 'random'; 1503 } 1504 1505 return $vars; 1506 } 1507 1508 /** 1509 * Randomizes the list of posts in the queue. 1510 * 1511 * Note: Can be disabled via query string: ?random=0 1512 */ 1513 public static function randomize_the_queue( $query ) { 1514 if ( ! is_admin() ) { 1515 return; 1516 } 1517 1518 // Don't randomize if disabled via query parameter. 1519 if ( '0' === $query->get( 'random' ) ) { 1520 return; 1521 } 1522 1523 // Ensure the request is the main query and just for the photo queue. 1524 if ( 1525 $query->is_main_query() 1526 && 1527 Registrations::get_post_type() === $query->get( 'post_type' ) 1528 && 1529 'pending' === $query->get( 'post_status' ) 1530 ) { 1531 $query->set( 'orderby', 'rand' ); 1532 } 1533 } 1534 1482 1535 } 1483 1536
Note: See TracChangeset
for help on using the changeset viewer.