Ticket #17703: 17703-04.patch
File 17703-04.patch, 8.7 KB (added by , 11 years ago) |
---|
-
src/wp-admin/admin-ajax.php
diff --git src/wp-admin/admin-ajax.php src/wp-admin/admin-ajax.php index d57d56b..434bcd8 100644
$core_actions_post = array( 58 58 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 59 59 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 60 60 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', 61 'save-user-color-scheme', 61 'save-user-color-scheme', 'get-updates-data', 62 62 ); 63 63 64 64 // Register core Ajax calls. -
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index caf6311..c736ddb 100644
function wp_ajax_save_user_color_scheme() { 2205 2205 update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); 2206 2206 wp_send_json_success(); 2207 2207 } 2208 2209 /** 2210 * Refresh plugin, theme, and core update counts and return localized counts and strings. 2211 * 2212 * 2213 * @since 3.9.0 2214 * 2215 */ 2216 function wp_ajax_get_updates_data() { 2217 2218 check_ajax_referer( 'get-updates-data', 'nonce' ); 2219 2220 delete_site_transient( 'update_core' ); 2221 delete_site_transient( 'update_plugins' ); 2222 delete_site_transient( 'update_themes' ); 2223 2224 wp_version_check(); 2225 wp_update_plugins(); 2226 wp_update_themes(); 2227 2228 $updates = wp_get_update_data(); 2229 $updates['formatted_counts'] = array(); 2230 2231 foreach( $updates['counts'] as $key => $val ) { 2232 $updates['formatted_counts'][$key] = number_Format_i18n( $val ); 2233 } 2234 2235 wp_send_json_success( $updates ); 2236 } 2237 -
src/wp-admin/includes/class-wp-upgrader-skins.php
diff --git src/wp-admin/includes/class-wp-upgrader-skins.php src/wp-admin/includes/class-wp-upgrader-skins.php index 71a1293..e72c3e3 100644
class WP_Upgrader_Skin { 91 91 } 92 92 function before() {} 93 93 function after() {} 94 /** 95 * Output javascript that calls function to update the update counts. 96 * 97 * @since 3.9.0 98 */ 99 function update_counts() { 100 echo '<script type="text/javascript"> 101 (function( wp ) { 102 if ( wp && wp.updateCounts ) { 103 var nonce = "' . wp_create_nonce( 'get-updates-data' ) . '"; 104 wp.updateCounts( nonce ); 105 } 106 })( window.wp ); 107 </script>'; 108 109 } 110 /** 111 * Output javascript that sends message to trigger update of update count 112 * information via postMessage. 113 * 114 * @since 3.9.0 115 */ 116 function update_counts_iframe() { 117 echo '<script type="text/javascript"> 118 if ( window.postMessage && JSON ) { 119 window.parent.postMessage( JSON.stringify( { action: "updateCounts", nonce: "' . wp_create_nonce( 'get-updates-data' ) . '" } ), window.location.protocol + "//" + window.location.hostname ); 120 } 121 </script>'; 122 } 94 123 95 124 } 96 125 -
src/wp-admin/includes/class-wp-upgrader.php
diff --git src/wp-admin/includes/class-wp-upgrader.php src/wp-admin/includes/class-wp-upgrader.php index 664595a..d13178f 100644
class Plugin_Upgrader extends WP_Upgrader { 512 512 // Force refresh of plugin update information 513 513 wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); 514 514 515 $this->skin->update_counts(); 516 515 517 return true; 516 518 } 517 519 … … class Plugin_Upgrader extends WP_Upgrader { 610 612 // Force refresh of plugin update information 611 613 wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); 612 614 615 $this->skin->update_counts_iframe(); 616 613 617 return $results; 614 618 } 615 619 … … class Theme_Upgrader extends WP_Upgrader { 895 899 896 900 wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); 897 901 902 $this->skin->update_counts(); 903 898 904 return true; 899 905 } 900 906 … … class Theme_Upgrader extends WP_Upgrader { 995 1001 // Refresh the Theme Update information 996 1002 wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); 997 1003 1004 $this->skin->update_counts_iframe(); 1005 998 1006 return $results; 999 1007 } 1000 1008 -
new file src/wp-admin/js/updates.js
diff --git src/wp-admin/js/updates.js src/wp-admin/js/updates.js new file mode 100644 index 0000000..3b6b0db
- + 1 window.wp = window.wp || {}; 2 3 (function( $, wp ) { 4 5 function refreshWithNewCounts( updatesData ) { 6 var $pluginCount = $('#menu-plugins'), 7 $coreCount = $('a[href="update-core.php"]'), 8 $adminBarUpdates = $( '#wp-admin-bar-updates' ); 9 10 $adminBarUpdates.find('.ab-item').attr( 'title', updatesData.title ); 11 $adminBarUpdates.find('.ab-label').text( updatesData.formatted_counts.total ); 12 $adminBarUpdates.find('.screen-reader-text').text( updatesData.title ); 13 14 $coreCount.find( '.update-plugins' ).attr( 'title', updatesData.title ) 15 .each( function( index, elem ) { 16 elem.className = elem.className.replace( /count-\d+/, 'count-' + updatesData.counts.total ); 17 } ) 18 .find( '.update-count' ).text( updatesData.formatted_counts.total ); 19 20 21 $pluginCount.find( '.plugin-count' ).text( updatesData.formatted_counts.plugins ); 22 23 $pluginCount.find( '.update-plugins' ).each( function( index, elem ) { 24 elem.className = elem.className.replace( /count-\d+/, 'count-' + updatesData.counts.plugins ); 25 } ); 26 } 27 28 /** 29 * Issue ajax call to fetch updated plugin, theme, and core update count information. 30 * 31 * @param {string} nonce Valid nonce 32 */ 33 wp.updateCounts = function( nonce ) { 34 var data, dfd; 35 36 data = { 37 nonce: nonce 38 }; 39 40 dfd = wp.ajax.post( 'get-updates-data', data ); 41 dfd.done( refreshWithNewCounts ); 42 }; 43 44 $( window ).on( 'message', function( e ) { 45 var event = e.originalEvent, 46 message, 47 loc = document.location, 48 expectedOrigin = loc.protocol + '//' + loc.hostname; 49 50 if ( event.origin !== expectedOrigin ) { 51 return; 52 } 53 54 message = $.parseJSON( event.data ); 55 56 if ( typeof message.action === 'undefined' || message.action !== 'updateCounts' ) { 57 return; 58 } 59 60 wp.updateCounts( message.nonce ); 61 62 } ); 63 64 })( jQuery, window.wp ); -
src/wp-admin/plugins.php
diff --git src/wp-admin/plugins.php src/wp-admin/plugins.php index 61efcf5..8b1e4a0 100644
if ( $action ) { 113 113 $title = __( 'Update Plugins' ); 114 114 $parent_file = 'plugins.php'; 115 115 116 wp_enqueue_script('updates'); 116 117 require_once(ABSPATH . 'wp-admin/admin-header.php'); 117 118 118 119 echo '<div class="wrap">'; -
src/wp-admin/update-core.php
diff --git src/wp-admin/update-core.php src/wp-admin/update-core.php index d40349e..fc9fcff 100644
require_once( dirname( __FILE__ ) . '/admin.php' ); 11 11 12 12 wp_enqueue_style( 'plugin-install' ); 13 13 wp_enqueue_script( 'plugin-install' ); 14 wp_enqueue_script( 'updates' ); 14 15 add_thickbox(); 15 16 16 17 if ( is_multisite() && ! is_network_admin() ) { -
src/wp-admin/update.php
diff --git src/wp-admin/update.php src/wp-admin/update.php index e70d9c2..551da8e 100644
if ( isset($_GET['action']) ) { 37 37 $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins)); 38 38 $nonce = 'bulk-update-plugins'; 39 39 40 wp_enqueue_script(' jquery');40 wp_enqueue_script('updates'); 41 41 iframe_header(); 42 42 43 43 $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); … … if ( isset($_GET['action']) ) { 54 54 $title = __('Update Plugin'); 55 55 $parent_file = 'plugins.php'; 56 56 $submenu_file = 'plugins.php'; 57 58 wp_enqueue_script('updates'); 57 59 require_once(ABSPATH . 'wp-admin/admin-header.php'); 58 60 59 61 $nonce = 'upgrade-plugin_' . $plugin; … … if ( isset($_GET['action']) ) { 154 156 check_admin_referer('upgrade-theme_' . $theme); 155 157 156 158 wp_enqueue_script( 'customize-loader' ); 159 wp_enqueue_script( 'updates' ); 157 160 158 161 $title = __('Update Theme'); 159 162 $parent_file = 'themes.php'; … … if ( isset($_GET['action']) ) { 185 188 $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes)); 186 189 $nonce = 'bulk-update-themes'; 187 190 188 wp_enqueue_script(' jquery');191 wp_enqueue_script('updates'); 189 192 iframe_header(); 190 193 191 194 $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); -
src/wp-includes/script-loader.php
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php index 6e4488d..44eb274 100644
function wp_default_scripts( &$scripts ) { 471 471 'ays' => __('Are you sure you want to install this plugin?') 472 472 ) ); 473 473 474 $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util' ) ); 475 474 476 $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' ); 475 477 476 478 $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );