Ticket #48105: 48105.2.patch
File 48105.2.patch, 20.4 KB (added by , 6 years ago) |
---|
-
src/js/_enqueues/admin/site-health.js
162 162 163 163 if ( 1 <= SiteHealth.site_status.async.length ) { 164 164 $.each( SiteHealth.site_status.async, function() { 165 var url = ajaxurl; 165 166 var data = { 166 167 'action': 'health-check-' + this.test.replace( '_', '-' ), 167 168 '_wpnonce': SiteHealth.nonce.site_status 168 169 }; 169 170 171 if ( "undefined" !== typeof( this.has_rest ) && this.has_rest ) { 172 url = SiteHealth.rest_base + this.test; 173 data = { 174 '_wpnonce': SiteHealth.nonce.rest_api 175 }; 176 } 177 170 178 if ( this.completed ) { 171 179 return true; 172 180 } … … 176 184 this.completed = true; 177 185 178 186 $.post( 179 ajaxurl, 180 data, 181 function( response ) { 182 /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ 183 AppendIssue( wp.hooks.applyFilters( 'site_status_test_result', response.data ) ); 184 maybeRunNextAsyncTest(); 185 } 186 ); 187 url, 188 data 189 ).done( function( response ) { 190 /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ 191 AppendIssue( wp.hooks.applyFilters( 'site_status_test_result', response.data ) ); 192 } ).fail( function( response ) { 193 var description, issue; 194 195 if ( "undefined" !== typeof( response.responseJSON ) && "undefined" !== typeof( response.responseJSON.message ) ) { 196 description = response.responseJSON.message; 197 } else { 198 description = __( 'No details available' ); 199 } 200 201 issue = { 202 'status': 'recommended', 203 'label': __( 'A test is unavailable' ), 204 'badge': { 205 'color': 'red', 206 'label': __( 'Unavailable' ) 207 }, 208 'description': '<p>' + this.url + '</p><p>' + description + '</p>', 209 'actions': '' 210 }; 211 212 /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ 213 AppendIssue( wp.hooks.applyFilters( 'site_status_test_result', issue ) ); 214 } ).always( function() { 215 maybeRunNextAsyncTest(); 216 } ); 187 217 188 218 return false; 189 219 } ); … … 212 242 } 213 243 214 244 if ( 0 < SiteHealth.site_status.async.length ) { 215 data = { 216 'action': 'health-check-' + SiteHealth.site_status.async[0].test.replace( '_', '-' ), 217 '_wpnonce': SiteHealth.nonce.site_status 218 }; 219 220 SiteHealth.site_status.async[0].completed = true; 221 222 $.post( 223 ajaxurl, 224 data, 225 function( response ) { 226 AppendIssue( response.data ); 227 maybeRunNextAsyncTest(); 228 } 229 ); 245 maybeRunNextAsyncTest(); 230 246 } else { 231 247 RecalculateProgression(); 232 248 } … … 234 250 235 251 function getDirectorySizes() { 236 252 var data = { 237 action: 'health-check-get-sizes', 238 _wpnonce: SiteHealth.nonce.site_status_result 253 _wpnonce: SiteHealth.nonce.rest_api 239 254 }; 240 255 241 256 var timestamp = ( new Date().getTime() ); … … 246 261 }, 3000 ); 247 262 248 263 $.post( { 249 type: 'POST', 250 url: ajaxurl, 264 url: SiteHealth.rest_base + 'wp/v2/site-health/get-directory-sizes', 251 265 data: data, 252 266 dataType: 'json' 253 267 } ).done( function( response ) { 254 updateDirSizes( response .data|| {} );268 updateDirSizes( response || {} ); 255 269 } ).always( function() { 256 270 var delay = ( new Date().getTime() ) - timestamp; 257 271 -
src/wp-admin/includes/ajax-actions.php
5106 5106 * Ajax handler for site health checks on server communication. 5107 5107 * 5108 5108 * @since 5.2.0 5109 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_dotorg_communication() 5110 * @see WP_REST_Site_Health_Controller::test_dotorg_communication() 5109 5111 */ 5110 5112 function wp_ajax_health_check_dotorg_communication() { 5113 _doing_it_wrong( 5114 'wp_ajax_health_check_dotorg_communication', 5115 sprintf( 5116 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5117 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5118 'wp_ajax_health_check_dotorg_communication', 5119 'WP_REST_Site_Health_Controller::test_dotorg_communication' 5120 ), 5121 '5.4.0' 5122 ); 5123 5111 5124 check_ajax_referer( 'health-check-site-status' ); 5112 5125 5113 5126 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5126 5139 * Ajax handler for site health checks on debug mode. 5127 5140 * 5128 5141 * @since 5.2.0 5142 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_is_in_debug_mode() 5143 * @see WP_REST_Site_Health_Controller::test_is_in_debug_mode() 5129 5144 */ 5130 5145 function wp_ajax_health_check_is_in_debug_mode() { 5146 _doing_it_wrong( 5147 'wp_ajax_health_check_is_in_debug_mode', 5148 sprintf( 5149 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5150 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5151 'wp_ajax_health_check_is_in_debug_mode', 5152 'WP_REST_Site_Health_Controller::test_is_in_debug_mode' 5153 ), 5154 '5.4.0' 5155 ); 5156 5131 5157 wp_verify_nonce( 'health-check-site-status' ); 5132 5158 5133 5159 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5146 5172 * Ajax handler for site health checks on background updates. 5147 5173 * 5148 5174 * @since 5.2.0 5175 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_background_updates() 5176 * @see WP_REST_Site_Health_Controller::test_background_updates() 5149 5177 */ 5150 5178 function wp_ajax_health_check_background_updates() { 5179 _doing_it_wrong( 5180 'wp_ajax_health_check_background_updates', 5181 sprintf( 5182 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5183 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5184 'wp_ajax_health_check_background_updates', 5185 'WP_REST_Site_Health_Controller::test_background_updates' 5186 ), 5187 '5.4.0' 5188 ); 5189 5151 5190 check_ajax_referer( 'health-check-site-status' ); 5152 5191 5153 5192 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5167 5206 * Ajax handler for site health checks on loopback requests. 5168 5207 * 5169 5208 * @since 5.2.0 5209 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_loopback_requests() 5210 * @see WP_REST_Site_Health_Controller::test_loopback_requests() 5170 5211 */ 5171 5212 function wp_ajax_health_check_loopback_requests() { 5213 _doing_it_wrong( 5214 'wp_ajax_health_check_loopback_requests', 5215 sprintf( 5216 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5217 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5218 'wp_ajax_health_check_loopback_requests', 5219 'WP_REST_Site_Health_Controller::test_loopback_requests' 5220 ), 5221 '5.4.0' 5222 ); 5223 5172 5224 check_ajax_referer( 'health-check-site-status' ); 5173 5225 5174 5226 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5204 5256 * Ajax handler for site health check to get directories and database sizes. 5205 5257 * 5206 5258 * @since 5.2.0 5259 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::get_directory_sizes() 5260 * @see WP_REST_Site_Health_Controller::get_directory_sizes() 5207 5261 */ 5208 5262 function wp_ajax_health_check_get_sizes() { 5263 _doing_it_wrong( 5264 'wp_ajax_health_check_get_sizes', 5265 sprintf( 5266 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5267 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5268 'wp_ajax_health_check_get_sizes', 5269 'WP_REST_Site_Health_Controller::get_directory_sizes' 5270 ), 5271 '5.4.0' 5272 ); 5273 5209 5274 check_ajax_referer( 'health-check-site-status-result' ); 5210 5275 5211 5276 if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) { -
src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php
1 <?php 2 /** 3 * REST API: WP_REST_Site_Health_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 5.4.0 8 */ 9 10 /** 11 * Core class for interacting with Site Health elements. 12 * 13 * @since 5.4.0 14 * 15 * @see WP_REST_Controller 16 */ 17 class WP_REST_Site_Health_Controller extends WP_REST_Controller { 18 19 private $site_health; 20 21 /** 22 * Constructor. 23 */ 24 public function __construct() { 25 if ( ! class_exists( 'WP_Site_Health' ) ) { 26 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 27 } 28 29 $this->site_health = new WP_Site_Health(); 30 31 $this->namespace = 'wp/v2'; 32 $this->rest_base = 'site-health'; 33 } 34 35 /** 36 * Register API routes. 37 * 38 * @since 5.4.0 39 * 40 * @see register_rest_route() 41 */ 42 public function register_routes() { 43 register_rest_route( 44 $this->namespace, 45 sprintf( 46 '/%s/%s', 47 $this->rest_base, 48 'test-background-updates' 49 ), 50 array( 51 'methods' => 'POST', 52 'callback' => array( $this, 'test_background_updates' ), 53 'permission_callback' => function() { 54 return $this->validate_request_permission( 'test-background-updates' ); 55 }, 56 ) 57 ); 58 59 register_rest_route( 60 $this->namespace, 61 sprintf( 62 '/%s/%s', 63 $this->rest_base, 64 'test-loopback-requests' 65 ), 66 array( 67 'methods' => 'POST', 68 'callback' => array( $this, 'test_loopback_requests' ), 69 'permission_callback' => function() { 70 return $this->validate_request_permission( 'test-dotorg-communication' ); 71 }, 72 ) 73 ); 74 75 register_rest_route( 76 $this->namespace, 77 sprintf( 78 '/%s/%s', 79 $this->rest_base, 80 'test-dotorg-communication' 81 ), 82 array( 83 'methods' => 'POST', 84 'callback' => array( $this, 'test_dotorg_communication' ), 85 'permission_callback' => function() { 86 return $this->validate_request_permission( 'test-dotorg-communication' ); 87 }, 88 ) 89 ); 90 91 register_rest_route( 92 $this->namespace, 93 sprintf( 94 '/%s/%s', 95 $this->rest_base, 96 'test-is-in-debug-mode' 97 ), 98 array( 99 'methods' => 'POST', 100 'callback' => array( $this, 'test_is_in_debug_mode' ), 101 'permission_callback' => function() { 102 return $this->validate_request_permission( 'test-is-in-debug-mode' ); 103 }, 104 ) 105 ); 106 107 register_rest_route( 108 $this->namespace, 109 sprintf( 110 '/%s/%s', 111 $this->rest_base, 112 'get-directory-sizes' 113 ), 114 array( 115 'methods' => 'POST', 116 'callback' => array( $this, 'get_directory_sizes' ), 117 'permission_callback' => function() { 118 return $this->validate_request_permission( 'test-is-in-debug-mode' ) && ! is_multisite(); 119 }, 120 ) 121 ); 122 } 123 124 public function validate_request_permission( $check ) { 125 $capability = apply_filters( "site_health_test_rest_capability_{$check}", 'view_site_health_checks', $check ); 126 127 return current_user_can( $capability ); 128 } 129 130 /** 131 * Check if background updates work as expected. 132 * 133 * @since 5.4.0 134 * 135 * @return array 136 */ 137 public function test_background_updates() { 138 return array( 139 'data' => $this->site_health->get_test_background_updates() 140 ); 141 } 142 143 /** 144 * Check that the site can reach the WordPress.org API. 145 * 146 * @since 5.4.0 147 * 148 * @return array 149 */ 150 public function test_dotorg_communication() { 151 return array( 152 'data' => $this->site_health->get_test_dotorg_communication() 153 ); 154 } 155 156 /** 157 * Check that loopbacks can be performed. 158 * 159 * @since 5.4.0 160 * 161 * @return array 162 */ 163 public function test_loopback_requests() { 164 return array( 165 'data' => $this->site_health->get_test_loopback_requests() 166 ); 167 } 168 169 /** 170 * Check if the site has debug mode enabled. 171 * 172 * @since 5.4.0 173 * 174 * @return array 175 */ 176 public function test_is_in_debug_mode() { 177 return array( 178 'data' => $this->site_health->get_test_is_in_debug_mode() 179 ); 180 } 181 182 /** 183 * Get the current directory sizes for this install. 184 * 185 * @since 5.4.0 186 */ 187 public function get_directory_sizes() { 188 if ( ! class_exists( 'WP_Debug_Data' ) ) { 189 require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' ); 190 } 191 192 $sizes_data = WP_Debug_Data::get_sizes(); 193 $all_sizes = array( 'raw' => 0 ); 194 195 foreach ( $sizes_data as $name => $value ) { 196 $name = sanitize_text_field( $name ); 197 $data = array(); 198 199 if ( isset( $value['size'] ) ) { 200 if ( is_string( $value['size'] ) ) { 201 $data['size'] = sanitize_text_field( $value['size'] ); 202 } else { 203 $data['size'] = (int) $value['size']; 204 } 205 } 206 207 if ( isset( $value['debug'] ) ) { 208 if ( is_string( $value['debug'] ) ) { 209 $data['debug'] = sanitize_text_field( $value['debug'] ); 210 } else { 211 $data['debug'] = (int) $value['debug']; 212 } 213 } 214 215 if ( ! empty( $value['raw'] ) ) { 216 $data['raw'] = (int) $value['raw']; 217 } 218 219 $all_sizes[ $name ] = $data; 220 } 221 222 if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) { 223 return new WP_Error( 'not_available', 'not_available', $all_sizes ); 224 } 225 226 return $all_sizes; 227 } 228 } -
src/wp-settings.php
248 248 require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-renderer-controller.php' ); 249 249 require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-settings-controller.php' ); 250 250 require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php' ); 251 require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php' ); 251 252 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php' ); 252 253 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php' ); 253 254 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php' ); -
src/wp-admin/site-health.php
27 27 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 28 28 } 29 29 30 $health_check_site_status = new WP_Site_Health(); 31 32 // Start by checking if this is a special request checking for the existence of certain filters. 33 $health_check_site_status->check_wp_version_check_exists(); 30 new WP_Site_Health(); 34 31 35 32 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 36 33 ?> -
src/wp-admin/includes/class-wp-site-health-auto-updates.php
85 85 * @return array The test results. 86 86 */ 87 87 public function test_wp_version_check_attached() { 88 if ( ! is_main_site() ) { 89 return; 90 } 91 92 $cookies = wp_unslash( $_COOKIE ); 93 $timeout = 10; 94 $headers = array( 95 'Cache-Control' => 'no-cache', 96 ); 97 /** This filter is documented in wp-includes/class-wp-http-streams.php */ 98 $sslverify = apply_filters( 'https_local_ssl_verify', false ); 99 100 // Include Basic auth in loopback requests. 101 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { 102 $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); 103 } 104 105 $url = add_query_arg( 106 array( 107 'health-check-test-wp_version_check' => true, 108 ), 109 admin_url( 'site-health.php' ) 110 ); 111 112 $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) ); 113 114 if ( is_wp_error( $test ) ) { 115 return array( 116 'description' => sprintf( 117 /* translators: %s: Name of the filter used. */ 118 __( 'Could not confirm that the %s filter is available.' ), 119 '<code>wp_version_check()</code>' 120 ), 121 'severity' => 'warning', 122 ); 123 } 124 125 $response = wp_remote_retrieve_body( $test ); 126 127 if ( 'yes' !== $response ) { 88 if ( ! has_filter( 'wp_version_check', 'wp_version_check' ) ) { 128 89 return array( 129 90 'description' => sprintf( 130 91 /* translators: %s: Name of the filter used. */ … … 305 266 * @return array The test results. 306 267 */ 307 268 function test_check_wp_filesystem_method() { 269 // Make sure the `request_filesystem_credentials` function is available during our REST call. 270 if ( ! function_exists( 'request_filesystem_credentials' ) ) { 271 require_once( ABSPATH . '/wp-admin/includes/file.php' ); 272 } 273 308 274 $skin = new Automatic_Upgrader_Skin; 309 275 $success = $skin->request_filesystem_credentials( false, ABSPATH ); 310 276 … … 351 317 return false; 352 318 } 353 319 320 // Make sure the `get_core_checksums` function is available during our REST call. 321 if ( ! function_exists( 'get_core_checksums' ) ) { 322 require_once( ABSPATH . '/wp-admin/includes/update.php' ); 323 } 324 354 325 $checksums = get_core_checksums( $wp_version, 'en_US' ); 355 326 $dev = ( false !== strpos( $wp_version, '-' ) ); 356 327 // Get the last stable version's files and test against that -
src/wp-admin/admin-ajax.php
134 134 'wp-privacy-export-personal-data', 135 135 'wp-privacy-erase-personal-data', 136 136 'health-check-site-status-result', 137 'health-check-dotorg-communication',138 'health-check-is-in-debug-mode',139 'health-check-background-updates',140 'health-check-loopback-requests',141 'health-check-get-sizes',142 137 ); 143 138 144 139 // Deprecated -
src/wp-admin/includes/class-wp-site-health.php
57 57 58 58 $health_check_js_variables = array( 59 59 'screen' => $screen->id, 60 'rest_base' => rest_url( '/' ), 60 61 'nonce' => array( 62 'rest_api' => wp_create_nonce( 'wp_rest' ), 61 63 'site_status' => wp_create_nonce( 'health-check-site-status' ), 62 64 'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ), 63 65 ), … … 132 134 if ( is_string( $test['test'] ) ) { 133 135 $health_check_js_variables['site_status']['async'][] = array( 134 136 'test' => $test['test'], 137 'has_rest' => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ), 135 138 'completed' => false, 136 139 ); 137 140 } … … 1937 1940 ), 1938 1941 'async' => array( 1939 1942 'dotorg_communication' => array( 1940 'label' => __( 'Communication with WordPress.org' ), 1941 'test' => 'dotorg_communication', 1943 'label' => __( 'Communication with WordPress.org' ), 1944 'test' => 'wp/v2/site-health/test-dotorg-communication', 1945 'has_rest' => true, 1942 1946 ), 1943 1947 'background_updates' => array( 1944 'label' => __( 'Background updates' ), 1945 'test' => 'background_updates', 1948 'label' => __( 'Background updates' ), 1949 'test' => 'wp/v2/site-health/test-background-updates', 1950 'has_rest' => true, 1946 1951 ), 1947 1952 'loopback_requests' => array( 1948 'label' => __( 'Loopback request' ), 1949 'test' => 'loopback_requests', 1953 'label' => __( 'Loopback request' ), 1954 'test' => 'wp/v2/site-health/test-loopback-requests', 1955 'has_rest' => true, 1950 1956 ), 1951 1957 ), 1952 1958 ); … … 2005 2011 * @return string The modified body class string. 2006 2012 */ 2007 2013 public function admin_body_class( $body_class ) { 2014 $screen = get_current_screen(); 2015 if ( 'site-health' !== $screen->id ) { 2016 return $body_class; 2017 } 2018 2008 2019 $body_class .= ' site-health'; 2009 2020 2010 2021 return $body_class; -
src/wp-includes/rest-api.php
272 272 $controller = new WP_REST_Themes_Controller; 273 273 $controller->register_routes(); 274 274 275 // Site Health 276 $controller = new WP_REST_Site_Health_Controller; 277 $controller->register_routes(); 278 275 279 } 276 280 277 281 /**