Making WordPress.org

Changeset 13784


Ignore:
Timestamp:
06/07/2024 04:40:29 AM (9 months ago)
Author:
coffee2code
Message:

Photo Directory, User: Exclude submission errors by default when calculating the count of a user's rejections.

Props nilovelez, coffee2code.
Fixes #7588.

File:
1 edited

Legend:

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

    r12889 r13784  
    118118     * Returns a count of rejected photos for a user.
    119119     *
    120      * @param int $user_id Optional. The user ID. If not defined, assumes global
    121      *                     author. Default false.
    122      * @return int
    123      */
    124     public static function count_rejected_photos( $user_id = false ) {
     120     * @param int $user_id                    Optional. The user ID. If not defined,
     121     *                                        assumes global author. Default false.
     122     * @param bool $exclude_submission_errors Optional. Should photos rejected due
     123     *                                        to the 'submission-error' reason be
     124     *                                        excluded from the count? Default true.
     125     * @return int
     126     */
     127    public static function count_rejected_photos( $user_id = false, $exclude_submission_errors = true ) {
    125128        global $wpdb;
    126129
    127         if (  ! $user_id ) {
     130        if ( ! $user_id ) {
    128131            global $authordata;
    129132
     
    135138        }
    136139
    137         return (int) $wpdb->get_var( $wpdb->prepare(
    138             "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND post_author = %d",
    139             Registrations::get_post_type(),
    140             Rejection::get_post_status(),
    141             $user_id
    142         ) );
     140        $args = [
     141            'post_type'      => Registrations::get_post_type(),
     142            'post_status'    => Rejection::get_post_status(),
     143            'author'         => $user_id,
     144            'fields'         => 'ids',
     145            'posts_per_page' => -1,
     146        ];
     147
     148        if ( $exclude_submission_errors ) {
     149            $args['meta_query'] = [
     150                [
     151                    'key'      => 'rejected_reason',
     152                    'value'    => 'submission-error',
     153                    'compare'  => '!=',
     154                ],
     155            ];
     156        }
     157
     158        $query = new \WP_Query( $args );
     159        return $query->found_posts;
    143160    }
    144161
Note: See TracChangeset for help on using the changeset viewer.