Making WordPress.org


Ignore:
Timestamp:
01/15/2024 05:23:52 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Allow plugins to upload additional versions for review.

This is currently limited to new plugins, which is prior to the first human review.

Iterations upon this will open it to plugins in the pending state as well, which is during the human review.

See #7384.

File:
1 edited

Legend:

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

    r12793 r13109  
    5252        ob_start();
    5353
    54         $uploader = new Upload_Handler();
    55 
    5654        include_once ABSPATH . 'wp-admin/includes/template.php';
    5755
     56        $uploader      = new Upload_Handler();
     57        $upload_result = false;
     58
    5859        list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins();
    5960
    60         $upload_result = false;
    61 
    6261        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'] )
     62            ! empty( $_POST['_wpnonce'] ) &&
     63            ! empty( $_FILES['zip_file'] ) &&
     64            (
     65                // New submission.
     66                ! $submitted_counts->total &&
     67                empty( $_POST['plugin_id'] ) &&
     68                wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' ) &&
     69                'upload' === $_POST['action']
     70            ) || (
     71                // Existing submission
     72                ! empty( $_POST['plugin_id'] ) &&
     73                'upload-additional' === $_POST['action'] &&
     74                wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload-' . $_POST['plugin_id'] )
     75            )
    6876        ) {
    69             $upload_result = $uploader->process_upload();
     77            $for_plugin    = absint( $_POST['plugin_id'] ?? 0 );
     78            $upload_result = $uploader->process_upload( $for_plugin );
    7079
    7180            if ( is_wp_error( $upload_result ) ) {
     81                $type    = 'error';
    7282                $message = $upload_result->get_error_message();
    7383            } else {
     84                $type    = 'success';
    7485                $message = $upload_result;
    7586            }
     
    7990
    8091            if ( ! empty( $message ) ) {
    81                 echo "<div class='notice notice-warning notice-alt'><p>{$message}</p></div>\n";
     92                echo "<div class='notice notice-{$type} notice-alt'><p>{$message}</p></div>\n";
    8293            }
    8394        }
    8495
    85         if ( ! is_wp_error( $upload_result ) ) :
     96        if ( ! is_wp_error( $upload_result ) || $submitted_counts->total ) :
    8697            $plugins       = wp_count_posts( 'plugin', 'readable' );
    8798            $oldest_plugin = get_posts( [ 'post_type' => 'plugin', 'post_status' => 'new', 'order' => 'ASC', 'orderby' => 'post_date_gmt', 'numberposts' => 1 ] );
     
    183194                    // List of all plugins in progress.
    184195                    foreach ( $submitted_plugins as $plugin ) {
    185                         $can_change_slug = ( 'new' === $plugin->post_status && ! $plugin->{'_wporg_plugin_original_slug'} );
     196                        $can_change_slug   = ( 'new' === $plugin->post_status && ! $plugin->{'_wporg_plugin_original_slug'} );
     197                        $can_upload_extras = in_array( $plugin->post_status, array( 'new', /* 'pending' */ ), true );
    186198
    187199                        echo '<li>';
     
    258270                            endif; // $can_change_slug
    259271                            echo '</li>';
     272
     273                            echo '<li>';
     274                            $attached_media = get_attached_media( 'application/zip', $plugin );
     275
     276                            echo '<strong>' . __( 'Submitted files:', 'wporg' ) . '</strong><ol>';
     277                            foreach ( $attached_media as $upload ) {
     278                                echo '<li><ul>';
     279                                $filename = $upload->submitted_name ?: preg_replace( '!^[0-9-_]+!', '', basename( get_attached_file( $upload->ID ) ) );
     280                                $version  = $upload->version ?: $plugin->version;
     281
     282                                echo '<li><code>' . esc_html( $filename ) . '</code></li>';
     283                                echo '<li>' . sprintf( __( 'Version: %s', 'wporg-plugins' ), '<code>' . esc_html( $version ) . '</code>' ) . '</li>';
     284                                echo '<li>' . sprintf( __( 'Upload Date: %s', 'wporg-plugins' ), date_i18n( get_option( 'date_format' ), strtotime( $upload->post_date ) ) ) . '</li>';
     285                                echo '</ul></li>';
     286                            }
     287                            if ( $can_upload_extras ) {
     288                                echo '<li class="unmarked-list"><a href="#" class="show-upload-additional hide-if-no-js">' . sprintf( __( 'Upload new version of %s for review.', 'wporg-plugins' ), esc_html( $plugin->post_title ) ) . '</a>';
     289                            }
     290                            echo '</ol>';
     291
     292                            if ( $can_upload_extras ) {
     293                                ?>
     294                                <form class="plugin-upload-form hidden" enctype="multipart/form-data" method="POST" action="">
     295                                    <?php wp_nonce_field( 'wporg-plugins-upload-' . $plugin->ID ); ?>
     296                                    <input type="hidden" name="action" value="upload-additional"/>
     297                                    <input type="hidden" name="plugin_id" value="<?php echo esc_attr( $plugin->ID ); ?>" />
     298
     299                                    <label class="button button-secondary zip-file">
     300                                        <input type="file" class="plugin-file" name="zip_file" size="25" accept=".zip" required data-maxbytes="<?php echo esc_attr( wp_max_upload_size() ); ?>" />
     301                                        <span><?php _e( 'Select File', 'wporg-plugins' ); ?></span>
     302                                    </label>
     303
     304                                    <input class="upload-button button button-primary" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ) ?>"/>
     305                                </form>
     306                                <?php
     307                            }
     308                            echo '</li>';
    260309                            echo '</ul>';
    261                        
    262310                        echo "</li>\n";
    263311                    }
     
    306354                    </ul>
    307355                </fieldset> */
    308 ?>
    309 
    310                 <input type="file" id="zip_file" class="plugin-file" name="zip_file" size="25" accept=".zip" required data-maxbytes="<?php echo esc_attr( wp_max_upload_size() ); ?>" />
    311                 <label class="button button-secondary" for="zip_file"><?php _e( 'Select File', 'wporg-plugins' ); ?></label>
     356                ?>
     357
     358                <label class="button button-secondary zip-file">
     359                    <input type="file" class="plugin-file" name="zip_file" size="25" accept=".zip" required data-maxbytes="<?php echo esc_attr( wp_max_upload_size() ); ?>" />
     360                    <span><?php _e( 'Select File', 'wporg-plugins' ); ?></span>
     361                </label>
    312362
    313363                <p>
     
    357407                <input id="upload_button" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>"/>
    358408            </form>
    359 
    360             <?php
    361             $upload_script = '
    362                 ( function ( $ ) {
    363                     var $label = $( "label.button" ),
    364                         labelText = $label.text();
    365                     $( "#zip_file" )
    366                         .on( "change", function( event ) {
    367                             var fileName = event.target.value.split( "\\\\" ).pop(),
    368                                 fileSize = event.target.files[0].size || 0;
    369 
    370                             if ( fileSize > $(this).data( "maxbytes" ) ) {
    371                                 event.target.value = "";
    372                                 fileName = false;
    373                             }
    374 
    375                             fileName ? $label.text( fileName ) : $label.text( labelText );
    376                         } )
    377                         .on( "focus", function() { $label.addClass( "focus" ); } )
    378                         .on( "blur", function() { $label.removeClass( "focus" ); } );
    379                 } ( window.jQuery ) );';
    380 
    381             if ( ! wp_script_is( 'jquery', 'done' ) ) {
    382                 wp_enqueue_script( 'jquery' );
    383                 wp_add_inline_script( 'jquery-migrate', $upload_script );
    384             } else {
    385                 printf( '<script>%s</script>', $upload_script );
    386             }
    387             ?>
    388 
    389409        <?php endif; // ! $submitted_counts->total
    390410
Note: See TracChangeset for help on using the changeset viewer.