Making WordPress.org

Changeset 14979


Ignore:
Timestamp:
07/17/2026 04:22:01 PM (3 weeks ago)
Author:
obenland
Message:

Plugin Directory: Better prevention against duplicate plugin submissions

Props frantorres, obenland, timse201.
Closes https://github.com/WordPress/wordpress.org/pull/698.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 edited

Legend:

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

    r14974 r14979  
    9898                        )
    9999                ) {
    100                         $for_plugin    = absint( $_POST['plugin_id'] ?? 0 );
    101                         $upload_result = $uploader->process_upload( $for_plugin );
     100                        $for_plugin = absint( $_POST['plugin_id'] ?? 0 );
     101
     102                        // Lock to prevent duplicate submissions from double-clicks or page reloads
     103                        $lock_key = 'plugin_upload_lock_' . get_current_user_id() . '_' . $for_plugin;
     104                        if ( false === wp_cache_add( $lock_key, time(), 'wporg-plugins', 5 * MINUTE_IN_SECONDS ) ) {
     105                                $upload_result = new \WP_Error(
     106                                        'upload_in_progress',
     107                                        __( 'Your previous upload is still being processed. Please wait a moment before trying again.', 'wporg-plugins' )
     108                                );
     109                        } else {
     110                                $upload_result = $uploader->process_upload( $for_plugin );
     111                                wp_cache_delete( $lock_key, 'wporg-plugins' );
     112                        }
    102113
    103114                        if ( is_wp_error( $upload_result ) ) {
     
    369380                                                                        </label>
    370381
    371                                                                         <input class="upload-button wp-block-button__link" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ) ?>"/>
     382                                                                        <input class="upload-button wp-block-button__link" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>" data-uploading-label="<?php esc_attr_e( 'Uploading…', 'wporg-plugins' ); ?>"/>
    372383                                                                </form>
    373384                                                                <?php
     
    630641                                </p>
    631642
    632                                 <input id="upload_button" class="wp-block-button__link" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>"/>
     643                                <input id="upload_button" class="wp-block-button__link" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>" data-uploading-label="<?php esc_attr_e( 'Uploading…', 'wporg-plugins' ); ?>"/>
    633644                        </form>
    634645                <?php endif; // $can_submit_new_plugin
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/js/upload.js

    r13109 r14979  
    5050        } );
    5151
     52        // Prevent duplicate submissions by disabling the submit button
     53        $( 'form.plugin-upload-form' ).on( 'submit', function() {
     54                var $button = $(this).find( 'input[type="submit"]' ),
     55                        uploadingLabel = $button.data( 'uploadingLabel' );
     56
     57                $button.prop( 'disabled', true );
     58
     59                if ( uploadingLabel ) {
     60                        $button.val( uploadingLabel );
     61                }
     62        } );
     63
    5264})( jQuery );
Note: See TracChangeset for help on using the changeset viewer.