Making WordPress.org

Changeset 12618


Ignore:
Timestamp:
06/05/2023 04:40:30 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Upload Shortcode: Remove a level of if() nesting for slightly more readable code.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes
Files:
2 edited

Legend:

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

    r12617 r12618  
    6161     */
    6262    public function process_upload() {
     63        if ( UPLOAD_ERR_OK !== $_FILES['zip_file']['error'] ) {
     64            return new \WP_Error( 'error_upload', __( 'Error in file upload.', 'wporg-plugins' ) );
     65        }
     66
     67        $zip_file         = $_FILES['zip_file']['tmp_name'];
    6368        $has_upload_token = $this->has_valid_upload_token();
    64         $zip_file         = $_FILES['zip_file']['tmp_name'];
    6569        $this->plugin_dir = Filesystem::unzip( $zip_file );
    6670
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php

    r12617 r12618  
    4242     */
    4343    public static function display() {
     44        if ( ! is_user_logged_in() ) {
     45            return '<div class="notice notice-error notice-alt"><p>' . sprintf(
     46                /* translators: Login URL */
     47                __( 'Before you can upload a new plugin, <a href="%s">please log in</a>.', 'wporg-plugins' ),
     48                esc_url( wp_login_url() )
     49            ) . '</p></div>';
     50        }
     51
    4452        ob_start();
    4553
    4654        $uploader = new Upload_Handler();
    4755
    48         if ( is_user_logged_in() ) :
    49             include_once ABSPATH . 'wp-admin/includes/template.php';
    50 
     56        include_once ABSPATH . 'wp-admin/includes/template.php';
     57
     58        list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins();
     59
     60        $upload_result = false;
     61
     62        if (
     63            ! empty( $_POST['_wpnonce'] )
     64            && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' )
     65            && 'upload' === $_POST['action']
     66            && ! $submitted_counts->total
     67            && ! empty( $_FILES['zip_file'] )
     68        ) {
     69            $upload_result = $uploader->process_upload();
     70
     71            if ( is_wp_error( $upload_result ) ) {
     72                $message = $upload_result->get_error_message();
     73            } else {
     74                $message = $upload_result;
     75            }
     76
     77            // Refresh the lists.
    5178            list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins();
    5279
    53             $upload_result = false;
    54 
    55             if (
    56                 ! empty( $_POST['_wpnonce'] )
    57                 && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' )
    58                 && 'upload' === $_POST['action']
    59                 && ! $submitted_counts->total
    60             ) {
    61                 if ( UPLOAD_ERR_OK === $_FILES['zip_file']['error'] ) {
    62                     $upload_result = $uploader->process_upload();
    63 
    64                     if ( is_wp_error( $upload_result ) ) {
    65                         $message = $upload_result->get_error_message();
    66                     } else {
    67                         $message = $upload_result;
    68                     }
    69 
    70                     // Refresh the lists.
    71                     list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins();
    72 
     80            if ( ! empty( $message ) ) {
     81                echo "<div class='notice notice-warning notice-alt'><p>{$message}</p></div>\n";
     82            }
     83        }
     84
     85        if ( ! is_wp_error( $upload_result ) ) :
     86            $plugins       = wp_count_posts( 'plugin', 'readable' );
     87            $oldest_plugin = get_posts( [ 'post_type' => 'plugin', 'post_status' => 'new', 'order' => 'ASC', 'orderby' => 'post_date_gmt', 'numberposts' => 1 ] );
     88            $queue_length  = floor( ( time() - strtotime( $oldest_plugin[0]->post_date_gmt ?? 'now' ) ) / DAY_IN_SECONDS );
     89            ?>
     90
     91            <div class="plugin-queue-message notice notice-info notice-alt">
     92                <p>
     93                <?php
     94                if ( 1 === (int) $plugins->new ) {
     95                    esc_html_e( 'Currently there is 1 plugin awaiting review.', 'wporg-plugins' );
    7396                } else {
    74                     $message = __( 'Error in file upload.', 'wporg-plugins' );
     97                    printf(
     98                        /* translators: %s: Amount of plugins awaiting review. */
     99                        esc_html( _n(
     100                            'Currently there is %s plugin awaiting review.',
     101                            'Currently there are %s plugins awaiting review.',
     102                            $plugins->new,
     103                            'wporg-plugins'
     104                        ) ),
     105                        '<strong>' . number_format_i18n( $plugins->new ) . '</strong>'
     106                    );
    75107                }
    76108
    77                 if ( ! empty( $message ) ) {
    78                     echo "<div class='notice notice-warning notice-alt'><p>{$message}</p></div>\n";
     109                // If the queue is currently beyond 10 days, display a warning to that effect.
     110                if ( $queue_length > 10 ) {
     111                    echo '</p><p>';
     112                    esc_html_e( 'The review queue is currently longer than normal, we apologize for the delays and ask for patience.', 'wporg-plugins' );
     113
     114                    echo '</p><p>';
     115                    printf(
     116                        /* translators: %s: Number of days. Only displayed if > 10 */
     117                        esc_html( _n(
     118                            'The current wait for an initial review is at least %s day.',
     119                            'The current wait for an initial review is at least %s days.',
     120                            $queue_length,
     121                            'wporg-plugins'
     122                        ) ),
     123                        '<strong>' . number_format_i18n( $queue_length ) . '</strong>'
     124                    );
     125                } else {
     126                    echo '</p><p>';
     127                    printf(
     128                        /* translators: plugins@wordpress.org */
     129                        __( 'Please wait at least 7 business days before asking for an update status from <a href="mailto:%1$s">%1$s</a>.', 'wporg-plugins' ),
     130                        'plugins@wordpress.org'
     131                    );
     132                    echo '</p>';
    79133                }
    80             }
    81 
    82             if ( ! is_wp_error( $upload_result ) ) :
    83                 $plugins       = wp_count_posts( 'plugin', 'readable' );
    84                 $oldest_plugin = get_posts( [ 'post_type' => 'plugin', 'post_status' => 'new', 'order' => 'ASC', 'orderby' => 'post_date_gmt', 'numberposts' => 1 ] );
    85                 $queue_length  = floor( ( time() - strtotime( $oldest_plugin[0]->post_date_gmt ?? 'now' ) ) / DAY_IN_SECONDS );
    86134                ?>
    87 
    88                 <div class="plugin-queue-message notice notice-info notice-alt">
     135                </p>
     136            </div>
     137
     138            <?php if ( $submitted_counts->total ) : ?>
     139
     140                <div class="plugin-queue-message notice notice-warning notice-alt">
    89141                    <p>
    90142                    <?php
    91                     if ( 1 === (int) $plugins->new ) {
    92                         esc_html_e( 'Currently there is 1 plugin awaiting review.', 'wporg-plugins' );
    93                     } else {
    94                         printf(
    95                             /* translators: %s: Amount of plugins awaiting review. */
    96                             esc_html( _n(
    97                                 'Currently there is %s plugin awaiting review.',
    98                                 'Currently there are %s plugins awaiting review.',
    99                                 $plugins->new,
     143                    if ( 0 !== $submitted_counts->approved ) {
     144                        printf(
     145                            /* translators: 1: Amount of approved plugins; 2: URL on how to use SVN */
     146                            wp_kses_post( _n(
     147                                'You have %1$s approved plugin that has not yet been used. We require developers to use the hosting we provide. Please upload your plugin via <a href="%2$s">SVN</a>.',
     148                                'You have %1$s approved plugins that have not yet been used. We require developers to use the hosting we provide. Please upload your plugins via <a href="%2$s">SVN</a>.',
     149                                $submitted_counts->approved,
    100150                                'wporg-plugins'
    101151                            ) ),
    102                             '<strong>' . number_format_i18n( $plugins->new ) . '</strong>'
    103                         );
    104                     }
    105 
    106                     // If the queue is currently beyond 10 days, display a warning to that effect.
    107                     if ( $queue_length > 10 ) {
    108                         echo '</p><p>';
    109                         esc_html_e( 'The review queue is currently longer than normal, we apologize for the delays and ask for patience.', 'wporg-plugins' );
    110 
    111                         echo '</p><p>';
    112                         printf(
    113                             /* translators: %s: Number of days. Only displayed if > 10 */
     152                            '<strong>' . $submitted_counts->approved . '</strong>',
     153                            'https://developer.wordpress.org/plugins/wordpress-org/how-to-use-subversion/'
     154                        );
     155                    } elseif ( 0 !== $submitted_counts->pending ) {
     156                        printf(
     157                            /* translators: %s: Amount of pending plugins. */
    114158                            esc_html( _n(
    115                                 'The current wait for an initial review is at least %s day.',
    116                                 'The current wait for an initial review is at least %s days.',
    117                                 $queue_length,
     159                                'You have %s plugin being actively reviewed and have been sent an email regarding issues. You must complete this review before you can submit another plugin. Please reply to that email with your corrected code attached or linked in order to proceed with the review.',
     160                                'You have %s plugins being actively reviewed and have been sent emails regarding issues. You must complete their reviews before you can submit another plugin. Please reply to the emails with your corrected code attached or linked in order to proceed with each review.',
     161                                $submitted_counts->pending,
    118162                                'wporg-plugins'
    119163                            ) ),
    120                             '<strong>' . number_format_i18n( $queue_length ) . '</strong>'
    121                         );
    122                     } else {
    123                         echo '</p><p>';
    124                         printf(
    125                             /* translators: plugins@wordpress.org */
    126                             __( 'Please wait at least 7 business days before asking for an update status from <a href="mailto:%1$s">%1$s</a>.', 'wporg-plugins' ),
    127                             'plugins@wordpress.org'
    128                         );
    129                         echo '</p>';
     164                            '<strong>' . $submitted_counts->pending . '</strong>'
     165                        );
     166                    } elseif ( 0 !== $submitted_counts->new ) {
     167                        printf(
     168                            /* translators: %s: Amount of new plugins. */
     169                            esc_html( _n(
     170                                'You have %s plugin that has been recently submitted but not yet reviewed. Please wait for your plugin to be reviewed and approved before submitting another.',
     171                                'You have %s plugins already submitted but not yet reviewed. Please wait for them to be reviewed and approved before submitting another plugin.',
     172                                $submitted_counts->new,
     173                                'wporg-plugins'
     174                            ) ),
     175                            '<strong>' . $submitted_counts->new . '</strong>'
     176                        );
    130177                    }
    131178                    ?>
    132179                    </p>
    133                 </div>
    134 
    135                 <?php if ( $submitted_counts->total ) : ?>
    136 
    137                     <div class="plugin-queue-message notice notice-warning notice-alt">
    138                         <p>
    139                         <?php
    140                         if ( 0 !== $submitted_counts->approved ) {
     180
     181                    <ul>
     182                    <?php
     183                    // List of all plugins in progress.
     184                    foreach ( $submitted_plugins as $plugin ) {
     185                        $can_change_slug = ! $plugin->{'_wporg_plugin_original_slug'};
     186
     187                        echo '<li>';
     188                            echo '<strong>' . esc_html( $plugin->post_title ) . '</strong>';
     189                            echo '<ul>';
    141190                            printf(
    142                                 /* translators: 1: Amount of approved plugins; 2: URL on how to use SVN */
    143                                 wp_kses_post( _n(
    144                                     'You have %1$s approved plugin that has not yet been used. We require developers to use the hosting we provide. Please upload your plugin via <a href="%2$s">SVN</a>.',
    145                                     'You have %1$s approved plugins that have not yet been used. We require developers to use the hosting we provide. Please upload your plugins via <a href="%2$s">SVN</a>.',
    146                                     $submitted_counts->approved,
    147                                     'wporg-plugins'
    148                                 ) ),
    149                                 '<strong>' . $submitted_counts->approved . '</strong>',
    150                                 'https://developer.wordpress.org/plugins/wordpress-org/how-to-use-subversion/'
     191                                '<li>%s</li>',
     192                                sprintf(
     193                                    __( 'Review status: %s', 'wporg-plugins' ),
     194                                    $plugin->status
     195                                )
    151196                            );
    152                         } elseif ( 0 !== $submitted_counts->pending ) {
     197                            echo '<li>';
    153198                            printf(
    154                                 /* translators: %s: Amount of pending plugins. */
    155                                 esc_html( _n(
    156                                     'You have %s plugin being actively reviewed and have been sent an email regarding issues. You must complete this review before you can submit another plugin. Please reply to that email with your corrected code attached or linked in order to proceed with the review.',
    157                                     'You have %s plugins being actively reviewed and have been sent emails regarding issues. You must complete their reviews before you can submit another plugin. Please reply to the emails with your corrected code attached or linked in order to proceed with each review.',
    158                                     $submitted_counts->pending,
    159                                     'wporg-plugins'
    160                                 ) ),
    161                                 '<strong>' . $submitted_counts->pending . '</strong>'
     199                                __( 'Current assigned slug: %s', 'wporg-plugins' ),
     200                                '<code>' . esc_html( $plugin->post_name ) . '</code>'
    162201                            );
    163                         } elseif ( 0 !== $submitted_counts->new ) {
    164                             printf(
    165                                 /* translators: %s: Amount of new plugins. */
    166                                 esc_html( _n(
    167                                     'You have %s plugin that has been recently submitted but not yet reviewed. Please wait for your plugin to be reviewed and approved before submitting another.',
    168                                     'You have %s plugins already submitted but not yet reviewed. Please wait for them to be reviewed and approved before submitting another plugin.',
    169                                     $submitted_counts->new,
    170                                     'wporg-plugins'
    171                                 ) ),
    172                                 '<strong>' . $submitted_counts->new . '</strong>'
    173                             );
    174                         }
    175                         ?>
    176                         </p>
    177 
    178                         <ul>
    179                         <?php
    180                         // List of all plugins in progress.
    181                         foreach ( $submitted_plugins as $plugin ) {
    182                             $can_change_slug = ! $plugin->{'_wporg_plugin_original_slug'};
    183 
    184                             echo '<li>';
    185                                 echo '<strong>' . esc_html( $plugin->post_title ) . '</strong>';
    186                                 echo '<ul>';
    187                                 printf(
    188                                     '<li>%s</li>',
    189                                     sprintf(
    190                                         __( 'Review status: %s', 'wporg-plugins' ),
    191                                         $plugin->status
    192                                     )
    193                                 );
    194                                 echo '<li>';
    195                                 printf(
    196                                     __( 'Current assigned slug: %s', 'wporg-plugins' ),
    197                                     '<code>' . esc_html( $plugin->post_name ) . '</code>'
    198                                 );
    199                                 ?>
    200                                 <?php if ( $can_change_slug ) : ?>
    201                                     <a href="#" class="hide-if-no-js" onclick="this.nextElementSibling.showModal()"><?php _e( 'change', 'wporg-plugins' ); ?></a>
    202                                     <dialog class="slug-change hide-if-no-js">
    203                                         <a onclick="this.parentNode.close()" class="close dashicons dashicons-no-alt"></a>
    204                                         <strong><?php _e( 'Request to change your plugin slug', 'wporg-plugins' ); ?></strong>
    205                                         <form>
    206                                             <input type="hidden" name="action" value="request-slug-change" />
    207                                             <input type="hidden" name="id" value="<?php echo esc_attr( $plugin->ID ); ?>" />
    208 
    209                                             <div class="notice notice-info notice-alt">
    210                                                 <p><?php _e( 'Your chosen slug cannot be guaranteed, and is subject to change based on the results of your review.', 'wporg-plugins' ); ?></p>
    211                                                 <p><?php
     202                            ?>
     203                            <?php if ( $can_change_slug ) : ?>
     204                                <a href="#" class="hide-if-no-js" onclick="this.nextElementSibling.showModal()"><?php _e( 'change', 'wporg-plugins' ); ?></a>
     205                                <dialog class="slug-change hide-if-no-js">
     206                                    <a onclick="this.parentNode.close()" class="close dashicons dashicons-no-alt"></a>
     207                                    <strong><?php _e( 'Request to change your plugin slug', 'wporg-plugins' ); ?></strong>
     208                                    <form>
     209                                        <input type="hidden" name="action" value="request-slug-change" />
     210                                        <input type="hidden" name="id" value="<?php echo esc_attr( $plugin->ID ); ?>" />
     211
     212                                        <div class="notice notice-info notice-alt">
     213                                            <p><?php _e( 'Your chosen slug cannot be guaranteed, and is subject to change based on the results of your review.', 'wporg-plugins' ); ?></p>
     214                                            <p><?php
     215                                                printf(
     216                                                    /* Translators: URL */
     217                                                    __( "Your slug is used to generate your plugins URL. Currently it's %s", 'wporg-plugins' ),
     218                                                    '<code>' . esc_url( home_url( $plugin->post_name ) . '/' ) . '</code>'
     219                                                );
     220                                            ?></p>
     221                                            <p><?php _e( 'Your slug (aka permalink) cannot be changed once your review is completed. Please choose carefully.', 'wporg-plugins' ); ?></p>
     222                                        </div>
     223                                        <div class="notice notice-error notice-alt hidden"><p></p></div>
     224                                        <p>
     225                                            <label>
     226                                                <strong><?php _e( 'Plugin Name', 'wporg-plugins' ); ?></strong><br>
     227                                                <?php echo esc_html( $plugin->post_title ); ?>
     228                                            </label>
     229                                        </p>
     230                                        <p>
     231                                            <label>
     232                                                <strong><?php _e( 'Desired Slug', 'wporg-plugins' ); ?></strong><br>
     233                                                <input type="text" name="post_name" required maxlength="200" pattern="[a-z0-9-]*" value="<?php echo esc_attr( $plugin->post_name ); ?>" />
     234                                            </label>
     235                                        </p>
     236
     237                                        <p>
     238                                            <label>
     239                                                <input type="checkbox" name="confirm" required />
     240                                                <?php
    212241                                                    printf(
    213                                                         /* Translators: URL */
    214                                                         __( "Your slug is used to generate your plugins URL. Currently it's %s", 'wporg-plugins' ),
    215                                                         '<code>' . esc_url( home_url( $plugin->post_name ) . '/' ) . '</code>'
     242                                                        /* Translators: URL to plugin guidelines */
     243                                                        __( 'I confirm that my slug choice <a href="%s">meets the guidelines for plugin slugs</a>.', 'wporg-plugins' ),
     244                                                        'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#17-plugins-must-respect-trademarks-copyrights-and-project-names'
    216245                                                    );
    217                                                 ?></p>
    218                                                 <p><?php _e( 'Your slug (aka permalink) cannot be changed once your review is completed. Please choose carefully.', 'wporg-plugins' ); ?></p>
    219                                             </div>
    220                                             <div class="notice notice-error notice-alt hidden"><p></p></div>
    221                                             <p>
    222                                                 <label>
    223                                                     <strong><?php _e( 'Plugin Name', 'wporg-plugins' ); ?></strong><br>
    224                                                     <?php echo esc_html( $plugin->post_title ); ?>
    225                                                 </label>
    226                                             </p>
    227                                             <p>
    228                                                 <label>
    229                                                     <strong><?php _e( 'Desired Slug', 'wporg-plugins' ); ?></strong><br>
    230                                                     <input type="text" name="post_name" required maxlength="200" pattern="[a-z0-9-]*" value="<?php echo esc_attr( $plugin->post_name ); ?>" />
    231                                                 </label>
    232                                             </p>
    233 
    234                                             <p>
    235                                                 <label>
    236                                                     <input type="checkbox" name="confirm" required />
    237                                                     <?php
    238                                                         printf(
    239                                                             /* Translators: URL to plugin guidelines */
    240                                                             __( 'I confirm that my slug choice <a href="%s">meets the guidelines for plugin slugs</a>.', 'wporg-plugins' ),
    241                                                             'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#17-plugins-must-respect-trademarks-copyrights-and-project-names'
    242                                                         );
    243                                                     ?>
    244                                                 </label>
    245                                             </p>
    246                                             <p>
    247                                                 <input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Request', 'wporg-plugins' ); ?>" />
    248                                             </p>
    249                                         </form>
    250                                     </dialog>
    251                                 <?php
    252                                 endif; // $can_change_slug
    253                                 echo '</li>';
    254                                 echo '</ul>';
    255                            
    256                             echo "</li>\n";
    257                         }
    258                         ?>
    259                         </ul>
    260                     </div>
    261 
    262                 <?php endif; // $submitted_counts->total ?>
    263 
    264             <?php endif; // ! is_wp_error( $upload_result ) ?>
    265 
    266             <?php
    267             if ( is_email_address_unsafe( wp_get_current_user()->user_email ) ) {
    268                 echo '<div class="notice notice-error notice-alt"><p>' .
    269                     sprintf(
    270                         /* translators: %s: Profile edit url. */
    271                         __( 'Your email host has email deliverability problems. Please <a href="%s">Update your email address</a> first.', 'wporg-plugins'),
    272                         esc_url( 'https://wordpress.org/support/users/' . wp_get_current_user()->user_nicename . '/edit' )
    273                      ) .
    274                      "</p></div>\n";
    275 
    276             } else if ( ! $submitted_counts->total && ( ! $upload_result || is_wp_error( $upload_result ) ) ) : ?>
    277 
    278                 <form id="upload_form" class="plugin-upload-form" enctype="multipart/form-data" method="POST" action="">
    279                     <?php wp_nonce_field( 'wporg-plugins-upload' ); ?>
    280                     <input type="hidden" name="action" value="upload"/>
    281                     <?php
    282                     if ( ! empty( $_REQUEST['upload_token'] ) ) {
    283                         printf(
    284                             '<input type="hidden" name="upload_token" value="%s"/>',
    285                             esc_attr( $_REQUEST['upload_token'] )
    286                         );
    287 
    288                         if ( ! $uploader->has_valid_upload_token() ) {
    289                             printf(
    290                                 '<div class="notice notice-error notice-alt"><p>%s</p></div>',
    291                                 esc_html__( 'The token provided is invalid for this user.', 'wporg-plugins')
    292                             );
    293                         }
     246                                                ?>
     247                                            </label>
     248                                        </p>
     249                                        <p>
     250                                            <input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Request', 'wporg-plugins' ); ?>" />
     251                                        </p>
     252                                    </form>
     253                                </dialog>
     254                            <?php
     255                            endif; // $can_change_slug
     256                            echo '</li>';
     257                            echo '</ul>';
     258                       
     259                        echo "</li>\n";
    294260                    }
    295261                    ?>
    296                     <?php
    297                     /*
    298                     <fieldset>
    299                         <legend><?php _e( 'Select categories (up to 3)', 'wporg-plugins' ); ?></legend>
    300                         <ul class="category-checklist">
    301                             <?php wp_terms_checklist( 0, array( 'taxonomy' => 'plugin_category' ) ); ?>
    302                         </ul>
    303                     </fieldset> */
    304 ?>
    305 
    306                     <input type="file" id="zip_file" class="plugin-file" name="zip_file" size="25" accept=".zip"/>
    307                     <label class="button button-secondary" for="zip_file"><?php _e( 'Select File', 'wporg-plugins' ); ?></label>
    308 
    309                     <p>
    310                         <small>
    311                             <?php
    312                             printf(
    313                                 /* translators: Maximum allowed file size. */
    314                                 esc_html__( 'Maximum allowed file size: %s', 'wporg-plugins' ),
    315                                 esc_html( size_format( wp_max_upload_size() ) )
    316                             );
    317                             ?>
    318                         </small>
    319                     </p>
    320 
    321                     <p>
    322                         <label>
    323                             <input type="checkbox" name="requirements[faq]" required="required">
    324                             <?php
    325                                 printf(
    326                                     __( 'I have read the <a href="%s">Frequently Asked Questions</a>.', 'wporg-plugins' ),
    327                                     'https://developer.wordpress.org/plugins/wordpress-org/plugin-developer-faq/'
    328                                 );
    329                             ?>
    330                         </label>
    331                         <br>
    332                         <label>
    333                             <input type="checkbox" name="requirements[guidelines]" required="required">
    334                             <?php
    335                                 printf(
    336                                     __( 'This plugin complies with all of the <a href="%s">Plugin Developer Guidelines</a>.', 'wporg-plugins' ),
    337                                     'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/'
    338                                 );
    339                             ?>
    340                         </label>
    341                         <br>
    342                         <label>
    343                             <input type="checkbox" name="requirements[author]" required="required">
    344                             <?php _e( 'I have permission to upload this plugin to WordPress.org for others to use and share.', 'wporg-plugins' ); ?>
    345                         </label>
    346                         <br>
    347                         <label>
    348                             <input type="checkbox" name="requirements[license]" required="required">
    349                             <?php _e( 'This plugin, all included libraries, and any other included assets are licenced as GPL or are under a GPL compatible license.', 'wporg-plugins' ); ?>
    350                         </label>
    351                     </p>
    352 
    353                     <input id="upload_button" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>"/>
    354                 </form>
    355 
     262                    </ul>
     263                </div>
     264
     265            <?php endif; // $submitted_counts->total ?>
     266
     267        <?php endif; // ! is_wp_error( $upload_result )
     268
     269        if ( is_email_address_unsafe( wp_get_current_user()->user_email ) ) {
     270            echo '<div class="notice notice-error notice-alt"><p>' .
     271                sprintf(
     272                    /* translators: %s: Profile edit url. */
     273                    __( 'Your email host has email deliverability problems. Please <a href="%s">Update your email address</a> first.', 'wporg-plugins'),
     274                    esc_url( 'https://wordpress.org/support/users/' . wp_get_current_user()->user_nicename . '/edit' )
     275                    ) .
     276                    "</p></div>\n";
     277
     278        } else if ( ! $submitted_counts->total && ( ! $upload_result || is_wp_error( $upload_result ) ) ) : ?>
     279            <form id="upload_form" class="plugin-upload-form" enctype="multipart/form-data" method="POST" action="">
     280                <?php wp_nonce_field( 'wporg-plugins-upload' ); ?>
     281                <input type="hidden" name="action" value="upload"/>
    356282                <?php
    357                 $upload_script = '
    358                     ( function ( $ ) {
    359                         var $label = $( "label.button" ),
    360                             labelText = $label.text();
    361                         $( "#zip_file" )
    362                             .on( "change", function( event ) {
    363                                 var fileName = event.target.value.split( "\\\\" ).pop();
    364                                 fileName ? $label.text( fileName ) : $label.text( labelText );
    365                             } )
    366                             .on( "focus", function() { $label.addClass( "focus" ); } )
    367                             .on( "blur", function() { $label.removeClass( "focus" ); } );
    368                     } ( window.jQuery ) );';
    369 
    370                 if ( ! wp_script_is( 'jquery', 'done' ) ) {
    371                     wp_enqueue_script( 'jquery' );
    372                     wp_add_inline_script( 'jquery-migrate', $upload_script );
    373                 } else {
    374                     printf( '<script>%s</script>', $upload_script );
     283                if ( ! empty( $_REQUEST['upload_token'] ) ) {
     284                    printf(
     285                        '<input type="hidden" name="upload_token" value="%s"/>',
     286                        esc_attr( $_REQUEST['upload_token'] )
     287                    );
     288
     289                    if ( ! $uploader->has_valid_upload_token() ) {
     290                        printf(
     291                            '<div class="notice notice-error notice-alt"><p>%s</p></div>',
     292                            esc_html__( 'The token provided is invalid for this user.', 'wporg-plugins')
     293                        );
     294                    }
    375295                }
    376296                ?>
    377 
    378             <?php endif; // ! $submitted_counts->total ?>
    379 
    380         <?php else : ?>
    381 
    382             <p>
     297                <?php
     298                /*
     299                <fieldset>
     300                    <legend><?php _e( 'Select categories (up to 3)', 'wporg-plugins' ); ?></legend>
     301                    <ul class="category-checklist">
     302                        <?php wp_terms_checklist( 0, array( 'taxonomy' => 'plugin_category' ) ); ?>
     303                    </ul>
     304                </fieldset> */
     305?>
     306
     307                <input type="file" id="zip_file" class="plugin-file" name="zip_file" size="25" accept=".zip"/>
     308                <label class="button button-secondary" for="zip_file"><?php _e( 'Select File', 'wporg-plugins' ); ?></label>
     309
     310                <p>
     311                    <small>
     312                        <?php
     313                        printf(
     314                            /* translators: Maximum allowed file size. */
     315                            esc_html__( 'Maximum allowed file size: %s', 'wporg-plugins' ),
     316                            esc_html( size_format( wp_max_upload_size() ) )
     317                        );
     318                        ?>
     319                    </small>
     320                </p>
     321
     322                <p>
     323                    <label>
     324                        <input type="checkbox" name="requirements[faq]" required="required">
     325                        <?php
     326                            printf(
     327                                __( 'I have read the <a href="%s">Frequently Asked Questions</a>.', 'wporg-plugins' ),
     328                                'https://developer.wordpress.org/plugins/wordpress-org/plugin-developer-faq/'
     329                            );
     330                        ?>
     331                    </label>
     332                    <br>
     333                    <label>
     334                        <input type="checkbox" name="requirements[guidelines]" required="required">
     335                        <?php
     336                            printf(
     337                                __( 'This plugin complies with all of the <a href="%s">Plugin Developer Guidelines</a>.', 'wporg-plugins' ),
     338                                'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/'
     339                            );
     340                        ?>
     341                    </label>
     342                    <br>
     343                    <label>
     344                        <input type="checkbox" name="requirements[author]" required="required">
     345                        <?php _e( 'I have permission to upload this plugin to WordPress.org for others to use and share.', 'wporg-plugins' ); ?>
     346                    </label>
     347                    <br>
     348                    <label>
     349                        <input type="checkbox" name="requirements[license]" required="required">
     350                        <?php _e( 'This plugin, all included libraries, and any other included assets are licenced as GPL or are under a GPL compatible license.', 'wporg-plugins' ); ?>
     351                    </label>
     352                </p>
     353
     354                <input id="upload_button" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>"/>
     355            </form>
     356
    383357            <?php
    384             printf(
    385                 /* translators: Login URL */
    386                 __( 'Before you can upload a new plugin, <a href="%s">please log in</a>.', 'wporg-plugins' ),
    387                 esc_url( wp_login_url() )
    388             );
     358            $upload_script = '
     359                ( function ( $ ) {
     360                    var $label = $( "label.button" ),
     361                        labelText = $label.text();
     362                    $( "#zip_file" )
     363                        .on( "change", function( event ) {
     364                            var fileName = event.target.value.split( "\\\\" ).pop();
     365                            fileName ? $label.text( fileName ) : $label.text( labelText );
     366                        } )
     367                        .on( "focus", function() { $label.addClass( "focus" ); } )
     368                        .on( "blur", function() { $label.removeClass( "focus" ); } );
     369                } ( window.jQuery ) );';
     370
     371            if ( ! wp_script_is( 'jquery', 'done' ) ) {
     372                wp_enqueue_script( 'jquery' );
     373                wp_add_inline_script( 'jquery-migrate', $upload_script );
     374            } else {
     375                printf( '<script>%s</script>', $upload_script );
     376            }
    389377            ?>
    390             </p>
    391 
    392         <?php
    393         endif; // is_user_logged_in()
     378
     379        <?php endif; // ! $submitted_counts->total
    394380
    395381        return ob_get_clean();
Note: See TracChangeset for help on using the changeset viewer.