Changeset 49154
- Timestamp:
- 10/15/2020 01:58:28 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
-
src/js/_enqueues/admin/site-health.js (modified) (9 diffs)
-
src/wp-admin/admin-ajax.php (modified) (1 diff)
-
src/wp-admin/includes/ajax-actions.php (modified) (4 diffs)
-
src/wp-admin/includes/class-wp-site-health-auto-updates.php (modified) (3 diffs)
-
src/wp-admin/includes/class-wp-site-health.php (modified) (4 diffs)
-
src/wp-includes/rest-api.php (modified) (1 diff)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php (added)
-
src/wp-includes/script-loader.php (modified) (1 diff)
-
src/wp-settings.php (modified) (1 diff)
-
tests/phpunit/tests/rest-api/rest-schema-setup.php (modified) (2 diffs)
-
tests/phpunit/tests/rest-api/rest-site-health-controller.php (added)
-
tests/qunit/fixtures/wp-api-generated.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/site-health.js
r48301 r49154 12 12 _n = wp.i18n._n, 13 13 sprintf = wp.i18n.sprintf, 14 data,15 14 clipboard = new ClipboardJS( '.site-health-copy-buttons .copy-button' ), 16 15 isDebugTab = $( '.health-check-body.health-check-debug-tab' ).length, … … 79 78 heading, 80 79 count; 81 80 82 81 SiteHealth.site_status.issues[ issue.status ]++; 83 82 84 83 count = SiteHealth.site_status.issues[ issue.status ]; 84 85 // If no test name is supplied, append a placeholder for markup references. 86 if ( typeof issue.test === 'undefined' ) { 87 issue.test = issue.status + count; 88 } 85 89 86 90 if ( 'critical' === issue.status ) { … … 120 124 var $circle = $( '.site-health-progress svg #bar' ); 121 125 var totalTests = parseInt( SiteHealth.site_status.issues.good, 0 ) + 122 parseInt( SiteHealth.site_status.issues.recommended, 0 ) +123 ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );126 parseInt( SiteHealth.site_status.issues.recommended, 0 ) + 127 ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 ); 124 128 var failedTests = ( parseInt( SiteHealth.site_status.issues.recommended, 0 ) * 0.5 ) + 125 ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );129 ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 ); 126 130 var val = 100 - Math.ceil( ( failedTests / totalTests ) * 100 ); 127 131 … … 207 211 this.completed = true; 208 212 209 $.post( 210 ajaxurl, 211 data, 212 function( response ) { 213 if ( 'undefined' !== typeof( this.has_rest ) && this.has_rest ) { 214 wp.apiRequest( { 215 url: this.test 216 } ) 217 .done( function( response ) { 218 /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ 219 appendIssue( wp.hooks.applyFilters( 'site_status_test_result', response ) ); 220 } ) 221 .fail( function( response ) { 222 var description; 223 224 if ( 'undefined' !== typeof( response.responseJSON ) && 'undefined' !== typeof( response.responseJSON.message ) ) { 225 description = response.responseJSON.message; 226 } else { 227 description = __( 'No details available' ); 228 } 229 230 addFailedSiteHealthCheckNotice( this.url, description ); 231 } ) 232 .always( function() { 233 maybeRunNextAsyncTest(); 234 } ); 235 } else { 236 $.post( 237 ajaxurl, 238 data 239 ).done( function( response ) { 213 240 /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ 214 241 appendIssue( wp.hooks.applyFilters( 'site_status_test_result', response.data ) ); 242 } ).fail( function( response ) { 243 var description; 244 245 if ( 'undefined' !== typeof( response.responseJSON ) && 'undefined' !== typeof( response.responseJSON.message ) ) { 246 description = response.responseJSON.message; 247 } else { 248 description = __( 'No details available' ); 249 } 250 251 addFailedSiteHealthCheckNotice( this.url, description ); 252 } ).always( function() { 215 253 maybeRunNextAsyncTest(); 216 } 217 );254 } ); 255 } 218 256 219 257 return false; … … 224 262 recalculateProgression(); 225 263 } 264 } 265 266 /** 267 * Add the details of a failed asynchronous test to the list of test results. 268 * 269 * @since 5.6.0 270 */ 271 function addFailedSiteHealthCheckNotice( url, description ) { 272 var issue; 273 274 issue = { 275 'status': 'recommended', 276 'label': __( 'A test is unavailable' ), 277 'badge': { 278 'color': 'red', 279 'label': __( 'Unavailable' ) 280 }, 281 'description': '<p>' + url + '</p><p>' + description + '</p>', 282 'actions': '' 283 }; 284 285 /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ 286 appendIssue( wp.hooks.applyFilters( 'site_status_test_result', issue ) ); 226 287 } 227 288 … … 244 305 245 306 if ( 0 < SiteHealth.site_status.async.length ) { 246 data = { 247 'action': 'health-check-' + SiteHealth.site_status.async[0].test.replace( '_', '-' ), 248 '_wpnonce': SiteHealth.nonce.site_status 249 }; 250 251 SiteHealth.site_status.async[0].completed = true; 252 253 $.post( 254 ajaxurl, 255 data, 256 function( response ) { 257 appendIssue( response.data ); 258 maybeRunNextAsyncTest(); 259 } 260 ); 307 maybeRunNextAsyncTest(); 261 308 } else { 262 309 recalculateProgression(); … … 265 312 266 313 function getDirectorySizes() { 267 var data = {268 action: 'health-check-get-sizes',269 _wpnonce: SiteHealth.nonce.site_status_result270 };271 272 314 var timestamp = ( new Date().getTime() ); 273 315 … … 277 319 }, 3000 ); 278 320 279 $.post( { 280 type: 'POST', 281 url: ajaxurl, 282 data: data, 283 dataType: 'json' 321 wp.apiRequest( { 322 path: '/wp-site-health/v1/directory-sizes' 284 323 } ).done( function( response ) { 285 updateDirSizes( response .data|| {} );324 updateDirSizes( response || {} ); 286 325 } ).always( function() { 287 326 var delay = ( new Date().getTime() ) - timestamp; … … 290 329 recalculateProgression(); 291 330 292 if ( delay > 3000 ) {331 if ( delay > 3000 ) { 293 332 /* 294 333 * We have announced that we're waiting. -
trunk/src/wp-admin/admin-ajax.php
r47835 r49154 144 144 145 145 // Deprecated. 146 $core_actions_post_deprecated = array( 'wp-fullscreen-save-post', 'press-this-save-post', 'press-this-add-category' ); 146 $core_actions_post_deprecated = array( 147 'wp-fullscreen-save-post', 148 'press-this-save-post', 149 'press-this-add-category', 150 'health-check-dotorg-communication', 151 'health-check-is-in-debug-mode', 152 'health-check-background-updates', 153 'health-check-loopback-requests', 154 ); 147 155 $core_actions_post = array_merge( $core_actions_post, $core_actions_post_deprecated ); 148 156 -
trunk/src/wp-admin/includes/ajax-actions.php
r49122 r49154 5143 5143 * 5144 5144 * @since 5.2.0 5145 * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_dotorg_communication() 5146 * @see WP_REST_Site_Health_Controller::test_dotorg_communication() 5145 5147 */ 5146 5148 function wp_ajax_health_check_dotorg_communication() { 5149 _doing_it_wrong( 5150 'wp_ajax_health_check_dotorg_communication', 5151 sprintf( 5152 // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. 5153 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5154 'wp_ajax_health_check_dotorg_communication', 5155 'WP_REST_Site_Health_Controller::test_dotorg_communication' 5156 ), 5157 '5.6.0' 5158 ); 5159 5147 5160 check_ajax_referer( 'health-check-site-status' ); 5148 5161 … … 5163 5176 * 5164 5177 * @since 5.2.0 5178 * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_background_updates() 5179 * @see WP_REST_Site_Health_Controller::test_background_updates() 5165 5180 */ 5166 5181 function wp_ajax_health_check_background_updates() { 5182 _doing_it_wrong( 5183 'wp_ajax_health_check_background_updates', 5184 sprintf( 5185 // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. 5186 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5187 'wp_ajax_health_check_background_updates', 5188 'WP_REST_Site_Health_Controller::test_background_updates' 5189 ), 5190 '5.6.0' 5191 ); 5192 5167 5193 check_ajax_referer( 'health-check-site-status' ); 5168 5194 … … 5183 5209 * 5184 5210 * @since 5.2.0 5211 * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_loopback_requests() 5212 * @see WP_REST_Site_Health_Controller::test_loopback_requests() 5185 5213 */ 5186 5214 function wp_ajax_health_check_loopback_requests() { 5215 _doing_it_wrong( 5216 'wp_ajax_health_check_loopback_requests', 5217 sprintf( 5218 // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. 5219 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5220 'wp_ajax_health_check_loopback_requests', 5221 'WP_REST_Site_Health_Controller::test_loopback_requests' 5222 ), 5223 '5.6.0' 5224 ); 5225 5187 5226 check_ajax_referer( 'health-check-site-status' ); 5188 5227 … … 5220 5259 * 5221 5260 * @since 5.2.0 5261 * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::get_directory_sizes() 5262 * @see WP_REST_Site_Health_Controller::get_directory_sizes() 5222 5263 */ 5223 5264 function wp_ajax_health_check_get_sizes() { 5265 _doing_it_wrong( 5266 'wp_ajax_health_check_get_sizes', 5267 sprintf( 5268 // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it. 5269 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5270 'wp_ajax_health_check_get_sizes', 5271 'WP_REST_Site_Health_Controller::get_directory_sizes' 5272 ), 5273 '5.6.0' 5274 ); 5275 5224 5276 check_ajax_referer( 'health-check-site-status-result' ); 5225 5277 -
trunk/src/wp-admin/includes/class-wp-site-health-auto-updates.php
r48792 r49154 91 91 */ 92 92 public function test_wp_version_check_attached() { 93 if ( ! is_main_site() ) { 94 return; 95 } 96 97 $cookies = wp_unslash( $_COOKIE ); 98 $timeout = 10; 99 $headers = array( 100 'Cache-Control' => 'no-cache', 101 ); 102 /** This filter is documented in wp-includes/class-wp-http-streams.php */ 103 $sslverify = apply_filters( 'https_local_ssl_verify', false ); 104 105 // Include Basic auth in loopback requests. 106 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { 107 $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); 108 } 109 110 $url = add_query_arg( 111 array( 112 'health-check-test-wp_version_check' => true, 113 ), 114 admin_url( 'site-health.php' ) 115 ); 116 117 $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) ); 118 119 if ( is_wp_error( $test ) ) { 120 return array( 121 'description' => sprintf( 122 /* translators: %s: Name of the filter used. */ 123 __( 'Could not confirm that the %s filter is available.' ), 124 '<code>wp_version_check()</code>' 125 ), 126 'severity' => 'warning', 127 );