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' );
}

if ( is_wp_error( $upload_result ) ) {
$type = 'error';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ function scripts() {
// The plugin submission page: /developers/add/
if ( is_page( 'add' ) ) {
wp_enqueue_script( 'wporg-plugins-upload', get_stylesheet_directory_uri() . '/js/upload.js', array( 'wp-api', 'jquery' ), filemtime( __DIR__ . '/js/upload.js' ), true );

wp_localize_script(
'wporg-plugins-upload',
'pluginUpload',
array(
'l10n' => array(
'uploading' => __( 'Uploading…', 'wporg-plugins' ),
),
)
);
}

// No Jetpack scripts needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@
$(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"]' );

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

if ( ! $button.data( 'defaultValue' ) ) {
$button.data( 'defaultValue', $button.val() );
}

if ( 'undefined' !== typeof pluginUpload && pluginUpload.l10n && pluginUpload.l10n.uploading ) {
$button.val( pluginUpload.l10n.uploading );
}
} );

})( jQuery );
Loading