Ticket #48105: 48105.patch
File 48105.patch, 12.5 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; 166 var active_test = this.test; 165 167 var data = { 166 'action': 'health-check-' + this.test.replace( '_', '-' ),168 'action': 'health-check-' + active_test.replace( '_', '-' ), 167 169 '_wpnonce': SiteHealth.nonce.site_status 168 170 }; 169 171 172 if ( "undefined" !== typeof( this.has_rest ) && this.has_rest ) { 173 url = SiteHealth.rest_base + this.test; 174 data = { 175 '_wpnonce': SiteHealth.nonce.rest_api 176 }; 177 } 178 170 179 if ( this.completed ) { 171 180 return true; 172 181 } … … 176 185 this.completed = true; 177 186 178 187 $.post( 179 ajaxurl, 180 data, 181 function( response ) { 182 AppendIssue( response.data ); 183 maybeRunNextAsyncTest(); 184 } 185 ); 188 url, 189 data 190 ).done( function( response ) { 191 AppendIssue( response.data ); 192 } ).fail( function( response ) { 193 var description = __( 'No details available' ); 194 195 if ( "undefined" !== typeof( response.responseJSON ) && "undefined" !== typeof( response.responseJSON.message ) ) { 196 description = response.responseJSON.message; 197 } 198 199 var issue = { 200 'status': 'recommended', 201 'label': sprintf( __( 'Unavailable test: %s' ), active_test ), 202 'test': active_test.replace( /\//g, '-' ), 203 'badge': { 204 'color': 'blue', 205 'label': __( 'Failed test' ) 206 }, 207 'description': '<p>' + description + '</p>', 208 'actions': '' 209 }; 210 211 AppendIssue( issue ); 212 } ).always(function() { 213 maybeRunNextAsyncTest(); 214 }); 186 215 187 216 return false; 188 217 } ); … … 211 240 } 212 241 213 242 if ( 0 < SiteHealth.site_status.async.length ) { 214 data = { 215 'action': 'health-check-' + SiteHealth.site_status.async[0].test.replace( '_', '-' ), 216 '_wpnonce': SiteHealth.nonce.site_status 217 }; 218 219 SiteHealth.site_status.async[0].completed = true; 220 221 $.post( 222 ajaxurl, 223 data, 224 function( response ) { 225 AppendIssue( response.data ); 226 maybeRunNextAsyncTest(); 227 } 228 ); 243 maybeRunNextAsyncTest(); 229 244 } else { 230 245 RecalculateProgression(); 231 246 } -
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
86 86 * @return array The test results. 87 87 */ 88 88 public function test_wp_version_check_attached() { 89 if ( ! is_main_site() ) { 90 return; 91 } 92 93 $cookies = wp_unslash( $_COOKIE ); 94 $timeout = 10; 95 $headers = array( 96 'Cache-Control' => 'no-cache', 97 ); 98 /** This filter is documented in wp-includes/class-wp-http-streams.php */ 99 $sslverify = apply_filters( 'https_local_ssl_verify', false ); 100 101 // Include Basic auth in loopback requests. 102 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { 103 $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); 104 } 105 106 $url = add_query_arg( 107 array( 108 'health-check-test-wp_version_check' => true, 109 ), 110 admin_url( 'site-health.php' ) 111 ); 112 113 $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) ); 114 115 if ( is_wp_error( $test ) ) { 116 return array( 117 'description' => sprintf( 118 /* translators: %s: Name of the filter used. */ 119 __( 'Could not confirm that the %s filter is available.' ), 120 '<code>wp_version_check()</code>' 121 ), 122 'severity' => 'warning', 123 ); 124 } 125 126 $response = wp_remote_retrieve_body( $test ); 127 128 if ( 'yes' !== $response ) { 89 if ( ! has_filter( 'wp_version_check', 'wp_version_check' ) ) { 129 90 return array( 130 91 'description' => sprintf( 131 92 /* translators: %s: Name of the filter used. */ … … 282 243 * @return array The test results. 283 244 */ 284 245 function test_check_wp_filesystem_method() { 246 // Make sure the `request_filesystem_credentials` function is available during our REST call. 247 if ( ! function_exists( 'request_filesystem_credentials' ) ) { 248 require_once( ABSPATH . '/wp-admin/includes/file.php' ); 249 } 250 285 251 $skin = new Automatic_Upgrader_Skin; 286 252 $success = $skin->request_filesystem_credentials( false, ABSPATH ); 287 253 … … 328 294 return false; 329 295 } 330 296 297 // Make sure the `get_core_checksums` function is available during our REST call. 298 if ( ! function_exists( 'get_core_checksums' ) ) { 299 require_once( ABSPATH . '/wp-admin/includes/update.php' ); 300 } 301 331 302 $checksums = get_core_checksums( $wp_version, 'en_US' ); 332 303 $dev = ( false !== strpos( $wp_version, '-' ) ); 333 304 // Get the last stable version's files and test against that -
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 ), … … 110 112 if ( is_string( $test['test'] ) ) { 111 113 $health_check_js_variables['site_status']['async'][] = array( 112 114 'test' => $test['test'], 115 'has_rest' => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ), 113 116 'completed' => false, 114 117 ); 115 118 } … … 1816 1819 ), 1817 1820 'async' => array( 1818 1821 'dotorg_communication' => array( 1819 'label' => __( 'Communication with WordPress.org' ), 1820 'test' => 'dotorg_communication', 1822 'label' => __( 'Communication with WordPress.org' ), 1823 'test' => 'wp/v2/site-health/test-dotorg-communication', 1824 'has_rest' => true, 1821 1825 ), 1822 1826 'background_updates' => array( 1823 'label' => __( 'Background updates' ), 1824 'test' => 'background_updates', 1827 'label' => __( 'Background updates' ), 1828 'test' => 'wp/v2/site-health/test-background-updates', 1829 'has_rest' => true, 1825 1830 ), 1826 1831 'loopback_requests' => array( 1827 'label' => __( 'Loopback request' ), 1828 'test' => 'loopback_requests', 1832 'label' => __( 'Loopback request' ), 1833 'test' => 'wp/v2/site-health/test-loopback-requests', 1834 'has_rest' => true, 1829 1835 ), 1830 1836 ), 1831 1837 ); … … 1884 1890 * @return string The modified body class string. 1885 1891 */ 1886 1892 public function admin_body_class( $body_class ) { 1893 $screen = get_current_screen(); 1894 if ( 'site-health' !== $screen->id ) { 1895 return $body_class; 1896 } 1897 1887 1898 $body_class .= ' site-health'; 1888 1899 1889 1900 return $body_class; -
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.3.0 8 */ 9 10 /** 11 * Core class for interacting with Site Health elements. 12 * 13 * @since 5.3.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.3.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 92 public function validate_request_permission( $check ) { 93 $capability = apply_filters( "site_health_test_rest_capability_{$check}", 'view_site_health_checks', $check ); 94 95 return current_user_can( $capability ); 96 } 97 98 /** 99 * Check if background updates work as expected. 100 * 101 * @since 5.3.0 102 * 103 * @return array 104 */ 105 public function test_background_updates() { 106 return array( 107 'data' => $this->site_health->get_test_background_updates() 108 ); 109 } 110 111 /** 112 * Check that the site can reach the WordPress.org API. 113 * 114 * @since 5.3.0 115 * 116 * @return array 117 */ 118 public function test_dotorg_communication() { 119 return array( 120 'data' => $this->site_health->get_test_dotorg_communication() 121 ); 122 } 123 124 /** 125 * Check that loopbacks can be performed. 126 * 127 * @since 5.3.0 128 * 129 * @return array 130 */ 131 public function test_loopback_requests() { 132 return array( 133 'data' => $this->site_health->get_test_loopback_requests() 134 ); 135 } 136 } -
src/wp-includes/rest-api.php
272 272 $controller = new WP_REST_Settings_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 // Themes. 276 280 $controller = new WP_REST_Themes_Controller; 277 281 $controller->register_routes();