Skip to content

Commit 9df7602

Browse files
committed
chore: Remove unused codes, Update plugin-upload.js
1 parent 35092c2 commit 9df7602

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/js/_enqueues/admin/plugin-upload.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function pluginUploadSuccess( fileObj, serverData ) {
107107
);
108108
}
109109
action_selector.append(
110-
`<li><button class="button activate-button cancel-overwrite" data-file="${fileObj.id}" data-attachment="${ data.attachment_id }"> ${ plugin_upload_intl.cancel } </button></li>`
110+
`<li><button class="button activate-button cancel-overwrite" data-file="${ fileObj.id }" data-attachment="${ data.attachment_id }"> ${ plugin_upload_intl.cancel } </button></li>`
111111
);
112112
action_selector.append(
113113
`<li><a href="#TB_inline?&inlineId=plugin-modal-window-${ fileObj.id }&width=700" class="thickbox" data-title="${ data.plugin.Name } ${ data.plugin.Version }">${ plugin_upload_intl.more_details }</a></li>`
@@ -132,7 +132,7 @@ function pluginUploadSuccess( fileObj, serverData ) {
132132
} );
133133
} else {
134134
action_selector.append(
135-
`<li><button class="button activate-button activate-plugin button-primary" data-name="${data.plugin.Name}" data-path="${data.path}"> ${ plugin_upload_intl.activate } </button></li>`
135+
`<li><button class="button activate-button activate-plugin button-primary" data-name="${ data.plugin.Name }" data-path="${ data.path }"> ${ plugin_upload_intl.activate } </button></li>`
136136
);
137137

138138
jQuery( '.button.activate-plugin' )
@@ -141,7 +141,7 @@ function pluginUploadSuccess( fileObj, serverData ) {
141141
const button = jQuery( this );
142142
const path = button.data( 'path' );
143143
const name = button.data( 'name' );
144-
activatePlugin( path,name, button );
144+
activatePlugin( path, name, button );
145145
} );
146146
}
147147
}
@@ -176,47 +176,50 @@ function overwritePlugin( attachment_id, button ) {
176176
const formData = new FormData();
177177
formData.append( '_wpnonce', upload_plugin_nonce );
178178
formData.append( 'action', 'upload-plugin' );
179-
button.prop( 'disabled', true );
179+
button.prop( 'disabled', true );
180180
button.text( plugin_upload_intl.processing + '...' );
181-
181+
const cancel_overwrite_button = button.parent().parent().find( '.cancel-overwrite' );
182+
cancel_overwrite_button.prop( 'disabled', true );
182183
jQuery.ajax( {
183184
type: 'POST',
184185
url: ajaxurl + '?package=' + attachment_id + '&overwrite=update-plugin',
185186
data: formData,
186187
processData: false, // Important: tell jQuery not to process the data.
187188
contentType: false, // Important: tell jQuery not to set contentType.
188189

189-
success: function ( ) {
190+
success: function () {
190191
button.text( plugin_upload_intl.updated );
191192
},
192-
error: function ( ) {
193+
error: function () {
193194
button.prop( 'disabled', false );
195+
cancel_overwrite_button.prop( 'disabled', false );
194196
button.text( plugin_upload_intl.activation_failed );
195197
},
196198
} );
197199
}
198200

199-
function cancelOverwritePlugin( file_id ,attachment_id, button ) {
200-
const formData = new FormData();
201+
function cancelOverwritePlugin( file_id, attachment_id, button ) {
202+
const formData = new FormData();
201203
formData.append( '_wpnonce', cancel_overwrite_nonce );
202204
formData.append( 'action', 'cancel-plugin-overwrite' );
203205
button.prop( 'disabled', true );
204206
button.text( plugin_upload_intl.processing + '...' );
205-
207+
const overwrite_button = button.parent().parent().find( '.overwrite-plugin' );
208+
overwrite_button.prop( 'disabled', true );
206209
jQuery.ajax( {
207210
type: 'POST',
208211
url: ajaxurl + '?package=' + attachment_id,
209212
data: formData,
210213
processData: false, // Important: tell jQuery not to process the data.
211214
contentType: false, // Important: tell jQuery not to set contentType.
212215

213-
success: function ( ) {
216+
success: function () {
214217
// Remove element from the dom.
215-
jQuery( '#plugin-item-' + file_id ).remove();
216-
218+
jQuery( '#plugin-item-' + file_id ).remove();
217219
},
218-
error: function ( ) {
220+
error: function () {
219221
button.prop( 'disabled', false );
222+
overwrite_button.prop( 'disabled', false );
220223
button.text( plugin_upload_intl.cancel_failed );
221224
},
222225
} );
@@ -237,10 +240,10 @@ function activatePlugin( path, name, button ) {
237240
processData: false, // Important: tell jQuery not to process the data
238241
contentType: false, // Important: tell jQuery not to set contentType
239242

240-
success: function ( ) {
243+
success: function () {
241244
button.text( plugin_upload_intl.activated );
242245
},
243-
error: function ( ) {
246+
error: function () {
244247
button.prop( 'disabled', false );
245248
button.text( plugin_upload_intl.failed );
246249
},

src/wp-admin/includes/ajax-actions.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,7 +4570,6 @@ function wp_ajax_upload_plugin() {
45704570
}
45714571

45724572
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
4573-
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
45744573
$file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
45754574

45764575
$nonce = 'upload-plugin';
@@ -4587,7 +4586,7 @@ function wp_ajax_upload_plugin() {
45874586
$status = array();
45884587
$plugin = $skin->upgrader->new_plugin_data;
45894588

4590-
$can_override = $skin->can_override_plugin();
4589+
$can_override = $skin->can_overwrite_plugin();
45914590

45924591
if ( $can_override ) {
45934592
$status['successCode'] = 'can_override';

src/wp-admin/includes/class-wp-ajax-upgrader-skin.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public function get_error_messages() {
102102
}
103103

104104
/**
105-
* Checks if the plugin can be overwritten and outputs the HTML for overwriting a plugin on upload.
105+
* Checks if the plugin can be overwritten and outputs an array of changes for overwriting a plugin on upload.
106106
*
107107
* @since 6.9.0
108108
*
109109
* @return bool|array Whether the plugin can be overwritten and an array of changes returned.
110110
*/
111-
public function can_override_plugin() {
111+
public function can_overwrite_plugin() {
112112
if ( ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
113113
return false;
114114
}
@@ -135,10 +135,9 @@ public function can_override_plugin() {
135135

136136
$rows = array(
137137
'Downgrade' => version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' ),
138-
'Plugin' => array( __( 'Old' ), __( 'New' ) ),
139138
);
140139

141-
$fields = array( __( 'Name' ), __( 'Version' ), __( 'Author' ), __( 'RequiresWP' ), __( 'RequiresPHP' ) );
140+
$fields = array( 'Name', 'Version', 'Author', 'RequiresWP', 'RequiresPHP' );
142141

143142
$is_same_plugin = true; // Let's consider only these rows.
144143

0 commit comments

Comments
 (0)