Making WordPress.org

Changeset 12140


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

Photo Directory, User: Move Uploads::user_reached_concurrent_submission_limit() to User::has_reached_concurrent_submission_limit().

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc
Files:
3 edited

Legend:

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

    r12107 r12140  
    560560        $content .= '<p>';
    561561        $content .= sprintf(
    562             _n( 'You can have up to <strong>%d</strong> photo in the moderation queue at a time. You currently have <strong>%d</strong>.', 'You can have up to <strong>%d</strong> photos in the moderation queue at a time. You currently have <strong>%d</strong>.', Uploads::MAX_PENDING_SUBMISSIONS,'wporg-photos' ),
    563             Uploads::MAX_PENDING_SUBMISSIONS,
     562            _n( 'You can have up to <strong>%d</strong> photo in the moderation queue at a time. You currently have <strong>%d</strong>.', 'You can have up to <strong>%d</strong> photos in the moderation queue at a time. You currently have <strong>%d</strong>.', User::MAX_PENDING_SUBMISSIONS,'wporg-photos' ),
     563            User::MAX_PENDING_SUBMISSIONS,
    564564            count( $pending )
    565565        );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php

    r12110 r12140  
    1616     */
    1717    const MAX_LENGTH_DESCRIPTION = 250;
    18 
    19     /**
    20      * Maximum number of pending/concurrent submissions.
    21      *
    22      * Once this threshold is met, a user will be unable to make another
    23      * submission until the current submission is approved or rejected.
    24      *
    25      * @var int
    26      */
    27     const MAX_PENDING_SUBMISSIONS = 5;
    2818
    2919    /**
     
    525515        // Check if user has reached submission limit.
    526516        if ( $can ) {
    527             $can = ! self::user_reached_concurrent_submission_limit();
     517            $can = ! User::has_reached_concurrent_submission_limit();
    528518            $reason = 'concurrent-submission-limit';
    529519        }
     
    849839
    850840    /**
    851      * Determines if user has reached concurrent submission limit for pending
    852      * uploads (e.g. max number of photos awaiting moderation).
    853      *
    854      * @return bool True if use has exceeded pending sumission limit, else false.
    855      */
    856     public static function user_reached_concurrent_submission_limit() {
    857         $limit_reached = true;
    858 
    859         if ( is_user_logged_in() ) {
    860             $posts = get_posts( [
    861                 'fields'         => 'ids',
    862                 'posts_per_page' => self::MAX_PENDING_SUBMISSIONS,
    863                 'author'         => get_current_user_id(),
    864                 'post_status'    => 'pending',
    865                 'post_type'      => Registrations::get_post_type(),
    866             ] );
    867 
    868             if ( count( $posts ) < self::MAX_PENDING_SUBMISSIONS ) {
    869                 $limit_reached = false;
    870             }
    871         }
    872 
    873         return $limit_reached;
    874     }
    875 
    876 
    877     /**
    878841     * Outputs a notice for users who are prevented from uploading and prevents
    879842     * the upload form from being output.
     
    914877            );
    915878
    916             if ( self::user_reached_concurrent_submission_limit() ) {
     879            if ( User::has_reached_concurrent_submission_limit() ) {
    917880                $content .= '<p>' . __( 'Thanks for your submissions! Please wait until a photo is approved by moderators before submitting again.', 'wporg-photos' ) . '</p>';
    918881            } else {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/user.php

    r12110 r12140  
    129129    }
    130130
     131    /**
     132     * Determines if user has reached concurrent submission limit for pending
     133     * uploads (e.g. max number of photos awaiting moderation).
     134     *
     135     * @param int $user_id Optional. The user ID. If not defined, assumes current
     136     *                     user. Default false.
     137     * @return bool True if user has exceeded pending sumission limit, else false.
     138     */
     139    public static function has_reached_concurrent_submission_limit( $user_id = false ) {
     140        $limit_reached = true;
     141
     142        if ( ! $user_id ) {
     143            $user_id = get_current_user_id();
     144        }
     145
     146        if ( $user_id ) {
     147            $posts = get_posts( [
     148                'fields'         => 'ids',
     149                'posts_per_page' => self::MAX_PENDING_SUBMISSIONS,
     150                'author'         => $user_id,
     151                'post_status'    => 'pending',
     152                'post_type'      => Registrations::get_post_type(),
     153            ] );
     154
     155            if ( count( $posts ) < self::MAX_PENDING_SUBMISSIONS ) {
     156                $limit_reached = false;
     157            }
     158        }
     159
     160        return $limit_reached;
     161    }
     162
    131163}
    132164
Note: See TracChangeset for help on using the changeset viewer.