Changeset 14056
- Timestamp:
- 09/16/2024 10:15:28 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/rejection.php
r14055 r14056 417 417 * @return WP_Post[] Array of rejected photo posts. 418 418 */ 419 public static function get_user_rejections( $user_id ) { 420 return get_posts( [ 421 'posts_per_page' => 99, 419 public static function get_user_rejections( $user_id, $args = [] ) { 420 $args = wp_parse_args( 421 $args, 422 [ 423 'fields' => 'all', 424 'posts_per_page' => 99, 425 ] 426 ); 427 428 return get_posts( array_merge( $args, [ 422 429 'author' => (int) $user_id, 423 430 'post_status' => Rejection::get_post_status(), 424 431 'post_type' => Registrations::get_post_type(), 425 ] ); 432 ] ) ); 433 } 434 435 /** 436 * Returns an array of the reasons and respective counts for all of the user's rejections. 437 * 438 * @param int $user_id The user ID. 439 * @return int Associative array of rejection reasons and the counts for how many rejections 440 * the user has for each reason. This does not include rejection reasons for which 441 * the user does not have any rejections. 442 */ 443 public static function get_user_rejection_reasons( $user_id ) { 444 global $wpdb; 445 $reasons = []; 446 $rejection_ids = self::get_user_rejections( $user_id, [ 'fields' => 'ids', 'posts_per_page' => -1 ] ); 447 448 if ( $rejection_ids ) { 449 $rejection_ids = implode( ',', array_map( 'absint', $rejection_ids ) ); 450 $results = $wpdb->get_results( $n = $wpdb->prepare( 451 "SELECT pm.meta_value as rejection_reason, COUNT(*) as count FROM {$wpdb->postmeta} pm WHERE pm.post_id IN ($rejection_ids) AND meta_key = %s GROUP BY pm.meta_value", 452 'rejected_reason' 453 ), ARRAY_A ); 454 455 foreach ( $results as $item ) { 456 $reasons[ $item['rejection_reason'] ] = (int) $item['count']; 457 } 458 } 459 460 return $reasons; 426 461 } 427 462
Note: See TracChangeset
for help on using the changeset viewer.