Changeset 3467419
- Timestamp:
- 02/23/2026 08:57:15 AM (6 weeks ago)
- Location:
- divewp-boost-site-performance/trunk
- Files:
-
- 4 edited
-
README.txt (modified) (1 diff)
-
assets/css/features/plugins-management.css (modified) (1 diff)
-
assets/js/divewp-plugins-management.js (modified) (4 diffs)
-
includes/features/plugins-management/class-plugins-management.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
divewp-boost-site-performance/trunk/README.txt
r3467366 r3467419 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.2 7 Stable tag: 2.3. 07 Stable tag: 2.3.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
divewp-boost-site-performance/trunk/assets/css/features/plugins-management.css
r3467366 r3467419 305 305 background-color: #2563eb; 306 306 border-color: #2563eb; 307 } 308 309 .divewp-plugins-drawer__update.button-success { 310 background-color: #16a34a; 311 border-color: #16a34a; 312 color: #fff; 313 } 314 315 .divewp-plugins-drawer__update.button-danger { 316 background-color: #dc2626; 317 border-color: #dc2626; 318 color: #fff; 307 319 } 308 320 -
divewp-boost-site-performance/trunk/assets/js/divewp-plugins-management.js
r3467366 r3467419 61 61 e.preventDefault(); 62 62 handleTogglePlugin(); 63 }); 64 65 // Update Button (AJAX in-modal update) 66 $(document).on('click', '.divewp-plugins-drawer__action[data-action="update"]', function(e) { 67 e.preventDefault(); 68 handleUpdatePlugin(); 63 69 }); 64 70 … … 381 387 // Update button visibility 382 388 if (hasUpdate) { 383 const updateUrl = getUpdateUrl(pluginFile); 384 updateBtn.attr('href', updateUrl).show(); 389 updateBtn.show(); 385 390 } else { 386 391 updateBtn.hide(); … … 964 969 965 970 /** 971 * Handle AJAX plugin update inside the drawer 972 */ 973 function handleUpdatePlugin() { 974 var drawer = $('.divewp-plugins-drawer'); 975 var pluginFile = drawer.data('plugin-file'); 976 var $card = drawer.data('plugin-card'); 977 var $updateBtn = drawer.find('.divewp-plugins-drawer__update'); 978 var $updateLabel = $updateBtn.find('.update-label'); 979 var $toggleBtn = drawer.find('.divewp-plugins-drawer__action[data-action="toggle"]'); 980 981 if (!pluginFile) { 982 alert(divewpPluginsData.strings.error); 983 return; 984 } 985 986 $updateBtn.prop('disabled', true); 987 $toggleBtn.prop('disabled', true); 988 $updateLabel.text(divewpPluginsData.strings.updating); 989 990 $.ajax({ 991 url: divewpPluginsData.ajaxurl, 992 type: 'POST', 993 data: { 994 action: 'divewp_update_plugin', 995 plugin_file: pluginFile, 996 nonce: divewpPluginsData.nonce 997 }, 998 success: function(response) { 999 if (response.success && response.data) { 1000 var result = response.data; 1001 var successMsg = divewpPluginsData.strings.updateSuccess 1002 .replace('%1$s', result.previous_version || '') 1003 .replace('%2$s', result.new_version || ''); 1004 1005 $updateLabel.text(successMsg); 1006 $updateBtn.removeClass('button-primary').addClass('button-success'); 1007 1008 // Update card data 1009 if ($card) { 1010 $card.data('plugin-version', result.new_version); 1011 $card.attr('data-plugin-version', result.new_version); 1012 $card.data('plugin-update', 0); 1013 $card.attr('data-plugin-update', '0'); 1014 $card.data('plugin-update-version', ''); 1015 $card.attr('data-plugin-update-version', ''); 1016 1017 $card.find('.divewp-plugin-version').text('v' + result.new_version); 1018 1019 updateCardStatus($card, result.is_active); 1020 } 1021 1022 // Hide update button after short delay 1023 setTimeout(function() { 1024 $updateBtn.fadeOut(300); 1025 }, 2000); 1026 1027 // Invalidate caches 1028 delete pluginDetailsCache[pluginFile]; 1029 delete pluginVersionsCache[pluginFile]; 1030 1031 // Update drawer state 1032 drawer.data('plugin-is-active', result.is_active); 1033 1034 // Update overview content to reflect new version 1035 var cachedOverview = drawer.data('overview-content') || ''; 1036 if (cachedOverview && result.previous_version) { 1037 cachedOverview = cachedOverview.replace( 1038 escapeHtml(result.previous_version), 1039 escapeHtml(result.new_version) 1040 ); 1041 // Remove "Update Available" row from overview 1042 cachedOverview = cachedOverview.replace( 1043 /<div class="divewp-plugin-details__item">[\s\S]*?Update Available[\s\S]*?<\/div>/, 1044 '' 1045 ); 1046 drawer.data('overview-content', cachedOverview); 1047 } 1048 1049 updateFilterCounts(); 1050 } else { 1051 var errorMsg = (response.data && response.data.message) ? response.data.message : divewpPluginsData.strings.updateError; 1052 $updateLabel.text(errorMsg); 1053 $updateBtn.removeClass('button-primary').addClass('button-danger'); 1054 1055 setTimeout(function() { 1056 $updateBtn.removeClass('button-danger').addClass('button-primary'); 1057 $updateLabel.text(divewpPluginsData.strings.updatePlugin); 1058 $updateBtn.prop('disabled', false); 1059 }, 3000); 1060 } 1061 }, 1062 error: function() { 1063 $updateLabel.text(divewpPluginsData.strings.updateError); 1064 $updateBtn.removeClass('button-primary').addClass('button-danger'); 1065 1066 setTimeout(function() { 1067 $updateBtn.removeClass('button-danger').addClass('button-primary'); 1068 $updateLabel.text(divewpPluginsData.strings.updatePlugin); 1069 $updateBtn.prop('disabled', false); 1070 }, 3000); 1071 }, 1072 complete: function() { 1073 $toggleBtn.prop('disabled', false); 1074 } 1075 }); 1076 } 1077 1078 /** 966 1079 * Update card status badges after toggle 967 1080 */ … … 1027 1140 } 1028 1141 1029 /**1030 * Get update plugin URL for WordPress update handler1031 */1032 function getUpdateUrl(pluginFile) {1033 const nonce = divewpPluginsData.updateNonce || divewpPluginsData.nonce;1034 return ajaxurl.replace('/admin-ajax.php', '/update.php') + '?action=upgrade-plugin&plugin=' + encodeURIComponent(pluginFile) + '&_wpnonce=' + encodeURIComponent(nonce);1035 }1036 1037 1142 // ========================================================================= 1038 1143 // Listen for filter bar events (from reusable divewp-filter-bar.js) -
divewp-boost-site-performance/trunk/includes/features/plugins-management/class-plugins-management.php
r3467366 r3467419 30 30 add_action('wp_ajax_divewp_get_plugin_versions', array($this, 'handle_get_plugin_versions')); 31 31 add_action('wp_ajax_divewp_rollback_plugin_version', array($this, 'handle_rollback_plugin_version')); 32 add_action('wp_ajax_divewp_update_plugin', array($this, 'handle_update_plugin')); 32 33 add_action('wp_ajax_divewp_get_plugin_ratings_batch', array($this, 'handle_get_plugin_ratings_batch')); 33 34 add_action('wp_ajax_divewp_get_plugin_icons_batch', array($this, 'handle_get_plugin_icons_batch')); … … 131 132 'noReviewsFound' => __('No reviews found for this plugin.', 'divewp-boost-site-performance'), 132 133 'viewAllReviews' => __('View all reviews on WordPress.org', 'divewp-boost-site-performance'), 134 'updating' => __('Updating…', 'divewp-boost-site-performance'), 135 'updatePlugin' => __('Update Plugin', 'divewp-boost-site-performance'), 136 /* translators: 1: Previous version number, 2: New version number after update. */ 137 'updateSuccess' => __('Successfully updated from v%1$s to v%2$s.', 'divewp-boost-site-performance'), 138 'updateError' => __('Update failed. Please try again.', 'divewp-boost-site-performance'), 133 139 /* translators: %s: number of ratings */ 134 140 'ratingsCount' => __('%s ratings', 'divewp-boost-site-performance'), … … 477 483 <span class="action-label"><?php esc_html_e('Toggle', 'divewp-boost-site-performance'); ?></span> 478 484 </button> 479 < a href="#" class="button button-primary divewp-plugins-drawer__action divewp-plugins-drawer__update" style="display:none;">485 <button type="button" class="button button-primary divewp-plugins-drawer__action divewp-plugins-drawer__update" data-action="update" style="display:none;"> 480 486 <span class="dashicons dashicons-update"></span> 481 < ?php esc_html_e('Update Plugin', 'divewp-boost-site-performance'); ?>482 </ a>487 <span class="update-label"><?php esc_html_e('Update Plugin', 'divewp-boost-site-performance'); ?></span> 488 </button> 483 489 </div> 484 490 </div> … … 1387 1393 } 1388 1394 } 1395 1396 /** 1397 * AJAX handler for updating a plugin to its latest version 1398 * 1399 * Uses Plugin_Upgrader with Automatic_Upgrader_Skin for silent in-modal update. 1400 * 1401 * @return void 1402 */ 1403 public function handle_update_plugin() { 1404 if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'divewp_plugins_nonce')) { 1405 wp_send_json_error(array('message' => esc_html__('Invalid nonce.', 'divewp-boost-site-performance'))); 1406 return; 1407 } 1408 1409 if (!current_user_can('update_plugins')) { 1410 wp_send_json_error(array('message' => esc_html__('You do not have permission to update plugins.', 'divewp-boost-site-performance'))); 1411 return; 1412 } 1413 1414 if (!isset($_POST['plugin_file'])) { 1415 wp_send_json_error(array('message' => esc_html__('Plugin file not specified.', 'divewp-boost-site-performance'))); 1416 return; 1417 } 1418 1419 $plugin_file = sanitize_text_field(wp_unslash($_POST['plugin_file'])); 1420 1421 if (!function_exists('get_plugins')) { 1422 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 1423 } 1424 1425 $all_plugins = get_plugins(); 1426 if (!isset($all_plugins[$plugin_file])) { 1427 wp_send_json_error(array('message' => esc_html__('Invalid plugin file.', 'divewp-boost-site-performance'))); 1428 return; 1429 } 1430 1431 $update_plugins = get_site_transient('update_plugins'); 1432 if (empty($update_plugins->response) || !isset($update_plugins->response[$plugin_file])) { 1433 wp_send_json_error(array('message' => esc_html__('No update available for this plugin.', 'divewp-boost-site-performance'))); 1434 return; 1435 } 1436 1437 $previous_version = $all_plugins[$plugin_file]['Version']; 1438 $new_version = $update_plugins->response[$plugin_file]->new_version; 1439 1440 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 1441 require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php'; 1442 require_once ABSPATH . 'wp-admin/includes/file.php'; 1443 require_once ABSPATH . 'wp-admin/includes/misc.php'; 1444 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 1445 1446 $skin = new \Automatic_Upgrader_Skin(); 1447 $upgrader = new \Plugin_Upgrader($skin); 1448 1449 $result = $upgrader->upgrade($plugin_file); 1450 1451 if (is_wp_error($result)) { 1452 wp_send_json_error(array( 1453 'message' => $this->map_upgrader_error($result), 1454 )); 1455 return; 1456 } 1457 1458 if (true !== $result) { 1459 $feedback = $skin->get_upgrade_messages(); 1460 $error_msg = !empty($feedback) ? implode(' ', $feedback) : __('Update failed for an unknown reason.', 'divewp-boost-site-performance'); 1461 wp_send_json_error(array('message' => $error_msg)); 1462 return; 1463 } 1464 1465 if (!function_exists('wp_update_plugins')) { 1466 require_once ABSPATH . 'wp-admin/includes/update.php'; 1467 } 1468 wp_update_plugins(); 1469 1470 $active_plugins = get_option('active_plugins', array()); 1471 $is_active = in_array($plugin_file, $active_plugins, true); 1472 1473 wp_send_json_success(array( 1474 'previous_version' => $previous_version, 1475 'new_version' => $new_version, 1476 'is_active' => $is_active, 1477 'message' => sprintf( 1478 /* translators: 1: previous version, 2: new version */ 1479 __('Successfully updated from v%1$s to v%2$s.', 'divewp-boost-site-performance'), 1480 $previous_version, 1481 $new_version 1482 ), 1483 )); 1484 } 1389 1485 }
Note: See TracChangeset
for help on using the changeset viewer.