Making WordPress.org


Ignore:
Timestamp:
10/20/2022 05:15:27 PM (2 years ago)
Author:
coffee2code
Message:

Photo Directory, User: Add getter for concurrent submission limit, with filter.

File:
1 edited

Legend:

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

    r12140 r12141  
    1616     * submission until a current submission is approved or rejected.
    1717     *
     18     * @see `get_concurrent_submission_limit()` for actually retrieving the maximum
     19     * pending submissions for a user, since it can vary based on the user and may
     20     * be filtered.
    1821     * @var int
    1922     */
     
    130133
    131134    /**
     135     * Returns the number of concurrent submissions allowed for a user.
     136     *
     137     * @param int $user_id Optional. The user ID. If not defined, assumes current
     138     *                     user. Default false.
     139     * @return int The number of concurrent submissions for a user.
     140     */
     141    public static function get_concurrent_submission_limit( $user_id = false ) {
     142        if ( ! $user_id ) {
     143            $user_id = get_current_user_id();
     144        }
     145
     146        if ( ! $user_id ) {
     147            return 0;
     148        }
     149
     150        return apply_filters( 'wporg_photos_max_concurrent_submissions', self::MAX_PENDING_SUBMISSIONS, $user_id );
     151    }
     152
     153    /**
    132154     * Determines if user has reached concurrent submission limit for pending
    133155     * uploads (e.g. max number of photos awaiting moderation).
     
    145167
    146168        if ( $user_id ) {
     169            $max_pending_submissions = self::get_concurrent_submission_limit( $user_id );
    147170            $posts = get_posts( [
    148171                'fields'         => 'ids',
    149                 'posts_per_page' => self::MAX_PENDING_SUBMISSIONS,
     172                'posts_per_page' => $max_pending_submissions,
    150173                'author'         => $user_id,
    151174                'post_status'    => 'pending',
     
    153176            ] );
    154177
    155             if ( count( $posts ) < self::MAX_PENDING_SUBMISSIONS ) {
     178            if ( count( $posts ) < $max_pending_submissions ) {
    156179                $limit_reached = false;
    157180            }
Note: See TracChangeset for help on using the changeset viewer.