Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,19 @@ public static function display() {
wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload-' . $_POST['plugin_id'] )
)
) {
$for_plugin = absint( $_POST['plugin_id'] ?? 0 );
$upload_result = $uploader->process_upload( $for_plugin );
$for_plugin = absint( $_POST['plugin_id'] ?? 0 );

// Lock to prevent duplicate submissions from double-clicks or page reloads
$lock_key = 'plugin_upload_lock_' . get_current_user_id() . '_' . $for_plugin;
if ( false === wp_cache_add( $lock_key, time(), 'wporg-plugins', 5 * MINUTE_IN_SECONDS ) ) {
$upload_result = new \WP_Error(
'upload_in_progress',
__( 'Your previous upload is still being processed. Please wait a moment before trying again.', 'wporg-plugins' )
);
} else {
$upload_result = $uploader->process_upload( $for_plugin );
wp_cache_delete( $lock_key, 'wporg-plugins' );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this strictly needed? Maybe we could try disabling the button first and see how it goes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the feedback given I suspect that they think the process is stuck, they open a new window or reload the page and submit it again (while it is still processing), so yes, this would be needed.

Disabling the button is an additional just-in-case, but looks that the lock is the main thing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't fail with a duplicate slug?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't, when the duplicated submissions happen the system adds a number to the slug.
For example for a plugin under the name "PRT SEO" we receive prt-seo, prt-seo-2, prt-seo-3 and so on.


if ( is_wp_error( $upload_result ) ) {
$type = 'error';
Expand Down Expand Up @@ -368,7 +379,7 @@ public static function display() {
<span><?php _e( 'Select File', 'wporg-plugins' ); ?></span>
</label>

<input class="upload-button wp-block-button__link" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ) ?>"/>
<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' ); ?>"/>
</form>
<?php
echo '</div>';
Expand Down Expand Up @@ -569,7 +580,7 @@ public static function display() {
</label>
</p>

<input id="upload_button" class="wp-block-button__link" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>"/>
<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' ); ?>"/>
</form>
<?php endif; // $can_submit_new_plugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@
$(this).hide().parents('ul').find('.plugin-upload-form.hidden').removeClass( 'hidden' );
} );

// Prevent duplicate submissions by disabling the submit button
$( 'form.plugin-upload-form' ).on( 'submit', function() {
var $button = $(this).find( 'input[type="submit"]' ),
uploadingLabel = $button.data( 'uploadingLabel' );

$button.prop( 'disabled', true );

if ( uploadingLabel ) {
$button.val( uploadingLabel );
}
} );

})( jQuery );
Loading