Ticket #48105: 48105.3.patch
| File 48105.3.patch, 22.0 KB (added by , 6 years ago) |
|---|
-
src/wp-settings.php
256 256 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-renderer-controller.php'; 257 257 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-settings-controller.php'; 258 258 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php'; 259 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php'; 259 260 require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php'; 260 261 require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php'; 261 262 require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php'; -
src/wp-admin/includes/ajax-actions.php
5120 5120 * Ajax handler for site health checks on server communication. 5121 5121 * 5122 5122 * @since 5.2.0 5123 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_dotorg_communication() 5124 * @see WP_REST_Site_Health_Controller::test_dotorg_communication() 5123 5125 */ 5124 5126 function wp_ajax_health_check_dotorg_communication() { 5127 _doing_it_wrong( 5128 'wp_ajax_health_check_dotorg_communication', 5129 sprintf( 5130 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5131 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5132 'wp_ajax_health_check_dotorg_communication', 5133 'WP_REST_Site_Health_Controller::test_dotorg_communication' 5134 ), 5135 '5.4.0' 5136 ); 5137 5125 5138 check_ajax_referer( 'health-check-site-status' ); 5126 5139 5127 5140 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5140 5153 * Ajax handler for site health checks on debug mode. 5141 5154 * 5142 5155 * @since 5.2.0 5156 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_is_in_debug_mode() 5157 * @see WP_REST_Site_Health_Controller::test_is_in_debug_mode() 5143 5158 */ 5144 5159 function wp_ajax_health_check_is_in_debug_mode() { 5160 _doing_it_wrong( 5161 'wp_ajax_health_check_is_in_debug_mode', 5162 sprintf( 5163 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5164 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5165 'wp_ajax_health_check_is_in_debug_mode', 5166 'WP_REST_Site_Health_Controller::test_is_in_debug_mode' 5167 ), 5168 '5.4.0' 5169 ); 5170 5145 5171 wp_verify_nonce( 'health-check-site-status' ); 5146 5172 5147 5173 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5160 5186 * Ajax handler for site health checks on background updates. 5161 5187 * 5162 5188 * @since 5.2.0 5189 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_background_updates() 5190 * @see WP_REST_Site_Health_Controller::test_background_updates() 5163 5191 */ 5164 5192 function wp_ajax_health_check_background_updates() { 5193 _doing_it_wrong( 5194 'wp_ajax_health_check_background_updates', 5195 sprintf( 5196 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5197 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5198 'wp_ajax_health_check_background_updates', 5199 'WP_REST_Site_Health_Controller::test_background_updates' 5200 ), 5201 '5.4.0' 5202 ); 5203 5165 5204 check_ajax_referer( 'health-check-site-status' ); 5166 5205 5167 5206 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5181 5220 * Ajax handler for site health checks on loopback requests. 5182 5221 * 5183 5222 * @since 5.2.0 5223 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::test_loopback_requests() 5224 * @see WP_REST_Site_Health_Controller::test_loopback_requests() 5184 5225 */ 5185 5226 function wp_ajax_health_check_loopback_requests() { 5227 _doing_it_wrong( 5228 'wp_ajax_health_check_loopback_requests', 5229 sprintf( 5230 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5231 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5232 'wp_ajax_health_check_loopback_requests', 5233 'WP_REST_Site_Health_Controller::test_loopback_requests' 5234 ), 5235 '5.4.0' 5236 ); 5237 5186 5238 check_ajax_referer( 'health-check-site-status' ); 5187 5239 5188 5240 if ( ! current_user_can( 'view_site_health_checks' ) ) { … … 5218 5270 * Ajax handler for site health check to get directories and database sizes. 5219 5271 * 5220 5272 * @since 5.2.0 5273 * @deprecated 5.4.0 Use WP_REST_Site_Health_Controller::get_directory_sizes() 5274 * @see WP_REST_Site_Health_Controller::get_directory_sizes() 5221 5275 */ 5222 5276 function wp_ajax_health_check_get_sizes() { 5277 _doing_it_wrong( 5278 'wp_ajax_health_check_get_sizes', 5279 sprintf( 5280 // translators: 1: The Site Health action that is no longer used by core. 2: The new function taht replaces it. 5281 __( 'The Site Health check for %1$s has been replaced with %2$s.' ), 5282 'wp_ajax_health_check_get_sizes', 5283 'WP_REST_Site_Health_Controller::get_directory_sizes' 5284 ), 5285 '5.4.0' 5286 ); 5287 5223 5288 check_ajax_referer( 'health-check-site-status-result' ); 5224 5289 5225 5290 if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) { -
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 'toggle-auto-updates', 143 138 ); 144 139 -
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 = 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-site-health/v1/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/class-wp-site-health.php
80 80 81 81 $health_check_js_variables = array( 82 82 'screen' => $screen->id, 83 'rest_base' => rest_url( '/' ), 83 84 'nonce' => array( 85 'rest_api' => wp_create_nonce( 'wp_rest' ), 84 86 'site_status' => wp_create_nonce( 'health-check-site-status' ), 85 87 'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ), 86 88 ), … … 133 135 if ( is_string( $test['test'] ) ) { 134 136 $health_check_js_variables['site_status']['async'][] = array( 135 137 'test' => $test['test'], 138 'has_rest' => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ), 136 139 'completed' => false, 137 140 ); 138 141 } … … 1963 1966 * experiences. 1964 1967 * 1965 1968 * @since 5.2.0 1969 * @since 5.5.0 Added support for `has_rest` and `permissions`. 1966 1970 * 1967 1971 * @return array The list of tests to run. 1968 1972 */ … … 2028 2032 ), 2029 2033 'async' => array( 2030 2034 'dotorg_communication' => array( 2031 'label' => __( 'Communication with WordPress.org' ), 2032 'test' => 'dotorg_communication', 2035 'label' => __( 'Communication with WordPress.org' ), 2036 'test' => rest_url( 'wp-site-health/v1/test/dotorg-communication' ), 2037 'has_rest' => true, 2033 2038 ), 2034 2039 'background_updates' => array( 2035 'label' => __( 'Background updates' ), 2036 'test' => 'background_updates', 2040 'label' => __( 'Background updates' ), 2041 'test' => rest_url( 'wp-site-health/v1/test/background-updates' ), 2042 'has_rest' => true, 2037 2043 ), 2038 2044 'loopback_requests' => array( 2039 'label' => __( 'Loopback request' ), 2040 'test' => 'loopback_requests', 2045 'label' => __( 'Loopback request' ), 2046 'test' => rest_url( 'wp-site-health/v1/test/loopback-requests' ), 2047 'has_rest' => true, 2041 2048 ), 2042 2049 ), 2043 2050 ); 2044 2045 // Conditionally include REST rules if the function for it exists.2046 if ( function_exists( 'rest_url' ) ) {2047 $tests['direct']['rest_availability'] = array(2048 'label' => __( 'REST API availability' ),2049 'test' => 'rest_availability',2050 );2051 }2052 2051 2053 2052 /** 2054 2053 * Add or modify which site status tests are run on a site. … … 2074 2073 * Plugins and themes are encouraged to prefix test identifiers with their slug 2075 2074 * to avoid any collisions between tests. 2076 2075 * 2077 * @type string $label A friendly label for your test to identify it by. 2078 * @type mixed $test A callable to perform a direct test, or a string Ajax action to be called 2079 * to perform an async test. 2076 * @type string $label A friendly label for your test to identify it by. 2077 * @type mixed $test A callable to perform a direct test, or a string AJAX action to be 2078 * called to perform an async test. 2079 * @type boolean $has_rest Optional. Denote if `$test` has a REST API endpoint. 2080 2080 * } 2081 2081 * } 2082 2082 */ -
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-includes/rest-api.php
281 281 $controller = new WP_REST_Themes_Controller; 282 282 $controller->register_routes(); 283 283 284 // Site Health 285 $controller = new WP_REST_Site_Health_Controller; 286 $controller->register_routes(); 287 284 288 } 285 289 286 290 /** -
src/wp-admin/site-health.php
23 23 wp_enqueue_style( 'site-health' ); 24 24 wp_enqueue_script( 'site-health' ); 25 25 26 if ( ! class_exists( 'WP_Site_Health' ) ) {27 require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';28 }29 30 $health_check_site_status = WP_Site_Health::get_instance();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();34 35 26 require_once ABSPATH . 'wp-admin/admin-header.php'; 36 27 ?> 37 28 <div class="health-check-header"> -
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.5.0 8 */ 9 10 /** 11 * Core class for interacting with Site Health elements. 12 * 13 * @since 5.5.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->namespace = 'wp-site-health/v1'; 30 31 $this->site_health = WP_Site_Health::get_instance(); 32 } 33 34 /** 35 * Register API routes. 36 * 37 * @since 5.5.0 38 * 39 * @see register_rest_route() 40 */ 41 public function register_routes() { 42 register_rest_route( 43 $this->namespace, 44 sprintf( 45 '/%s/%s', 46 'test', 47 'background-updates' 48 ), 49 array( 50 'methods' => 'POST', 51 'callback' => array( $this, 'test_background_updates' ), 52 'permission_callback' => function() { 53 return $this->validate_request_permission( 'background_updates' ); 54 }, 55 ) 56 ); 57 58 register_rest_route( 59 $this->namespace, 60 sprintf( 61 '/%s/%s', 62 'test', 63 'loopback-requests' 64 ), 65 array( 66 'methods' => 'POST', 67 'callback' => array( $this, 'test_loopback_requests' ), 68 'permission_callback' => function() { 69 return $this->validate_request_permission( 'loopback_requests' ); 70 }, 71 ) 72 ); 73 74 register_rest_route( 75 $this->namespace, 76 sprintf( 77 '/%s/%s', 78 'test', 79 'dotorg-communication' 80 ), 81 array( 82 'methods' => 'POST', 83 'callback' => array( $this, 'test_dotorg_communication' ), 84 'permission_callback' => function() { 85 return $this->validate_request_permission( 'dotorg_communication' ); 86 }, 87 ) 88 ); 89 90 register_rest_route( 91 $this->namespace, 92 sprintf( 93 '/%s/%s', 94 'test', 95 'debug_enabled' 96 ), 97 array( 98 'methods' => 'POST', 99 'callback' => array( $this, 'test_is_in_debug_mode' ), 100 'permission_callback' => function() { 101 return $this->validate_request_permission( 'debug_enabled' ); 102 }, 103 ) 104 ); 105 106 register_rest_route( 107 $this->namespace, 108 sprintf( 109 '/%s/%s', 110 'get', 111 'directory-sizes' 112 ), 113 array( 114 'methods' => 'POST', 115 'callback' => array( $this, 'get_directory_sizes' ), 116 'permission_callback' => function() { 117 return $this->validate_request_permission( 'debug_enabled' ) && ! is_multisite(); 118 }, 119 ) 120 ); 121 } 122 123 /** 124 * Validate if the current user can request this REST endpoint. 125 * 126 * @param string $check The endpoint check being ran. 127 * 128 * @return bool 129 */ 130 public function validate_request_permission( $check ) { 131 $default_capability = 'view_site_health_checks'; 132 133 /** 134 * Filter the capability needed to run a given Site Health check. 135 * 136 * @since 5.5.0 137 * 138 * @param string $default_capability The default capability required for this check. 139 * @param string $check The Site Health check being performed. 140 */ 141 $capability = apply_filters( "site_health_test_rest_capability_{$check}", $default_capability, $check ); 142 143 return current_user_can( $capability ); 144 } 145 146 /** 147 * Check if background updates work as expected. 148 * 149 * @since 5.5.0 150 * 151 * @return array 152 */ 153 public function test_background_updates() { 154 return array( 155 'data' => $this->site_health->get_test_background_updates() 156 ); 157 } 158 159 /** 160 * Check that the site can reach the WordPress.org API. 161 * 162 * @since 5.5.0 163 * 164 * @return array 165 */ 166 public function test_dotorg_communication() { 167 return array( 168 'data' => $this->site_health->get_test_dotorg_communication() 169 ); 170 } 171 172 /** 173 * Check that loopbacks can be performed. 174 * 175 * @since 5.5.0 176 * 177 * @return array 178 */ 179 public function test_loopback_requests() { 180 return array( 181 'data' => $this->site_health->get_test_loopback_requests() 182 ); 183 } 184 185 /** 186 * Check if the site has debug mode enabled. 187 * 188 * @since 5.5.0 189 * 190 * @return array 191 */ 192 public function test_is_in_debug_mode() { 193 return array( 194 'data' => $this->site_health->get_test_is_in_debug_mode() 195 ); 196 } 197 198 /** 199 * Get the current directory sizes for this install. 200 * 201 * @since 5.5.0 202 */ 203 public function get_directory_sizes() { 204 if ( ! class_exists( 'WP_Debug_Data' ) ) { 205 require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' ); 206 } 207 208 $sizes_data = WP_Debug_Data::get_sizes(); 209 $all_sizes = array( 'raw' => 0 ); 210 211 foreach ( $sizes_data as $name => $value ) { 212 $name = sanitize_text_field( $name ); 213 $data = array(); 214 215 if ( isset( $value['size'] ) ) { 216 if ( is_string( $value['size'] ) ) { 217 $data['size'] = sanitize_text_field( $value['size'] ); 218 } else { 219 $data['size'] = (int) $value['size']; 220 } 221 } 222 223 if ( isset( $value['debug'] ) ) { 224 if ( is_string( $value['debug'] ) ) { 225 $data['debug'] = sanitize_text_field( $value['debug'] ); 226 } else { 227 $data['debug'] = (int) $value['debug']; 228 } 229 } 230 231 if ( ! empty( $value['raw'] ) ) { 232 $data['raw'] = (int) $value['raw']; 233 } 234 235 $all_sizes[ $name ] = $data; 236 } 237 238 if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) { 239 return new WP_Error( 'not_available', 'not_available', $all_sizes ); 240 } 241 242 return $all_sizes; 243 } 244 }