Making WordPress.org

Changeset 14723


Ignore:
Timestamp:
03/17/2026 01:52:57 PM (12 days ago)
Author:
obenland
Message:

Plugin Directory: Use shared pre-flight checks from Upload_Handler

Replaces inline 2FA, holiday, email deliverability, and queue
capacity checks with the shared methods added in [14721].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php

    r14717 r14723  
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
    33use WordPressdotorg\Plugin_Directory\Template;
    4 use Two_Factor_Core;
    5 use function WordPressdotorg\Two_Factor\{ user_requires_2fa, get_onboarding_account_url };
     4use function WordPressdotorg\Two_Factor\get_onboarding_account_url;
    65
    76class Upload {
     
    6362        }
    6463
    65         // Require 2FA for plugin authors on upload.
    66         if (
    67             function_exists( 'WordPressdotorg\Two_Factor\user_requires_2fa' ) &&
    68             class_exists( 'Two_Factor_Core' ) &&
    69             user_requires_2fa( wp_get_current_user() ) &&
    70             ! Two_Factor_Core::is_user_using_two_factor( get_current_user_id() )
    71         ) {
     64        // Check 2FA before proceeding.
     65        $preconditions = Upload_Handler::accepting_uploads();
     66        if ( is_wp_error( $preconditions ) && '2fa_required' === $preconditions->get_error_code() ) {
    7267            return '<div class="notice notice-error notice-alt"><p>' . sprintf(
    7368                /* translators: Setup 2FA url */
    7469                __( 'Before you can upload a new plugin, <a href="%s">please enable two-factor authentication</a>.', 'wporg-plugins' ),
    75                 esc_url( get_onboarding_account_url() )
     70                esc_url( function_exists( 'WordPressdotorg\Two_Factor\get_onboarding_account_url' ) ? get_onboarding_account_url() : 'https://profiles.wordpress.org/me/profile/security' )
    7671            ) . '</p></div>';
    7772        }
     
    8479        $upload_result = false;
    8580
    86         /*
    87          * Determine the maximum number of plugins a user can have in the queue.
    88          *
    89          * Plugin owners with more than 1m active installs can have up to 10 plugins in the queue.
    90          *
    91          * @see https://meta.trac.wordpress.org/ticket/76641
    92          */
    93         $maximum_plugins_in_queue = 1;
    94         $user_active_installs     = array_sum(
    95             wp_list_pluck(
    96                 get_posts( [
    97                     'author'      => get_current_user_id(),
    98                     'post_type'   => 'plugin',
    99                     'post_status' => 'publish', // Only count published plugins.
    100                     'numberposts' => -1
    101                 ] ),
    102                 '_active_installs'
    103             )
    104         );
    105         if ( $user_active_installs > 1000000 /* 1m+ */ ) {
    106             $maximum_plugins_in_queue = 10;
    107         }
    108 
    10981        list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins();
    110         $can_submit_new_plugin                        = $submitted_counts->total < $maximum_plugins_in_queue;
     82        $can_submit_new_plugin                        = ! is_wp_error( $preconditions );
    11183
    11284        if (
     
    139111            // Refresh the lists.
    140112            list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins();
    141             $can_submit_new_plugin                        = $submitted_counts->total < $maximum_plugins_in_queue;
     113            $can_submit_new_plugin                        = ! is_wp_error( Upload_Handler::has_queue_capacity() );
    142114
    143115            if ( ! empty( $message ) ) {
     
    388360        <?php endif; // ! is_wp_error( $upload_result )
    389361
    390         if ( defined( 'WPORG_ON_HOLIDAY' ) && WPORG_ON_HOLIDAY ) {
     362        if ( is_wp_error( $preconditions ) && 'submissions_paused' === $preconditions->get_error_code() ) {
    391363            printf(
    392364                '<div class="notice notice-error notice-alt"><p>%s</p></div>',
     
    396368                )
    397369            );
    398         } else if ( function_exists( 'is_email_address_unsafe' ) /* multisite-only */ && is_email_address_unsafe( wp_get_current_user()->user_email ) ) {
     370        } else if ( is_wp_error( $preconditions ) && 'unsafe_email' === $preconditions->get_error_code() ) {
    399371            echo '<div class="notice notice-error notice-alt"><p>' .
    400372                sprintf(
     
    406378
    407379        } else if ( $can_submit_new_plugin && ( ! $upload_result || is_wp_error( $upload_result ) ) ) :
    408             if ( $maximum_plugins_in_queue > 1 && $submitted_counts->total ) {
    409                 printf(
    410                     '<div class="notice notice-info notice-alt"><p>%s</p></div>',
    411                     sprintf(
    412                         /* translators: %s: Maximum number of plugins in the queue. */
    413                         __( 'You can have up to %s plugins in the queue at a time. You may submit an additional plugin for review below.', 'wporg-plugins' ),
    414                         '<strong>' . number_format_i18n( $maximum_plugins_in_queue ) . '</strong>'
    415                     )
    416                 );
    417             }
    418380
    419381            ?>
Note: See TracChangeset for help on using the changeset viewer.