Ticket #46573: 46573.2.diff
File 46573.2.diff, 135.9 KB (added by , 5 years ago) |
---|
-
Gruntfile.js
diff --git a/Gruntfile.js b/Gruntfile.js index a27fc2b735..f40fa336cf 100644
a b module.exports = function(grunt) { 263 263 [ WORKING_DIR + 'wp-admin/js/tags-box.js' ]: [ './src/js/_enqueues/admin/tags-box.js' ], 264 264 [ WORKING_DIR + 'wp-admin/js/tags-suggest.js' ]: [ './src/js/_enqueues/admin/tags-suggest.js' ], 265 265 [ WORKING_DIR + 'wp-admin/js/tags.js' ]: [ './src/js/_enqueues/admin/tags.js' ], 266 [ WORKING_DIR + 'wp-admin/js/site-health.js' ]: [ './src/js/_enqueues/admin/site-health.js' ], 266 267 [ WORKING_DIR + 'wp-admin/js/theme-plugin-editor.js' ]: [ './src/js/_enqueues/wp/theme-plugin-editor.js' ], 267 268 [ WORKING_DIR + 'wp-admin/js/theme.js' ]: [ './src/js/_enqueues/wp/theme.js' ], 268 269 [ WORKING_DIR + 'wp-admin/js/updates.js' ]: [ './src/js/_enqueues/wp/updates.js' ], -
new file src/js/_enqueues/admin/site-health.js
diff --git a/src/js/_enqueues/admin/site-health.js b/src/js/_enqueues/admin/site-health.js new file mode 100644 index 0000000000..606e5ad2db
- + 1 /** 2 * Interactions used by the Site Health modules in WordPress. 3 * 4 * @output wp-admin/js/site-health.js 5 */ 6 7 /* global ajaxurl, SiteHealth, wp */ 8 9 jQuery( document ).ready( function( $ ) { 10 11 var data; 12 13 // Debug information copy section. 14 $( '.health-check-copy-field' ).click( function( e ) { 15 var $textarea = $( '#system-information-' + $( this ).data( 'copy-field' ) + '-copy-field' ), 16 $wrapper = $( this ).closest( 'div' ); 17 18 e.preventDefault(); 19 20 $textarea.select(); 21 22 if ( document.execCommand( 'copy' ) ) { 23 $( '.copy-field-success', $wrapper ).addClass( 'visible' ); 24 $( this ).focus(); 25 26 wp.a11y.speak( SiteHealth.string.site_info_copied, 'polite' ); 27 } 28 } ); 29 30 $( '.health-check-toggle-copy-section' ).click( function( e ) { 31 var $copySection = $( '.system-information-copy-wrapper' ); 32 33 e.preventDefault(); 34 35 if ( $copySection.hasClass( 'hidden' ) ) { 36 $copySection.removeClass( 'hidden' ); 37 38 $( this ).text( SiteHealth.string.site_info_hide_copy ); 39 } else { 40 $copySection.addClass( 'hidden' ); 41 42 $( this ).text( SiteHealth.string.site_info_show_copy ); 43 } 44 } ); 45 46 // Accordion handling in various areas. 47 $( '.health-check-accordion' ).on( 'click', '.health-check-accordion-trigger', function() { 48 var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) ); 49 50 if ( isExpanded ) { 51 $( this ).attr( 'aria-expanded', 'false' ); 52 $( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true ); 53 } else { 54 $( this ).attr( 'aria-expanded', 'true' ); 55 $( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false ); 56 } 57 } ); 58 59 $( '.health-check-accordion' ).on( 'keyup', '.health-check-accordion-trigger', function( e ) { 60 if ( '38' === e.keyCode.toString() ) { 61 $( '.health-check-accordion-trigger', $( this ).closest( 'dt' ).prevAll( 'dt' ) ).focus(); 62 } else if ( '40' === e.keyCode.toString() ) { 63 $( '.health-check-accordion-trigger', $( this ).closest( 'dt' ).nextAll( 'dt' ) ).focus(); 64 } 65 } ); 66 67 // Site Health test handling. 68 69 $( '.site-health-view-passed' ).on( 'click', function() { 70 var goodIssuesWrapper = $( '#health-check-issues-good' ); 71 72 goodIssuesWrapper.toggleClass( 'hidden' ); 73 $( this ).attr( 'aria-expanded', ! goodIssuesWrapper.hasClass( 'hidden' ) ); 74 } ); 75 76 /** 77 * Append a new issue to the issue list. 78 * 79 * @since 5.2.0 80 * 81 * @param {Object} issue The issue data. 82 */ 83 function AppendIssue( issue ) { 84 var template = wp.template( 'health-check-issue' ), 85 issueWrapper = $( '#health-check-issues-' + issue.status ), 86 issueCounter = $( '.issue-count', issueWrapper ); 87 88 SiteHealth.site_status.issues[ issue.status ]++; 89 90 issueCounter.text( SiteHealth.site_status.issues[ issue.status ] ); 91 $( '.issues', '#health-check-issues-' + issue.status ).append( template( issue ) ); 92 } 93 94 /** 95 * Update site health status indicator as asynchronous tests are run and returned. 96 * 97 * @since 5.2.0 98 */ 99 function RecalculateProgression() { 100 var r, c, pct; 101 var $progressBar = $( '#progressbar' ); 102 var $circle = $( '#progressbar svg #bar' ); 103 var totalTests = parseInt( SiteHealth.site_status.issues.good, 0 ) + parseInt( SiteHealth.site_status.issues.recommended, 0 ) + ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 ); 104 var failedTests = parseInt( SiteHealth.site_status.issues.recommended, 0 ) + ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 ); 105 var val = 100 - Math.ceil( ( failedTests / totalTests ) * 100 ); 106 107 if ( 0 === totalTests ) { 108 $progressBar.addClass( 'hidden' ); 109 return; 110 } 111 112 $progressBar.removeClass( 'loading' ); 113 114 r = $circle.attr( 'r' ); 115 c = Math.PI * ( r * 2 ); 116 117 if ( 0 > val ) { 118 val = 0; 119 } 120 if ( 100 < val ) { 121 val = 100; 122 } 123 124 pct = ( ( 100 - val ) / 100 ) * c; 125 126 $circle.css({ strokeDashoffset: pct } ); 127 128 if ( 1 > parseInt( SiteHealth.site_status.issues.critical, 0 ) ) { 129 $( '#health-check-issues-critical' ).addClass( 'hidden' ); 130 } 131 132 if ( 1 > parseInt( SiteHealth.site_status.issues.recommended, 0 ) ) { 133 $( '#health-check-issues-recommended' ).addClass( 'hidden' ); 134 } 135 136 if ( 50 <= val ) { 137 $circle.addClass( 'orange' ).removeClass( 'red' ); 138 } 139 140 if ( 90 <= val ) { 141 $circle.addClass( 'green' ).removeClass( 'orange' ); 142 } 143 144 if ( 100 === val ) { 145 $( '.site-status-all-clear' ).removeClass( 'hide' ); 146 $( '.site-status-has-issues' ).addClass( 'hide' ); 147 } 148 149 $progressBar.attr( 'data-pct', val ); 150 $progressBar.attr( 'aria-valuenow', val ); 151 152 $( '.health-check-body' ).attr( 'aria-hidden', false ); 153 154 $.post( 155 ajaxurl, 156 { 157 'action': 'health-check-site-status-result', 158 '_wpnonce': SiteHealth.nonce.site_status_result, 159 'counts': SiteHealth.site_status.issues 160 } 161 ); 162 163 wp.a11y.speak( SiteHealth.string.site_health_complete_screen_reader.replace( '%s', val + '%' ), 'polite' ); 164 } 165 166 /** 167 * Queue the next asynchronous test when we're ready to run it. 168 * 169 * @since 5.2.0 170 */ 171 function maybeRunNextAsyncTest() { 172 var doCalculation = true; 173 174 if ( 1 <= SiteHealth.site_status.async.length ) { 175 $.each( SiteHealth.site_status.async, function() { 176 var data = { 177 'action': 'health-check-' + this.test.replace( '_', '-' ), 178 '_wpnonce': SiteHealth.nonce.site_status 179 }; 180 181 if ( this.completed ) { 182 return true; 183 } 184 185 doCalculation = false; 186 187 this.completed = true; 188 189 $.post( 190 ajaxurl, 191 data, 192 function( response ) { 193 AppendIssue( response.data ); 194 maybeRunNextAsyncTest(); 195 } 196 ); 197 198 return false; 199 } ); 200 } 201 202 if ( doCalculation ) { 203 RecalculateProgression(); 204 } 205 } 206 207 if ( 'undefined' !== typeof SiteHealth ) { 208 if ( 0 === SiteHealth.site_status.direct.length && 0 === SiteHealth.site_status.async.length ) { 209 RecalculateProgression(); 210 } else { 211 SiteHealth.site_status.issues = { 212 'good': 0, 213 'recommended': 0, 214 'critical': 0 215 }; 216 } 217 218 if ( 0 < SiteHealth.site_status.direct.length ) { 219 $.each( SiteHealth.site_status.direct, function() { 220 AppendIssue( this ); 221 } ); 222 } 223 224 if ( 0 < SiteHealth.site_status.async.length ) { 225 data = { 226 'action': 'health-check-' + SiteHealth.site_status.async[0].test.replace( '_', '-' ), 227 '_wpnonce': SiteHealth.nonce.site_status 228 }; 229 230 SiteHealth.site_status.async[0].completed = true; 231 232 $.post( 233 ajaxurl, 234 data, 235 function( response ) { 236 AppendIssue( response.data ); 237 maybeRunNextAsyncTest(); 238 } 239 ); 240 } else { 241 RecalculateProgression(); 242 } 243 } 244 245 } ); -
src/wp-admin/admin-ajax.php
diff --git a/src/wp-admin/admin-ajax.php b/src/wp-admin/admin-ajax.php index 93c32393e0..e0194ceba8 100644
a b $core_actions_post = array( 131 131 'edit-theme-plugin-file', 132 132 'wp-privacy-export-personal-data', 133 133 'wp-privacy-erase-personal-data', 134 'health-check-site-status-result', 135 'health-check-dotorg-communication', 136 'health-check-is-in-debug-mode', 137 'health-check-background-updates', 138 'health-check-loopback-requests', 134 139 ); 135 140 136 141 // Deprecated -
new file src/wp-admin/css/site-health.css
diff --git a/src/wp-admin/css/site-health.css b/src/wp-admin/css/site-health.css new file mode 100644 index 0000000000..69f05abfc1
- + 1 body.site-health #wpcontent { 2 padding-left: 0; 3 } 4 5 body.site-health .wrap { 6 margin-right: 0; 7 margin-left: 0; 8 } 9 10 body.site-health .wrap h2 { 11 padding: 1rem 0; 12 font-size: 1.3em; 13 line-height: 1.4; 14 font-weight: 600; 15 } 16 17 body.site-health ul li, 18 body.site-health ol li { 19 line-height: 1.5; 20 } 21 22 body.site-health .health-check-header { 23 text-align: center; 24 margin-top: 0; 25 margin-bottom: 1rem; 26 background: #fff; 27 border-bottom: 1px solid #e2e4e7; 28 } 29 30 body.site-health .health-check-header .title-section { 31 display: flex; 32 align-items: center; 33 justify-content: center; 34 } 35 36 body.site-health .health-check-header .title-section h1 { 37 display: inline-block; 38 font-weight: 600; 39 margin: 1rem 0.8rem 1rem 0.8rem; 40 } 41 42 body.site-health .health-check-header .title-section #progressbar { 43 display: inline-block; 44 height: 40px; 45 width: 40px; 46 margin: 0; 47 border-radius: 100%; 48 position: relative; 49 font-weight: 600; 50 font-size: 0.4rem; 51 } 52 53 body.site-health .health-check-header .title-section #progressbar:after { 54 position: absolute; 55 display: block; 56 height: 80px; 57 width: 80px; 58 left: 50%; 59 top: 50%; 60 content: attr(data-pct) "%"; 61 margin-top: -40px; 62 margin-left: -40px; 63 border-radius: 100%; 64 line-height: 80px; 65 font-size: 2em; 66 } 67 68 body.site-health .health-check-header .title-section #progressbar.hidden { 69 display: none; 70 } 71 72 body.site-health .health-check-header .title-section #progressbar.loading:after { 73 animation: loadingEllipsis 3s infinite ease-in-out; 74 } 75 76 body.site-health .health-check-header .title-section #progressbar.loading svg #bar { 77 stroke-dashoffset: 0; 78 stroke: #adc5d2; 79 animation: loadingPulse 3s infinite ease-in-out; 80 } 81 82 body.site-health .health-check-header .title-section #progressbar svg circle { 83 stroke-dashoffset: 0; 84 transition: stroke-dashoffset 1s linear; 85 stroke: #ccc; 86 stroke-width: 2em; 87 } 88 89 body.site-health .health-check-header .title-section #progressbar svg #bar { 90 stroke-dashoffset: 565; 91 stroke: #dc3232; 92 } 93 94 body.site-health .health-check-header .title-section #progressbar svg #bar.green { 95 stroke: #46b450; 96 } 97 98 body.site-health .health-check-header .title-section #progressbar svg #bar.orange { 99 stroke: #ffb900; 100 } 101 102 @keyframes loadingPulse { 103 0% { 104 stroke: #adc5d2; 105 } 106 50% { 107 stroke: #00a0d2; 108 } 109 100% { 110 stroke: #adc5d2; 111 } 112 } 113 114 @keyframes loadingEllipsis { 115 0% { 116 content: "."; 117 } 118 50% { 119 content: ".."; 120 } 121 100% { 122 content: "..."; 123 } 124 } 125 126 body.site-health .health-check-header .tabs-wrapper { 127 display: block; 128 } 129 130 body.site-health .health-check-header .tabs-wrapper .tab { 131 float: none; 132 display: inline-block; 133 text-decoration: none; 134 color: inherit; 135 padding: 0.5rem 1rem 1rem; 136 margin: 0 1rem; 137 transition: box-shadow 0.5s ease-in-out; 138 } 139 140 body.site-health .health-check-header .tabs-wrapper .tab:focus { 141 color: #191e23; 142 outline: 1px solid #6c7781; 143 box-shadow: none; 144 } 145 146 body.site-health .health-check-header .tabs-wrapper .tab.active { 147 box-shadow: inset 0 -3px #007cba; 148 font-weight: 600; 149 } 150 151 body.site-health .health-check-body { 152 max-width: 800px; 153 width: 100%; 154 margin: 0 auto; 155 } 156 157 body.site-health .health-check-table thead th:first-child, 158 body.site-health .health-check-table thead td:first-child { 159 width: 30%; 160 } 161 162 body.site-health .health-check-table tbody td { 163 width: 70%; 164 } 165 166 body.site-health .health-check-table tbody td:first-child { 167 width: 30%; 168 } 169 170 body.site-health .health-check-table tbody td ul, 171 body.site-health .health-check-table tbody td ol { 172 margin: 0; 173 } 174 175 body.site-health .pass:before, 176 body.site-health .good:before { 177 content: "\f147"; 178 display: inline-block; 179 color: #46b450; 180 font-family: dashicons; 181 vertical-align: top; 182 } 183 184 body.site-health .warning:before { 185 content: "\f460"; 186 display: inline-block; 187 color: #ffb900; 188 font-family: dashicons; 189 } 190 191 body.site-health .info:before { 192 content: "\f348"; 193 display: inline-block; 194 color: #00a0d2; 195 font-family: dashicons; 196 } 197 198 body.site-health .fail:before, 199 body.site-health .error:before { 200 content: "\f335"; 201 display: inline-block; 202 color: #dc3232; 203 font-family: dashicons; 204 } 205 206 body.site-health .spinner { 207 float: none; 208 } 209 210 body.site-health .system-information-copy-wrapper { 211 display: block; 212 margin: 1rem 0; 213 } 214 215 body.site-health .system-information-copy-wrapper.hidden { 216 display: none; 217 } 218 219 body.site-health .system-information-copy-wrapper textarea { 220 width: 100%; 221 } 222 223 body.site-health .health-check-toggle-copy-section:hover { 224 background: none; 225 } 226 227 body.site-health .system-information-copy-wrapper .copy-button-wrapper { 228 margin: 0.5rem 0 1rem; 229 } 230 231 body.site-health .copy-field-success { 232 display: none; 233 color: #40860a; 234 line-height: 1.8; 235 margin-left: 0.5rem; 236 } 237 238 body.site-health .copy-field-success.visible { 239 display: inline-block; 240 height: 28px; 241 line-height: 28px; 242 } 243 244 body.site-health .site-status-has-issues { 245 display: block; 246 } 247 248 body.site-health .site-status-has-issues.hide { 249 display: none; 250 } 251 252 body.site-health h3 { 253 padding: 0; 254 font-weight: 400; 255 } 256 257 body.site-health .view-more { 258 text-align: center; 259 } 260 261 body.site-health .issues-wrapper:first-of-type { 262 margin-top: 3rem; 263 } 264 265 body.site-health .issues-wrapper { 266 margin-bottom: 4rem; 267 } 268 269 body.site-health .site-status-all-clear { 270 display: flex; 271 flex-direction: column; 272 align-items: center; 273 justify-content: center; 274 text-align: center; 275 height: 100%; 276 width: 100%; 277 margin-top: 0; 278 } 279 280 @media all and (min-width: 784px) { 281 body.site-health .site-status-all-clear { 282 margin: 5rem 0; 283 } 284 } 285 286 body.site-health .site-status-all-clear.hide { 287 display: none; 288 } 289 290 body.site-health .site-status-all-clear .dashicons { 291 font-size: 150px; 292 height: 130px; 293 width: 150px; 294 } 295 296 body.site-health .site-status-all-clear .encouragement { 297 font-size: 1.5rem; 298 font-weight: 600; 299 } 300 301 body.site-health .site-status-all-clear p { 302 margin: 0; 303 } 304 305 body .health-check-accordion { 306 border: 1px solid #e2e4e7; 307 } 308 309 body .health-check-accordion dt { 310 font-weight: 600; 311 border-top: 1px solid #e2e4e7; 312 } 313 314 body .health-check-accordion dt:first-child { 315 border-radius: 0.3em 0.3em 0 0; 316 border-top: none; 317 } 318 319 body .health-check-accordion .health-check-accordion-trigger { 320 background: #fff; 321 border: 0; 322 color: #212121; 323 cursor: pointer; 324 display: block; 325 font-weight: 400; 326 margin: 0; 327 padding: 1em 1.5em; 328 position: relative; 329 text-align: left; 330 width: 100%; 331 } 332 333 body .health-check-accordion .health-check-accordion-trigger:hover, 334 body .health-check-accordion .health-check-accordion-trigger:active { 335 background: #f8f9f9; 336 } 337 338 body .health-check-accordion .health-check-accordion-trigger:focus { 339 color: #191e23; 340 border: none; 341 box-shadow: none; 342 outline-offset: -2px; 343 outline: 1px dotted #555d66; 344 } 345 346 body .health-check-accordion .health-check-accordion-trigger .title { 347 display: inline-block; 348 pointer-events: none; 349 font-weight: 600; 350 } 351 352 body .health-check-accordion .health-check-accordion-trigger .icon { 353 border: solid #191e23; 354 border-width: 0 2px 2px 0; 355 height: 0.5rem; 356 pointer-events: none; 357 position: absolute; 358 right: 1.5em; 359 top: 50%; 360 transform: translateY(-70%) rotate(45deg); 361 width: 0.5rem; 362 } 363 364 body .health-check-accordion .health-check-accordion-trigger .badge { 365 display: inline-block; 366 padding: 0.1rem 0.5rem 0.15rem; 367 background-color: #d7dade; 368 border-radius: 3px; 369 color: #000; 370 font-weight: 600; 371 margin: 0 0.5rem; 372 } 373 374 body .health-check-accordion .health-check-accordion-trigger .badge.blue { 375 background-color: #0073af; 376 color: #fff; 377 } 378 379 body .health-check-accordion .health-check-accordion-trigger .badge.orange { 380 background-color: #ffb900; 381 color: #000; 382 } 383 384 body .health-check-accordion .health-check-accordion-trigger .badge.red { 385 background-color: #dc3232; 386 color: #fff; 387 } 388 389 body .health-check-accordion .health-check-accordion-trigger .badge.green { 390 background-color: #40860a; 391 color: #fff; 392 } 393 394 body .health-check-accordion .health-check-accordion-trigger .badge.pink { 395 background-color: #f4b0fc; 396 color: #000; 397 } 398 399 body .health-check-accordion .health-check-accordion-trigger .badge.gray { 400 background-color: #ccc; 401 color: #000; 402 } 403 404 body .health-check-accordion .health-check-accordion-trigger .badge.light-blue { 405 background-color: #10e9fb; 406 color: #000; 407 } 408 409 body .health-check-accordion .health-check-accordion-trigger .badge.light-green { 410 background-color: #60f999; 411 color: #000; 412 } 413 414 body .health-check-accordion .health-check-accordion-trigger[aria-expanded="true"] .icon { 415 transform: translateY(-30%) rotate(-135deg) 416 } 417 418 body .health-check-accordion .health-check-accordion-panel { 419 margin: 0; 420 padding: 1em 1.5em; 421 background: #fff; 422 } 423 424 body .health-check-accordion .health-check-accordion-panel > div { 425 display: block; 426 } 427 428 body .health-check-accordion .health-check-accordion-panel[hidden] { 429 display: none; 430 } 431 432 body .health-check-accordion dl dd { 433 margin: 0 0 0.5em 2em; 434 } 435 No newline at end of file -
src/wp-admin/css/wp-admin.css
diff --git a/src/wp-admin/css/wp-admin.css b/src/wp-admin/css/wp-admin.css index 14c10f9cd9..b475cf0aaf 100644
a b 12 12 @import url(widgets.css); 13 13 @import url(site-icon.css); 14 14 @import url(l10n.css); 15 @import url(site-health.css); -
src/wp-admin/includes/ajax-actions.php
diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 474319e75c..cb39a2ee4f 100644
a b function wp_ajax_wp_privacy_erase_personal_data() { 4858 4858 4859 4859 wp_send_json_success( $response ); 4860 4860 } 4861 4862 /** 4863 * Ajax handler for site health checks on server communication. 4864 * 4865 * @since 5.2.0 4866 */ 4867 function wp_ajax_health_check_dotorg_communication() { 4868 check_ajax_referer( 'health-check-site-status' ); 4869 4870 if ( ! current_user_can( 'install_plugins' ) ) { 4871 wp_send_json_error(); 4872 } 4873 4874 if ( ! class_exists( 'WP_Site_Health' ) ) { 4875 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 4876 } 4877 4878 $site_health = new WP_Site_Health(); 4879 wp_send_json_success( $site_health->get_test_dotorg_communication() ); 4880 } 4881 4882 /** 4883 * Ajax handler for site health checks on debug mode. 4884 * 4885 * @since 5.2.0 4886 */ 4887 function wp_ajax_health_check_is_in_debug_mode() { 4888 wp_verify_nonce( 'health-check-site-status' ); 4889 4890 if ( ! current_user_can( 'install_plugins' ) ) { 4891 wp_send_json_error(); 4892 } 4893 4894 if ( ! class_exists( 'WP_Site_Health' ) ) { 4895 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 4896 } 4897 4898 $site_health = new WP_Site_Health(); 4899 wp_send_json_success( $site_health->get_test_is_in_debug_mode() ); 4900 } 4901 4902 /** 4903 * Ajax handler for site health checks on background updates. 4904 * 4905 * @since 5.2.0 4906 */ 4907 function wp_ajax_health_check_background_updates() { 4908 check_ajax_referer( 'health-check-site-status' ); 4909 4910 if ( ! current_user_can( 'install_plugins' ) ) { 4911 wp_send_json_error(); 4912 } 4913 4914 if ( ! class_exists( 'WP_Site_Health' ) ) { 4915 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 4916 } 4917 4918 $site_health = new WP_Site_Health(); 4919 wp_send_json_success( $site_health->get_test_background_updates() ); 4920 } 4921 4922 4923 /** 4924 * Ajax handler for site health checks on loopback requests. 4925 * 4926 * @since 5.2.0 4927 */ 4928 function wp_ajax_health_check_loopback_requests() { 4929 check_ajax_referer( 'health-check-site-status' ); 4930 4931 if ( ! current_user_can( 'install_plugins' ) ) { 4932 wp_send_json_error(); 4933 } 4934 4935 if ( ! class_exists( 'WP_Site_Health' ) ) { 4936 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 4937 } 4938 4939 $site_health = new WP_Site_Health(); 4940 wp_send_json_success( $site_health->get_test_loopback_requests() ); 4941 } 4942 4943 /** 4944 * Ajax handler for site health check to update the result status. 4945 * 4946 * @since 5.2.0 4947 */ 4948 function wp_ajax_health_check_site_status_result() { 4949 check_ajax_referer( 'health-check-site-status-result' ); 4950 4951 if ( ! current_user_can( 'install_plugins' ) ) { 4952 wp_send_json_error(); 4953 } 4954 4955 set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) ); 4956 4957 wp_send_json_success(); 4958 } -
new file src/wp-admin/includes/class-wp-debug-data.php
diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php new file mode 100644 index 0000000000..db52b82c80
- + 1 <?php 2 /** 3 * Class for providing debug data based on a users WordPress environment. 4 * 5 * @package WordPress 6 * @subpackage Site_Health 7 * @since 5.2.0 8 */ 9 10 class WP_Debug_Data { 11 /** 12 * Calls all core functions to check for updates. 13 * 14 * @since 5.2.0 15 */ 16 static function check_for_updates() { 17 wp_version_check(); 18 wp_update_plugins(); 19 wp_update_themes(); 20 } 21 22 /** 23 * Static function for generating site debug data when required. 24 * 25 * @since 5.2.0 26 * 27 * @throws ImagickException 28 * @global wpdb $wpdb WordPress database abstraction object. 29 * 30 * @param string $locale Optional. An ISO formatted language code to provide debug translations in. Default null. 31 * @return array The debug data for the site. 32 */ 33 static function debug_data( $locale = null ) { 34 global $wpdb; 35 36 if ( ! empty( $locale ) ) { 37 // Change the language used for translations 38 if ( function_exists( 'switch_to_locale' ) ) { 39 $original_locale = get_locale(); 40 $switched_locale = switch_to_locale( $locale ); 41 } 42 } 43 44 $upload_dir = wp_upload_dir(); 45 if ( file_exists( ABSPATH . 'wp-config.php' ) ) { 46 $wp_config_path = ABSPATH . 'wp-config.php'; 47 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged 48 } elseif ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) { 49 $wp_config_path = dirname( ABSPATH ) . '/wp-config.php'; 50 } 51 52 $core_current_version = get_bloginfo( 'version' ); 53 $core_updates = get_core_updates(); 54 $core_update_needed = ''; 55 56 foreach ( $core_updates as $core => $update ) { 57 if ( 'upgrade' === $update->response ) { 58 // translators: %s: Latest WordPress version number. 59 $core_update_needed = ' ' . sprintf( __( '( Latest version: %s )' ), $update->version ); 60 } else { 61 $core_update_needed = ''; 62 } 63 } 64 65 // Set up the array that holds all debug information. 66 $info = array( 67 'wp-core' => array( 68 'label' => __( 'WordPress' ), 69 'fields' => array( 70 'version' => array( 71 'label' => __( 'Version' ), 72 'value' => $core_current_version . $core_update_needed, 73 ), 74 'language' => array( 75 'label' => __( 'Language' ), 76 'value' => ( ! empty( $locale ) ? $original_locale : get_locale() ), 77 ), 78 'home_url' => array( 79 'label' => __( 'Home URL' ), 80 'value' => get_bloginfo( 'url' ), 81 'private' => true, 82 ), 83 'site_url' => array( 84 'label' => __( 'Site URL' ), 85 'value' => get_bloginfo( 'wpurl' ), 86 'private' => true, 87 ), 88 'permalink' => array( 89 'label' => __( 'Permalink structure' ), 90 'value' => get_option( 'permalink_structure' ) ?: __( 'No permalink structure set' ), 91 ), 92 'https_status' => array( 93 'label' => __( 'Is this site using HTTPS?' ), 94 'value' => ( is_ssl() ? __( 'Yes' ) : __( 'No' ) ), 95 ), 96 'user_registration' => array( 97 'label' => __( 'Can anyone register on this site?' ), 98 'value' => ( get_option( 'users_can_register' ) ? __( 'Yes' ) : __( 'No' ) ), 99 ), 100 'default_comment_status' => array( 101 'label' => __( 'Default comment status' ), 102 'value' => get_option( 'default_comment_status' ), 103 ), 104 'multisite' => array( 105 'label' => __( 'Is this a multisite?' ), 106 'value' => ( is_multisite() ? __( 'Yes' ) : __( 'No' ) ), 107 ), 108 ), 109 ), 110 'wp-dropins' => array( 111 'label' => __( 'Drop-ins' ), 112 'description' => __( 'Drop-ins are single files that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ), 113 'fields' => array(), 114 ), 115 'wp-active-theme' => array( 116 'label' => __( 'Active Theme' ), 117 'fields' => array(), 118 ), 119 'wp-themes' => array( 120 'label' => __( 'Other Themes' ), 121 'show_count' => true, 122 'fields' => array(), 123 ), 124 'wp-mu-plugins' => array( 125 'label' => __( 'Must Use Plugins' ), 126 'show_count' => true, 127 'fields' => array(), 128 ), 129 'wp-plugins-active' => array( 130 'label' => __( 'Active Plugins' ), 131 'show_count' => true, 132 'fields' => array(), 133 ), 134 'wp-plugins-inactive' => array( 135 'label' => __( 'Inactive Plugins' ), 136 'show_count' => true, 137 'fields' => array(), 138 ), 139 'wp-media' => array( 140 'label' => __( 'Media Handling' ), 141 'fields' => array(), 142 ), 143 'wp-server' => array( 144 'label' => __( 'Server' ), 145 'description' => __( "The options shown below relate to your server setup. If changes are required, you may need your web host's assistance." ), 146 'fields' => array(), 147 ), 148 'wp-database' => array( 149 'label' => __( 'Database' ), 150 'fields' => array(), 151 ), 152 'wp-constants' => array( 153 'label' => __( 'WordPress Constants' ), 154 'description' => __( 'These settings are defined in your wp-config.php file, and alter where and hwow parts of WordPress are loaded..' ), 155 'fields' => array( 156 'ABSPATH' => array( 157 'label' => 'ABSPATH', 158 'value' => ( ! defined( 'ABSPATH' ) ? __( 'Undefined' ) : ABSPATH ), 159 'private' => true, 160 ), 161 'WP_HOME' => array( 162 'label' => 'WP_HOME', 163 'value' => ( ! defined( 'WP_HOME' ) ? __( 'Undefined' ) : WP_HOME ), 164 ), 165 'WP_SITEURL' => array( 166 'label' => 'WP_SITEURL', 167 'value' => ( ! defined( 'WP_SITEURL' ) ? __( 'Undefined' ) : WP_SITEURL ), 168 ), 169 'WP_DEBUG' => array( 170 'label' => 'WP_DEBUG', 171 'value' => ( ! defined( 'WP_DEBUG' ) ? __( 'Undefined' ) : ( WP_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 172 ), 173 'WP_MAX_MEMORY_LIMIT' => array( 174 'label' => 'WP_MAX_MEMORY_LIMIT', 175 'value' => ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ? __( 'Undefined' ) : WP_MAX_MEMORY_LIMIT ), 176 ), 177 'WP_DEBUG_DISPLAY' => array( 178 'label' => 'WP_DEBUG_DISPLAY', 179 'value' => ( ! defined( 'WP_DEBUG_DISPLAY' ) ? __( 'Undefined' ) : ( WP_DEBUG_DISPLAY ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 180 ), 181 'WP_DEBUG_LOG' => array( 182 'label' => 'WP_DEBUG_LOG', 183 'value' => ( ! defined( 'WP_DEBUG_LOG' ) ? __( 'Undefined' ) : ( WP_DEBUG_LOG ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 184 ), 185 'SCRIPT_DEBUG' => array( 186 'label' => 'SCRIPT_DEBUG', 187 'value' => ( ! defined( 'SCRIPT_DEBUG' ) ? __( 'Undefined' ) : ( SCRIPT_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 188 ), 189 'WP_CACHE' => array( 190 'label' => 'WP_CACHE', 191 'value' => ( ! defined( 'WP_CACHE' ) ? __( 'Undefined' ) : ( WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 192 ), 193 'CONCATENATE_SCRIPTS' => array( 194 'label' => 'CONCATENATE_SCRIPTS', 195 'value' => ( ! defined( 'CONCATENATE_SCRIPTS' ) ? __( 'Undefined' ) : ( CONCATENATE_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 196 ), 197 'COMPRESS_SCRIPTS' => array( 198 'label' => 'COMPRESS_SCRIPTS', 199 'value' => ( ! defined( 'COMPRESS_SCRIPTS' ) ? __( 'Undefined' ) : ( COMPRESS_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 200 ), 201 'COMPRESS_CSS' => array( 202 'label' => 'COMPRESS_CSS', 203 'value' => ( ! defined( 'COMPRESS_CSS' ) ? __( 'Undefined' ) : ( COMPRESS_CSS ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 204 ), 205 'WP_LOCAL_DEV' => array( 206 'label' => 'WP_LOCAL_DEV', 207 'value' => ( ! defined( 'WP_LOCAL_DEV' ) ? __( 'Undefined' ) : ( WP_LOCAL_DEV ? __( 'Enabled' ) : __( 'Disabled' ) ) ), 208 ), 209 ), 210 ), 211 'wp-filesystem' => array( 212 'label' => __( 'Filesystem Permissions' ), 213 'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ), 214 'fields' => array( 215 'all' => array( 216 'label' => __( 'The main WordPress directory' ), 217 'value' => ( wp_is_writable( ABSPATH ) ? __( 'Writable' ) : __( 'Not writable' ) ), 218 ), 219 'wp-content' => array( 220 'label' => __( 'The wp-content directory' ), 221 'value' => ( wp_is_writable( WP_CONTENT_DIR ) ? __( 'Writable' ) : __( 'Not writable' ) ), 222 ), 223 'uploads' => array( 224 'label' => __( 'The uploads directory' ), 225 'value' => ( wp_is_writable( $upload_dir['basedir'] ) ? __( 'Writable' ) : __( 'Not writable' ) ), 226 ), 227 'plugins' => array( 228 'label' => __( 'The plugins directory' ), 229 'value' => ( wp_is_writable( WP_PLUGIN_DIR ) ? __( 'Writable' ) : __( 'Not writable' ) ), 230 ), 231 'themes' => array( 232 'label' => __( 'The themes directory' ), 233 'value' => ( wp_is_writable( get_template_directory() . '/..' ) ? __( 'Writable' ) : __( 'Not writable' ) ), 234 ), 235 ), 236 ), 237 ); 238 239 // Conditionally add debug information for multisite setups. 240 if ( is_multisite() ) { 241 $network_query = new WP_Network_Query(); 242 $network_ids = $network_query->query( 243 array( 244 'fields' => 'ids', 245 'number' => 100, 246 'no_found_rows' => false, 247 ) 248 ); 249 250 $site_count = 0; 251 foreach ( $network_ids as $network_id ) { 252 $site_count += get_blog_count( $network_id ); 253 } 254 255 $info['wp-core']['fields']['user_count'] = array( 256 'label' => __( 'User count' ), 257 'value' => get_user_count(), 258 ); 259 $info['wp-core']['fields']['site_count'] = array( 260 'label' => __( 'Site count' ), 261 'value' => $site_count, 262 ); 263 $info['wp-core']['fields']['network_count'] = array( 264 'label' => __( 'Network count' ), 265 'value' => $network_query->found_networks, 266 ); 267 } else { 268 $user_count = count_users(); 269 270 $info['wp-core']['fields']['user_count'] = array( 271 'label' => __( 'User count' ), 272 'value' => $user_count['total_users'], 273 ); 274 } 275 276 // WordPress features requiring processing. 277 $wp_dotorg = wp_remote_get( 278 'https://wordpress.org', 279 array( 280 'timeout' => 10, 281 ) 282 ); 283 if ( ! is_wp_error( $wp_dotorg ) ) { 284 $info['wp-core']['fields']['dotorg_communication'] = array( 285 'label' => __( 'Communication with WordPress.org' ), 286 'value' => sprintf( 287 __( 'WordPress.org is reachable' ) 288 ), 289 ); 290 } else { 291 $info['wp-core']['fields']['dotorg_communication'] = array( 292 'label' => __( 'Communication with WordPress.org' ), 293 'value' => sprintf( 294 // translators: %1$s: The IP address WordPress.org resolves to. %2$s: The error returned by the lookup. 295 __( 'Unable to reach WordPress.org at %1$s: %2$s' ), 296 gethostbyname( 'wordpress.org' ), 297 $wp_dotorg->get_error_message() 298 ), 299 ); 300 } 301 302 // Get a list of all drop-in replacements. 303 $dropins = get_dropins(); 304 $dropin_description = _get_dropins(); 305 foreach ( $dropins as $dropin_key => $dropin ) { 306 $info['wp-dropins']['fields'][ sanitize_key( $dropin_key ) ] = array( 307 'label' => $dropin_key, 308 'value' => $dropin_description[ $dropin_key ][0], 309 ); 310 } 311 312 // Populate the media fields. 313 $info['wp-media']['fields']['image_editor'] = array( 314 'label' => __( 'Active editor' ), 315 'value' => _wp_image_editor_choose(), 316 ); 317 318 // Get ImageMagic information, if available. 319 if ( class_exists( 'Imagick' ) ) { 320 // Save the Imagick instance for later use. 321 $imagick = new Imagick(); 322 $imagick_version = $imagick->getVersion(); 323 } else { 324 $imagick_version = __( 'Not available' ); 325 } 326 $info['wp-media']['fields']['imagick_module_version'] = array( 327 'label' => __( 'ImageMagick version number' ), 328 'value' => ( is_array( $imagick_version ) ? $imagick_version['versionNumber'] : $imagick_version ), 329 ); 330 $info['wp-media']['fields']['imagemagick_version'] = array( 331 'label' => __( 'ImageMagick version string' ), 332 'value' => ( is_array( $imagick_version ) ? $imagick_version['versionString'] : $imagick_version ), 333 ); 334 335 // If Imagick is used as our editor, provide some more information about its limitations. 336 if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) { 337 $limits = array( 338 'area' => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : __( 'Not available' ) ), 339 'disk' => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : __( 'Not available' ) ), 340 'file' => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : __( 'Not available' ) ), 341 'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : __( 'Not available' ) ), 342 'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : __( 'Not available' ) ), 343 'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : __( 'Not available' ) ), 344 ); 345 346 $info['wp-media']['fields']['imagick_limits'] = array( 347 'label' => __( 'Imagick Resource Limits' ), 348 'value' => $limits, 349 ); 350 } 351 352 // Get GD information, if available. 353 if ( function_exists( 'gd_info' ) ) { 354 $gd = gd_info(); 355 } else { 356 $gd = false; 357 } 358 $info['wp-media']['fields']['gd_version'] = array( 359 'label' => __( 'GD version' ), 360 'value' => ( is_array( $gd ) ? $gd['GD Version'] : __( 'Not available' ) ), 361 ); 362 363 // Get Ghostscript information, if available. 364 if ( function_exists( 'exec' ) ) { 365 $gs = exec( 'gs --version' ); 366 $gs = ( ! empty( $gs ) ? $gs : __( 'Not available' ) ); 367 } else { 368 $gs = __( 'Unable to determine if Ghostscript is installed' ); 369 } 370 $info['wp-media']['fields']['ghostscript_version'] = array( 371 'label' => __( 'Ghostscript version' ), 372 'value' => $gs, 373 ); 374 375 // Populate the server debug fields. 376 $info['wp-server']['fields']['server_architecture'] = array( 377 'label' => __( 'Server architecture' ), 378 'value' => ( ! function_exists( 'php_uname' ) ? __( 'Unable to determine server architecture' ) : sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) ) ), 379 ); 380 $info['wp-server']['fields']['httpd_software'] = array( 381 'label' => __( 'Web server' ), 382 'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ), 383 ); 384 $info['wp-server']['fields']['php_version'] = array( 385 'label' => __( 'PHP version' ), 386 'value' => ( ! function_exists( 'phpversion' ) ? __( 'Unable to determine PHP version' ) : sprintf( 387 '%s %s', 388 phpversion(), 389 ( 64 === PHP_INT_SIZE * 8 ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) ) 390 ) 391 ), 392 ); 393 $info['wp-server']['fields']['php_sapi'] = array( 394 'label' => __( 'PHP SAPI' ), 395 'value' => ( ! function_exists( 'php_sapi_name' ) ? __( 'Unable to determine PHP SAPI' ) : php_sapi_name() ), 396 ); 397 398 // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values. 399 if ( ! function_exists( 'ini_get' ) ) { 400 $info['wp-server']['fields']['ini_get'] = array( 401 'label' => __( 'Server settings' ), 402 'value' => __( 'Unable to determine some settings, as the ini_get() function has been disabled.' ), 403 ); 404 } else { 405 $info['wp-server']['fields']['max_input_variables'] = array( 406 'label' => __( 'PHP max input variables' ), 407 'value' => ini_get( 'max_input_vars' ), 408 ); 409 $info['wp-server']['fields']['time_limit'] = array( 410 'label' => __( 'PHP time limit' ), 411 'value' => ini_get( 'max_execution_time' ), 412 ); 413 $info['wp-server']['fields']['memory_limit'] = array( 414 'label' => __( 'PHP memory limit' ), 415 'value' => ini_get( 'memory_limit' ), 416 ); 417 $info['wp-server']['fields']['max_input_time'] = array( 418 'label' => __( 'Max input time' ), 419 'value' => ini_get( 'max_input_time' ), 420 ); 421 $info['wp-server']['fields']['upload_max_size'] = array( 422 'label' => __( 'Upload max filesize' ), 423 'value' => ini_get( 'upload_max_filesize' ), 424 ); 425 $info['wp-server']['fields']['php_post_max_size'] = array( 426 'label' => __( 'PHP post max size' ), 427 'value' => ini_get( 'post_max_size' ), 428 ); 429 } 430 431 if ( function_exists( 'curl_version' ) ) { 432 $curl = curl_version(); 433 434 $info['wp-server']['fields']['curl_version'] = array( 435 'label' => __( 'cURL version' ), 436 'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ), 437 ); 438 } else { 439 $info['wp-server']['fields']['curl_version'] = array( 440 'label' => __( 'cURL version' ), 441 'value' => __( 'Not available' ), 442 ); 443 } 444 445 $info['wp-server']['fields']['suhosin'] = array( 446 'label' => __( 'Is SUHOSIN installed?' ), 447 'value' => ( ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) ) ? __( 'Yes' ) : __( 'No' ) ), 448 ); 449 450 $info['wp-server']['fields']['imagick_availability'] = array( 451 'label' => __( 'Is the Imagick library available?' ), 452 'value' => ( extension_loaded( 'imagick' ) ? __( 'Yes' ) : __( 'No' ) ), 453 ); 454 455 // Check if a .htaccess file exists. 456 if ( is_file( ABSPATH . '/.htaccess' ) ) { 457 // If the file exists, grab the content of it. 458 $htaccess_content = file_get_contents( ABSPATH . '/.htaccess' ); 459 460 // Filter away the core WordPress rules. 461 $filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) ); 462 463 $info['wp-server']['fields']['htaccess_extra_rules'] = array( 464 'label' => __( 'htaccess rules' ), 465 'value' => ( ! empty( $filtered_htaccess_content ) ? __( 'Custom rules have been added to your htaccess file.' ) : __( 'Your htaccess file contains only core WordPress features.' ) ), 466 ); 467 } 468 469 // Populate the database debug fields. 470 if ( is_resource( $wpdb->dbh ) ) { 471 // Old mysql extension. 472 $extension = 'mysql'; 473 } elseif ( is_object( $wpdb->dbh ) ) { 474 // mysqli or PDO. 475 $extension = get_class( $wpdb->dbh ); 476 } else { 477 // Unknown sql extension. 478 $extension = null; 479 } 480 481 /* 482 * Check what database engine is used, this will throw compatibility 483 * warnings from PHP compatibility testers, but `mysql_*` is 484 * still valid in PHP 5.6, so we need to account for that. 485 */ 486 if ( method_exists( $wpdb, 'db_version' ) ) { 487 if ( $wpdb->use_mysqli ) { 488 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info 489 $server = mysqli_get_server_info( $wpdb->dbh ); 490 } else { 491 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info 492 $server = mysql_get_server_info( $wpdb->dbh ); 493 } 494 } else { 495 $server = null; 496 } 497 498 if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) { 499 $client_version = $wpdb->dbh->client_info; 500 } else { 501 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info 502 if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) { 503 $client_version = $matches[0]; 504 } else { 505 $client_version = null; 506 } 507 } 508 509 $info['wp-database']['fields']['extension'] = array( 510 'label' => __( 'Extension' ), 511 'value' => $extension, 512 ); 513 $info['wp-database']['fields']['server_version'] = array( 514 'label' => __( 'Server version' ), 515 'value' => $server, 516 ); 517 $info['wp-database']['fields']['client_version'] = array( 518 'label' => __( 'Client version' ), 519 'value' => $client_version, 520 ); 521 $info['wp-database']['fields']['database_user'] = array( 522 'label' => __( 'Database user' ), 523 'value' => $wpdb->dbuser, 524 'private' => true, 525 ); 526 $info['wp-database']['fields']['database_host'] = array( 527 'label' => __( 'Database host' ), 528 'value' => $wpdb->dbhost, 529 'private' => true, 530 ); 531 $info['wp-database']['fields']['database_name'] = array( 532 'label' => __( 'Database name' ), 533 'value' => $wpdb->dbname, 534 'private' => true, 535 ); 536 $info['wp-database']['fields']['database_prefix'] = array( 537 'label' => __( 'Database prefix' ), 538 'value' => $wpdb->prefix, 539 'private' => true, 540 ); 541 542 // List must use plugins if there are any. 543 $mu_plugins = get_mu_plugins(); 544 545 foreach ( $mu_plugins as $plugin_path => $plugin ) { 546 $plugin_version = $plugin['Version']; 547 $plugin_author = $plugin['Author']; 548 549 $plugin_version_string = __( 'No version or author information is available.' ); 550 551 if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) { 552 // translators: %1$s: Plugin version number. %2$s: Plugin author name. 553 $plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author ); 554 } 555 if ( empty( $plugin_version ) && ! empty( $plugin_author ) ) { 556 // translators: %s: Plugin author name. 557 $plugin_version_string = sprintf( __( 'By %s' ), $plugin_author ); 558 } 559 if ( ! empty( $plugin_version ) && empty( $plugin_author ) ) { 560 // translators: %s: Plugin version number. 561 $plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version ); 562 } 563 564 $info['wp-mu-plugins']['fields'][ sanitize_key( $plugin['Name'] ) ] = array( 565 'label' => $plugin['Name'], 566 'value' => $plugin_version_string, 567 ); 568 } 569 570 // List all available plugins. 571 $plugins = get_plugins(); 572 $plugin_updates = get_plugin_updates(); 573 574 foreach ( $plugins as $plugin_path => $plugin ) { 575 $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive'; 576 577 $plugin_version = $plugin['Version']; 578 $plugin_author = $plugin['Author']; 579 580 $plugin_version_string = __( 'No version or author information is available.' ); 581 582 if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) { 583 // translators: %1$s: Plugin version number. %2$s: Plugin author name. 584 $plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author ); 585 } 586 if ( empty( $plugin_version ) && ! empty( $plugin_author ) ) { 587 // translators: %s: Plugin author name. 588 $plugin_version_string = sprintf( __( 'By %s' ), $plugin_author ); 589 } 590 if ( ! empty( $plugin_version ) && empty( $plugin_author ) ) { 591 // translators: %s: Plugin version number. 592 $plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version ); 593 } 594 595 if ( array_key_exists( $plugin_path, $plugin_updates ) ) { 596 // translators: %s: Latest plugin version number. 597 $plugin_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version ); 598 } else { 599 $plugin_update_needed = ''; 600 } 601 602 $info[ $plugin_part ]['fields'][ sanitize_key( $plugin['Name'] ) ] = array( 603 'label' => $plugin['Name'], 604 'value' => $plugin_version_string . $plugin_update_needed, 605 ); 606 } 607 608 // Populate the section for the currently active theme. 609 global $_wp_theme_features; 610 $theme_features = array(); 611 if ( ! empty( $_wp_theme_features ) ) { 612 foreach ( $_wp_theme_features as $feature => $options ) { 613 $theme_features[] = $feature; 614 } 615 } 616 617 $active_theme = wp_get_theme(); 618 $theme_updates = get_theme_updates(); 619 620 if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) { 621 // translators: %s: Latest theme version number. 622 $theme_update_needed_active = ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $active_theme->stylesheet ]->update['new_version'] ); 623 } else { 624 $theme_update_needed_active = ''; 625 } 626 627 $info['wp-active-theme']['fields'] = array( 628 'name' => array( 629 'label' => __( 'Name' ), 630 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 631 'value' => $active_theme->Name, 632 ), 633 'version' => array( 634 'label' => __( 'Version' ), 635 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 636 'value' => $active_theme->Version . $theme_update_needed_active, 637 ), 638 'author' => array( 639 'label' => __( 'Author' ), 640 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 641 'value' => wp_kses( $active_theme->Author, array() ), 642 ), 643 'author_website' => array( 644 'label' => __( 'Author website' ), 645 'value' => ( $active_theme->offsetGet( 'Author URI' ) ? $active_theme->offsetGet( 'Author URI' ) : __( 'Undefined' ) ), 646 ), 647 'parent_theme' => array( 648 'label' => __( 'Parent theme' ), 649 'value' => ( $active_theme->parent_theme ? $active_theme->parent_theme : __( 'None' ) ), 650 ), 651 'theme_features' => array( 652 'label' => __( 'Theme features' ), 653 'value' => implode( ', ', $theme_features ), 654 ), 655 ); 656 657 // Populate a list of all themes available in the install. 658 $all_themes = wp_get_themes(); 659 660 foreach ( $all_themes as $theme_slug => $theme ) { 661 // Ignore the currently active theme from the list of all themes. 662 if ( $active_theme->stylesheet == $theme_slug ) { 663 continue; 664 } 665 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 666 $theme_version = $theme->Version; 667 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 668 $theme_author = $theme->Author; 669 670 $theme_version_string = __( 'No version or author information is available.' ); 671 672 if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) { 673 // translators: %1$s: Theme version number. %2$s: Theme author name. 674 $theme_version_string = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, wp_kses( $theme_author, array() ) ); 675 } 676 if ( empty( $theme_version ) && ! empty( $theme_author ) ) { 677 // translators: %s: Theme author name. 678 $theme_version_string = sprintf( __( 'By %s' ), wp_kses( $theme_author, array() ) ); 679 } 680 if ( ! empty( $theme_version ) && empty( $theme_author ) ) { 681 // translators: %s: Theme version number. 682 $theme_version_string = sprintf( __( 'Version %s' ), $theme_version ); 683 } 684 685 if ( array_key_exists( $theme_slug, $theme_updates ) ) { 686 // translators: %s: Latest theme version number. 687 $theme_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] ); 688 } else { 689 $theme_update_needed = ''; 690 } 691 692 $info['wp-themes']['fields'][ sanitize_key( $theme->Name ) ] = array( 693 'label' => sprintf( 694 // translators: %1$s: Theme name. %2$s: Theme slug. 695 __( '%1$s (%2$s)' ), 696 // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 697 $theme->Name, 698 $theme_slug 699 ), 700 'value' => $theme_version_string . $theme_update_needed, 701 ); 702 } 703 704 // Add more filesystem checks 705 if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) { 706 $info['wp-filesystem']['fields']['mu_plugin_directory'] = array( 707 'label' => __( 'The must use plugins directory' ), 708 'value' => ( wp_is_writable( WPMU_PLUGIN_DIR ) ? __( 'Writable' ) : __( 'Not writable' ) ), 709 ); 710 } 711 712 /** 713 * Add or modify new debug sections. 714 * 715 * Plugin or themes may wish to introduce their own debug information without creating additional admin pages for this 716 * kind of information as it is rarely needed, they can then utilize this filter to introduce their own sections. 717 * 718 * Array keys added by core are all prefixed with `wp-`, plugins and themes are encouraged to use their own slug as 719 * a prefix, both for consistency as well as avoiding key collisions. 720 * 721 * @since 5.2.0 722 * 723 * @param array $args { 724 * The debug information to be added to the core information page. 725 * 726 * @type string $label The title for this section of the debug output. 727 * @type string $description Optional. A description for your information section which may contain basic HTML 728 * markup: `em`, `strong` and `a` for linking to documentation or putting emphasis. 729 * @type boolean $show_count Optional. If set to `true` the amount of fields will be included in the title for 730 * this section. 731 * @type boolean $private Optional. If set to `true` the section and all associated fields will be excluded 732 * from the copy-paste text area. 733 * @type array $fields { 734 * An associative array containing the data to be displayed. 735 * 736 * @type string $label The label for this piece of information. 737 * @type string $value The output that is of interest for this field. 738 * @type boolean $private Optional. If set to `true` the field will not be included in the copy-paste text area 739 * on top of the page, allowing you to show, for example, API keys here. 740 * } 741 * } 742 */ 743 $info = apply_filters( 'debug_information', $info ); 744 745 if ( ! empty( $locale ) ) { 746 // Change the language used for translations 747 if ( function_exists( 'restore_previous_locale' ) && $switched_locale ) { 748 restore_previous_locale(); 749 } 750 } 751 752 return $info; 753 } 754 755 /** 756 * Print the formatted variation of the information gathered for debugging, in a manner 757 * suitable for a text area that can be instantly copied to a forum or support ticket. 758 * 759 * @since 5.2.0 760 * 761 * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function. 762 */ 763 public static function textarea_format( $info_array ) { 764 echo "`\n"; 765 766 foreach ( $info_array as $section => $details ) { 767 // Skip this section if there are no fields, or the section has been declared as private. 768 if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) { 769 continue; 770 } 771 772 printf( 773 "### %s%s ###\n\n", 774 $details['label'], 775 ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' ) 776 ); 777 778 foreach ( $details['fields'] as $field ) { 779 if ( isset( $field['private'] ) && true === $field['private'] ) { 780 continue; 781 } 782 783 $values = $field['value']; 784 if ( is_array( $field['value'] ) ) { 785 $values = ''; 786 787 foreach ( $field['value'] as $name => $value ) { 788 $values .= sprintf( 789 "\n\t%s: %s", 790 $name, 791 $value 792 ); 793 } 794 } 795 796 printf( 797 "%s: %s\n", 798 $field['label'], 799 $values 800 ); 801 } 802 echo "\n"; 803 } 804 echo '`'; 805 } 806 807 /** 808 * Return the size of a directory, including all subdirectories. 809 * 810 * @since 5.2.0 811 * 812 * @param string $path The directory to check. 813 * @return int The directory size, in bytes. 814 */ 815 public static function get_directory_size( $path ) { 816 $size = 0; 817 818 foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ) ) as $file ) { 819 $size += $file->getSize(); 820 } 821 822 return $size; 823 } 824 825 /** 826 * Fetch the total size of all the database tables for the active database user. 827 * 828 * @since 5.2.0 829 * 830 * @return int The size of the database, in bytes. 831 */ 832 public static function get_database_size() { 833 global $wpdb; 834 $size = 0; 835 $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A ); 836 837 if ( $wpdb->num_rows > 0 ) { 838 foreach ( $rows as $row ) { 839 $size += $row['Data_length'] + $row['Index_length']; 840 } 841 } 842 843 return $size; 844 } 845 } -
new file src/wp-admin/includes/class-wp-site-health-auto-updates.php
diff --git a/src/wp-admin/includes/class-wp-site-health-auto-updates.php b/src/wp-admin/includes/class-wp-site-health-auto-updates.php new file mode 100644 index 0000000000..b445fd5f59
- + 1 <?php 2 /** 3 * Class for testing automatic updates in the WordPress code. 4 * 5 * @package WordPress 6 * @subpackage Site_Health 7 * @since 5.2.0 8 */ 9 10 class WP_Site_Health_Auto_Updates { 11 /** 12 * WP_Site_Health_Auto_Updates constructor. 13 * @since 5.2.0 14 */ 15 public function __construct() { 16 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 17 } 18 19 20 /** 21 * Run tests to determine if auto-updates can run. 22 * 23 * @since 5.2.0 24 * 25 * @return array The test results. 26 */ 27 public function run_tests() { 28 $tests = array( 29 $this->test_constants( 'DISALLOW_FILE_MODS', false ), 30 $this->test_constants( 'AUTOMATIC_UPDATER_DISABLED', false ), 31 $this->test_constants( 'WP_AUTO_UPDATE_CORE', true ), 32 $this->test_wp_version_check_attached(), 33 $this->test_filters_automatic_updater_disabled(), 34 $this->test_if_failed_update(), 35 $this->test_vcs_abspath(), 36 $this->test_check_wp_filesystem_method(), 37 $this->test_all_files_writable(), 38 $this->test_accepts_dev_updates(), 39 $this->test_accepts_minor_updates(), 40 ); 41 42 $tests = array_filter( $tests ); 43 $tests = array_map( 44 function( $test ) { 45 $test = (object) $test; 46 47 if ( empty( $test->severity ) ) { 48 $test->severity = 'warning'; 49 } 50 51 return $test; 52 }, 53 $tests 54 ); 55 56 return $tests; 57 } 58 59 /** 60 * Test if auto-updated related constants are set correctly. 61 * 62 * @since 5.2.0 63 * 64 * @param string $constant The name of the constant to check. 65 * @param bool $value The value that the constant should be, if set. 66 * @return array The test results. 67 */ 68 public function test_constants( $constant, $value ) { 69 if ( defined( $constant ) && constant( $constant ) != $allowed_constants[ $constant ] ) { 70 return array( 71 'description' => sprintf( 72 /* translators: %s: Name of the constant used. */ 73 __( 'The %s constant is defined and enabled.' ), 74 "<code>$constant</code>" 75 ), 76 'severity' => 'fail', 77 ); 78 } 79 } 80 81 /** 82 * Check if updates are intercepted by a filter. 83 * 84 * @since 5.2.0 85 * 86 * @return array The test results. 87 */ 88 public function test_wp_version_check_attached() { 89 $cookies = wp_unslash( $_COOKIE ); 90 $timeout = 10; 91 $headers = array( 92 'Cache-Control' => 'no-cache', 93 ); 94 95 // Include Basic auth in loopback requests. 96 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { 97 $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); 98 } 99 100 $url = add_query_arg( 101 array( 102 'health-check-test-wp_version_check' => true, 103 ), 104 admin_url() 105 ); 106 107 $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) ); 108 109 $response = wp_remote_retrieve_body( $test ); 110 111 if ( 'yes' !== $response ) { 112 return array( 113 'description' => sprintf( 114 /* translators: %s: Name of the filter used. */ 115 __( 'A plugin has prevented updates by disabling %s.' ), 116 '<code>wp_version_check()</code>' 117 ), 118 'severity' => 'fail', 119 ); 120 } 121 } 122 123 /** 124 * Check if automatic updates are disabled by a filter. 125 * 126 * @since 5.2.0 127 * 128 * @return array The test results. 129 */ 130 public function test_filters_automatic_updater_disabled() { 131 if ( apply_filters( 'automatic_updater_disabled', false ) ) { 132 return array( 133 'description' => sprintf( 134 /* translators: %s: Name of the filter used. */ 135 __( 'The %s filter is enabled.' ), 136 '<code>automatic_updater_disabled</code>' 137 ), 138 'severity' => 'fail', 139 ); 140 } 141 } 142 143 /** 144 * Check if automatic updates have tried to run, but failed, previously. 145 * 146 * @since 5.2.0 147 * 148 * @return array|bool The test results. false if the auto updates failed. 149 */ 150 function test_if_failed_update() { 151 $failed = get_site_option( 'auto_core_update_failed' ); 152 153 if ( ! $failed ) { 154 return false; 155 } 156 157 if ( ! empty( $failed['critical'] ) ) { 158 $description = __( 'A previous automatic background update ended with a critical failure, so updates are now disabled.' ); 159 $description .= ' ' . __( 'You would have received an email because of this.' ); 160 $description .= ' ' . __( "When you've been able to update using the \"Update Now\" button on Dashboard > Updates, we'll clear this error for future update attempts." ); 161 $description .= ' ' . sprintf( 162 /* translators: %s: Code of error shown. */ 163 __( 'The error code was %s.' ), 164 '<code>' . $failed['error_code'] . '</code>' 165 ); 166 return array( 167 'description' => $description, 168 'severity' => 'warning', 169 ); 170 } 171 172 $description = __( 'A previous automatic background update could not occur.' ); 173 if ( empty( $failed['retry'] ) ) { 174 $description .= ' ' . __( 'You would have received an email because of this.' ); 175 } 176 177 $description .= ' ' . __( "We'll try again with the next release." ); 178 $description .= ' ' . sprintf( 179 /* translators: %s: Code of error shown. */ 180 __( 'The error code was %s.' ), 181 '<code>' . $failed['error_code'] . '</code>' 182 ); 183 return array( 184 'description' => $description, 185 'severity' => 'warning', 186 ); 187 } 188 189 /** 190 * Check if WordPress is controlled by a VCS (Git, Subversion etc). 191 * 192 * @since 5.2.0 193 * 194 * @return array The test results. 195 */ 196 public function test_vcs_abspath() { 197 $context_dirs = array( ABSPATH ); 198 $vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' ); 199 $check_dirs = array(); 200 201 foreach ( $context_dirs as $context_dir ) { 202 // Walk up from $context_dir to the root. 203 do { 204 $check_dirs[] = $context_dir; 205 206 // Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here. 207 if ( dirname( $context_dir ) == $context_dir ) { 208 break; 209 } 210 211 // Continue one level at a time. 212 } while ( $context_dir = dirname( $context_dir ) ); 213 } 214 215 $check_dirs = array_unique( $check_dirs ); 216 217 // Search all directories we've found for evidence of version control. 218 foreach ( $vcs_dirs as $vcs_dir ) { 219 foreach ( $check_dirs as $check_dir ) { 220 // phpcs:ignore 221 if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) { 222 break 2; 223 } 224 } 225 } 226 227 if ( $checkout && ! apply_filters( 'automatic_updates_is_vcs_checkout', true, ABSPATH ) ) { 228 return array( 229 'description' => sprintf( 230 // translators: %1$s: Folder name. %2$s: Version control directory. %3$s: Filter name. 231 __( 'The folder %1$s was detected as being under version control (%2$s), but the %3$s filter is allowing updates.' ), 232 '<code>' . $check_dir . '</code>', 233 "<code>$vcs_dir</code>", 234 '<code>automatic_updates_is_vcs_checkout</code>' 235 ), 236 'severity' => 'info', 237 ); 238 } 239 240 if ( $checkout ) { 241 return array( 242 'description' => sprintf( 243 // translators: %1$s: Folder name. %2$s: Version control directory. 244 __( 'The folder %1$s was detected as being under version control (%2$s).' ), 245 '<code>' . $check_dir . '</code>', 246 "<code>$vcs_dir</code>" 247 ), 248 'severity' => 'fail', 249 ); 250 } 251 252 return array( 253 'description' => __( 'No version control systems were detected.' ), 254 'severity' => 'pass', 255 ); 256 } 257 258 /** 259 * Check if we can access files without providing credentials. 260 * 261 * @since 5.2.0 262 * 263 * @return array The test results. 264 */ 265 function test_check_wp_filesystem_method() { 266 $skin = new Automatic_Upgrader_Skin; 267 $success = $skin->request_filesystem_credentials( false, ABSPATH ); 268 269 if ( ! $success ) { 270 $description = __( 'Your installation of WordPress prompts for FTP credentials to perform updates.' ); 271 $description .= ' ' . __( '(Your site is performing updates over FTP due to file ownership. Talk to your hosting company.)' ); 272 273 return array( 274 'description' => $description, 275 'severity' => 'fail', 276 ); 277 } 278 279 return array( 280 'description' => __( "Your installation of WordPress doesn't require FTP credentials to perform updates." ), 281 'severity' => 'pass', 282 ); 283 } 284 285 /** 286 * Check if core files are writable by the web user/group. 287 * 288 * @since 5.2.0 289 * 290 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. 291 * 292 * @return array|bool The test results. false if they're not writeable. 293 */ 294 function test_all_files_writable() { 295 global $wp_filesystem; 296 297 include ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z 298 299 $skin = new Automatic_Upgrader_Skin; 300 $success = $skin->request_filesystem_credentials( false, ABSPATH ); 301 302 if ( ! $success ) { 303 return false; 304 } 305 306 WP_Filesystem(); 307 308 if ( 'direct' != $wp_filesystem->method ) { 309 return false; 310 } 311 312 $checksums = get_core_checksums( $wp_version, 'en_US' ); 313 $dev = ( false !== strpos( $wp_version, '-' ) ); 314 // Get the last stable version's files and test against that 315 if ( ! $checksums && $dev ) { 316 $checksums = get_core_checksums( (float) $wp_version - 0.1, 'en_US' ); 317 } 318 319 // There aren't always checksums for development releases, so just skip the test if we still can't find any 320 if ( ! $checksums && $dev ) { 321 return false; 322 } 323 324 if ( ! $checksums ) { 325 $description = sprintf( 326 // translators: %s: WordPress version 327 __( "Couldn't retrieve a list of the checksums for WordPress %s." ), 328 $wp_version 329 ); 330 $description .= ' ' . __( 'This could mean that connections are failing to WordPress.org.' ); 331 return array( 332 'description' => $description, 333 'severity' => 'warning', 334 ); 335 } 336 337 $unwritable_files = array(); 338 foreach ( array_keys( $checksums ) as $file ) { 339 if ( 'wp-content' == substr( $file, 0, 10 ) ) { 340 continue; 341 } 342 if ( ! file_exists( ABSPATH . '/' . $file ) ) { 343 continue; 344 } 345 if ( ! is_writable( ABSPATH . '/' . $file ) ) { 346 $unwritable_files[] = $file; 347 } 348 } 349 350 if ( $unwritable_files ) { 351 if ( count( $unwritable_files ) > 20 ) { 352 $unwritable_files = array_slice( $unwritable_files, 0, 20 ); 353 $unwritable_files[] = '...'; 354 } 355 return array( 356 'description' => __( 'Some files are not writable by WordPress:' ) . ' <ul><li>' . implode( '</li><li>', $unwritable_files ) . '</li></ul>', 357 'severity' => 'fail', 358 ); 359 } else { 360 return array( 361 'description' => __( 'All of your WordPress files are writable.' ), 362 'severity' => 'pass', 363 ); 364 } 365 } 366 367 /** 368 * Check if the install is using a development branch and can use nightly packages. 369 * 370 * @since 5.2.0 371 * 372 * @return array|bool The test results. false if it isn't a development version. 373 */ 374 function test_accepts_dev_updates() { 375 include ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z 376 // Only for dev versions 377 if ( false === strpos( $wp_version, '-' ) ) { 378 return false; 379 } 380 381 if ( defined( 'WP_AUTO_UPDATE_CORE' ) && ( 'minor' === WP_AUTO_UPDATE_CORE || false === WP_AUTO_UPDATE_CORE ) ) { 382 return array( 383 'description' => sprintf( 384 /* translators: %s: Name of the constant used. */ 385 __( 'WordPress development updates are blocked by the %s constant.' ), 386 '<code>WP_AUTO_UPDATE_CORE</code>' 387 ), 388 'severity' => 'fail', 389 ); 390 } 391 392 if ( ! apply_filters( 'allow_dev_auto_core_updates', $wp_version ) ) { 393 return array( 394 'description' => sprintf( 395 /* translators: %s: Name of the filter used. */ 396 __( 'WordPress development updates are blocked by the %s filter.' ), 397 '<code>allow_dev_auto_core_updates</code>' 398 ), 399 'severity' => 'fail', 400 ); 401 } 402 } 403 404 /** 405 * Check if the site supports automatic minor updates. 406 * 407 * @since 5.2.0 408 * 409 * @return array The test results. 410 */ 411 function test_accepts_minor_updates() { 412 if ( defined( 'WP_AUTO_UPDATE_CORE' ) && false === WP_AUTO_UPDATE_CORE ) { 413 return array( 414 'description' => sprintf( 415 /* translators: %s: Name of the constant used. */ 416 __( 'WordPress security and maintenance releases are blocked by %s.' ), 417 "<code>define( 'WP_AUTO_UPDATE_CORE', false );</code>" 418 ), 419 'severity' => 'fail', 420 ); 421 } 422 423 if ( ! apply_filters( 'allow_minor_auto_core_updates', true ) ) { 424 return array( 425 'description' => sprintf( 426 /* translators: %s: Name of the filter used. */ 427 __( 'WordPress security and maintenance releases are blocked by the %s filter.' ), 428 '<code>allow_minor_auto_core_updates</code>' 429 ), 430 'severity' => 'fail', 431 ); 432 } 433 } 434 } -
new file src/wp-admin/includes/class-wp-site-health.php
diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php new file mode 100644 index 0000000000..1682491458
- + 1 <?php 2 /** 3 * Class for looking up a sites health based on a users WordPress environment. 4 * 5 * @package WordPress 6 * @subpackage Site_Health 7 * @since 5.2.0 8 */ 9 10 class WP_Site_Health { 11 private $mysql_min_version_check; 12 private $mysql_rec_version_check; 13 14 public $is_mariadb = false; 15 private $mysql_server_version = ''; 16 private $health_check_mysql_required_version = '5.5'; 17 private $health_check_mysql_rec_version = ''; 18 19 public $schedules; 20 public $crons; 21 public $last_missed_cron = null; 22 23 /** 24 * WP_Site_Health constructor. 25 * 26 * @since 5.2.0 27 */ 28 public function __construct() { 29 $this->prepare_sql_data(); 30 31 add_action( 'wp_loaded', array( $this, 'check_wp_version_check_exists' ) ); 32 33 add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); 34 35 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 36 } 37 38 /** 39 * Enqueues the site health scripts. 40 * 41 * @since 5.2.0 42 */ 43 public function enqueue_scripts() { 44 $screen = get_current_screen(); 45 if ( 'site-health' !== $screen->id ) { 46 return; 47 } 48 49 $health_check_js_variables = array( 50 'screen' => $screen->id, 51 'string' => array( 52 'please_wait' => __( 'Please wait...' ), 53 'copied' => __( 'Copied' ), 54 'running_tests' => __( 'Currently being tested...' ), 55 'site_health_complete' => __( 'All site health tests have finished running.' ), 56 'site_info_show_copy' => __( 'Show options for copying this information' ), 57 'site_info_hide_copy' => __( 'Hide options for copying this information' ), 58 // translators: %s: The percentage score for the tests. 59 'site_health_complete_screen_reader' => __( 'All site health tests have finished running. Your site scored %s, and the results are now available on the page.' ), 60 'site_info_copied' => __( 'Site information has been added to your clipboard.' ), 61 ), 62 'nonce' => array( 63 'site_status' => wp_create_nonce( 'health-check-site-status' ), 64 'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ), 65 ), 66 'site_status' => array( 67 'direct' => array(), 68 'async' => array(), 69 'issues' => array( 70 'good' => 0, 71 'recommended' => 0, 72 'critical' => 0, 73 ), 74 ), 75 ); 76 77 $issue_counts = get_transient( 'health-check-site-status-result' ); 78 79 if ( false !== $issue_counts ) { 80 $issue_counts = json_decode( $issue_counts ); 81 82 $health_check_js_variables['site_status']['issues'] = $issue_counts; 83 } 84 85 if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) { 86 $tests = WP_Site_Health::get_tests(); 87 foreach ( $tests['direct'] as $test ) { 88 $test_function = sprintf( 89 'get_test_%s', 90 $test['test'] 91 ); 92 93 if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) { 94 $health_check_js_variables['site_status']['direct'][] = call_user_func( array( $this, $test_function ) ); 95 } else { 96 $health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] ); 97 } 98 } 99 100 foreach ( $tests['async'] as $test ) { 101 $health_check_js_variables['site_status']['async'][] = array( 102 'test' => $test['test'], 103 'completed' => false, 104 ); 105 } 106 } 107 108 wp_localize_script( 'site-health', 'SiteHealth', $health_check_js_variables ); 109 } 110 111 /** 112 * Run the SQL version checks. 113 * 114 * These values are used in later tests, but the part of preparing them is more easily managed early 115 * in the class for ease of access and discovery. 116 * 117 * @since 5.2.0 118 * 119 * @global wpdb $wpdb WordPress database abstraction object. 120 */ 121 private function prepare_sql_data() { 122 global $wpdb; 123 124 if ( method_exists( $wpdb, 'db_version' ) ) { 125 if ( $wpdb->use_mysqli ) { 126 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info 127 $mysql_server_type = mysqli_get_server_info( $wpdb->dbh ); 128 } else { 129 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info 130 $mysql_server_type = mysql_get_server_info( $wpdb->dbh ); 131 } 132 133 $this->mysql_server_version = $wpdb->get_var( 'SELECT VERSION()' ); 134 } 135 136 $this->health_check_mysql_rec_version = '5.6'; 137 138 if ( stristr( $mysql_server_type, 'mariadb' ) ) { 139 $this->is_mariadb = true; 140 $this->health_check_mysql_rec_version = '10.0'; 141 } 142 143 $this->mysql_min_version_check = version_compare( '5.5', $this->mysql_server_version, '<=' ); 144 $this->mysql_rec_version_check = version_compare( $this->health_check_mysql_rec_version, $this->mysql_server_version, '<=' ); 145 } 146 147 /** 148 * Test if `wp_version_check` is blocked. 149 * 150 * It's possible to block updates with the `wp_version_check` filter, but this can't be checked during an 151 * AJAX call, as the filter is never introduced then. 152 * 153 * This filter overrides a normal page request if it's made by an admin through the AJAX call with the 154 * right query argument to check for this. 155 * 156 * @since 5.2.0 157 */ 158 public function check_wp_version_check_exists() { 159 if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'update_core' ) || ! isset( $_GET['health-check-test-wp_version_check'] ) ) { 160 return; 161 } 162 163 echo ( has_filter( 'wp_version_check', 'wp_version_check' ) ? 'yes' : 'no' ); 164 165 die(); 166 } 167 168 /** 169 * Tests for WordPress version and outputs it. 170 * 171 * Gives various results depending on what kind of updates are available, if any, to encourage the 172 * user to install security updates as a priority. 173 * 174 * @since 5.2.0 175 * 176 * @return array The test result. 177 */ 178 public function get_test_wordpress_version() { 179 $result = array( 180 'label' => '', 181 'status' => '', 182 'badge' => array( 183 'label' => 'Security', 184 'color' => 'red', 185 ), 186 'description' => '', 187 'actions' => '', 188 'test' => 'wordpress_version', 189 ); 190 191 $core_current_version = get_bloginfo( 'version' ); 192 $core_updates = get_core_updates(); 193 194 if ( ! is_array( $core_updates ) ) { 195 $result['status'] = 'recommended'; 196 197 $result['label'] = sprintf( 198 // translators: %s: Your current version of WordPress. 199 __( 'WordPress version %s' ), 200 $core_current_version 201 ); 202 203 $result['description'] = sprintf( 204 '<p>%s</p>', 205 __( 'We were unable to check if any new versions of WordPress are available.' ) 206 ); 207 208 $result['actions'] = sprintf( 209 '<a href="%s">%s</a>', 210 esc_url( admin_url( 'update-core.php?force-check=1' ) ), 211 __( 'Check for updates manually' ) 212 ); 213 } else { 214 foreach ( $core_updates as $core => $update ) { 215 if ( 'upgrade' === $update->response ) { 216 $current_version = explode( '.', $core_current_version ); 217 $new_version = explode( '.', $update->version ); 218 219 $current_major = $current_version[0] . '.' . $current_version[1]; 220 $new_major = $new_version[0] . '.' . $new_version[1]; 221 222 $result['label'] = sprintf( 223 // translators: %s: The latest version of WordPress available. 224 __( 'WordPress update available (%s)' ), 225 $update->version 226 ); 227 228 $result['actions'] = sprintf( 229 '<a href="%s">%s</a>', 230 esc_url( admin_url( 'update-core.php' ) ), 231 __( 'Install the latest version of WordPress' ) 232 ); 233 234 if ( $current_major !== $new_major ) { 235 // This is a major version mismatch. 236 $result['status'] = 'recommended'; 237 $result['description'] = sprintf( 238 '<p>%s</p>', 239 __( 'A new version of WordPress is available.' ) 240 ); 241 } else { 242 // This is a minor version, sometimes considered more critical. 243 $result['status'] = 'critical'; 244 $result['description'] = sprintf( 245 '<p>%s</p>', 246 __( 'A new minor update is available for your site. Because minor updates often address security, it’s important to install them.' ) 247 ); 248 } 249 } else { 250 $result['status'] = 'good'; 251 $result['label'] = sprintf( 252 // translators: %s: The current version of WordPress installed on this site. 253 __( 'Your WordPress version is up to date (%s)' ), 254 $core_current_version 255 ); 256 257 $result['description'] = sprintf( 258 '<p>%s</p>', 259 __( 'You are currently running the latest version of WordPress available, keep it up!' ) 260 ); 261 } 262 } 263 } 264 265 return $result; 266 } 267 268 /** 269 * Test if plugins are outdated, or unnecessary. 270 * 271 * The tests checks if your plugins are up to date, and encourages you to remove any that are not in use. 272 * 273 * @since 5.2.0 274 * 275 * @return array The test result. 276 */ 277 public function get_test_plugin_version() { 278 $result = array( 279 'label' => __( 'Your plugins are up to date' ), 280 'status' => 'good', 281 'badge' => array( 282 'label' => 'Security', 283 'color' => 'red', 284 ), 285 'description' => sprintf( 286 '<p>%s</p>', 287 __( 'Plugins extend your site’s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it’s vital to keep them up to date.' ) 288 ), 289 'actions' => '', 290 'test' => 'plugin_version', 291 ); 292 293 $plugins = get_plugins(); 294 $plugin_updates = get_plugin_updates(); 295 296 $plugins_have_updates = false; 297 $plugins_active = 0; 298 $plugins_total = 0; 299 $plugins_needs_update = 0; 300 301 // Loop over the available plugins and check their versions and active state. 302 foreach ( $plugins as $plugin_path => $plugin ) { 303 $plugins_total++; 304 305 if ( is_plugin_active( $plugin_path ) ) { 306 $plugins_active++; 307 } 308 309 $plugin_version = $plugin['Version']; 310 311 if ( array_key_exists( $plugin_path, $plugin_updates ) ) { 312 $plugins_needs_update++; 313 $plugins_have_updates = true; 314 } 315 } 316 317 // Add a notice if there are outdated plugins. 318 if ( $plugins_needs_update > 0 ) { 319 $result['status'] = 'critical'; 320 321 $result['label'] = __( 'You have plugins waiting to be updated' ); 322 323 $result['description'] .= sprintf( 324 '<p>%s</p>', 325 sprintf( 326 esc_html( 327 /* translators: %d: The number of outdated plugins. */ 328 _n( 329 'Your site has %d plugin waiting to be updated.', 330 'Your site has %d plugins waiting for updates.', 331 $plugins_needs_update 332 ) 333 ), 334 $plugins_needs_update 335 ) 336 ); 337 } else { 338 $result['description'] .= sprintf( 339 '<p>%s</p>', 340 sprintf( 341 esc_html( 342 /* translators: %d: The number of active plugins. */ 343 _n( 344 'Your site has %d active plugin, and it is up to date.', 345 'Your site has %d active plugins, and they are all up to date.', 346 $plugins_active 347 ) 348 ), 349 $plugins_active 350 ) 351 ); 352 } 353 354 // Check if there are inactive plugins. 355 if ( $plugins_total > $plugins_active ) { 356 $unused_plugins = $plugins_total - $plugins_active; 357 358 $result['status'] = 'recommended'; 359 360 $result['label'] = __( 'Inactive plugins should be removed' ); 361 362 $result['description'] .= sprintf( 363 '<p>%s</p>', 364 sprintf( 365 esc_html( 366 /* translators: %d: The number of inactive plugins. */ 367 _n( 368 'Your site has %d inactive plugin. Inactive plugins are tempting targets for attackers. if you’re not going to use a plugin, we recommend you remove it.', 369 'Your site has %d inactive plugins. Inactive plugins are tempting targets for attackers. if you’re not going to use a plugin, we recommend you remove it.', 370 $unused_plugins 371 ) 372 ), 373 $unused_plugins 374 ) 375 ); 376 } 377 378 return $result; 379 } 380 381 /** 382 * Test if themes are outdated, or unnecessary. 383 * 384 * The tests checks if your site has a default theme (to fall back on if there is a need), if your themes 385 * are up to date and, finally, encourages you to remove any themes that are not needed. 386 * 387 * @since 5.2.0 388 * 389 * @return array The test results. 390 */ 391 public function get_test_theme_version() { 392 $result = array( 393 'label' => __( 'Your themes are up to date' ), 394 'status' => 'good', 395 'badge' => array( 396 'label' => 'Security', 397 'color' => 'red', 398 ), 399 'description' => sprintf( 400 '<p>%s</p>', 401 __( 'Themes add your site’s look and feel. It’s important to keep them up to date, to stay consistent with your brand and keep your site secure.' ) 402 ), 403 'actions' => '', 404 'test' => 'theme_version', 405 ); 406 407 $theme_updates = get_theme_updates(); 408 409 $themes_total = 0; 410 $themes_need_updates = 0; 411 $themes_inactive = 0; 412 413 // This value is changed during processing to determine how many themes are considered a reasonable amount. 414 $allowed_theme_count = 1; 415 416 $has_default_theme = false; 417 $has_unused_themes = false; 418 $show_unused_themes = true; 419 $using_default_theme = false; 420 421 // Populate a list of all themes available in the install. 422 $all_themes = wp_get_themes(); 423 $active_theme = wp_get_theme(); 424 425 foreach ( $all_themes as $theme_slug => $theme ) { 426 $themes_total++; 427 428 if ( WP_DEFAULT_THEME === $theme_slug ) { 429 $has_default_theme = true; 430 431 if ( get_stylesheet() === $theme_slug ) { 432 $using_default_theme = true; 433 } 434 } 435 436 if ( array_key_exists( $theme_slug, $theme_updates ) ) { 437 $themes_need_updates++; 438 } 439 } 440 441 // If this is a child theme, increase the allowed theme count by one, to account for the parent. 442 if ( $active_theme->parent() ) { 443 $allowed_theme_count++; 444 } 445 446 // If there's a default theme installed, we count that as allowed as well. 447 if ( $has_default_theme ) { 448 $allowed_theme_count++; 449 } 450 451 if ( $themes_total > $allowed_theme_count ) { 452 $has_unused_themes = true; 453 $themes_inactive = ( $themes_total - $allowed_theme_count ); 454 } 455 456 // Check if any themes need to be updated. 457 if ( $themes_need_updates > 0 ) { 458 $result['status'] = 'critical'; 459 460 $result['label'] = __( 'You have themes waiting to be updated' ); 461 462 $result['description'] .= sprintf( 463 '<p>%s</p>', 464 sprintf( 465 esc_html( 466 /* translators: %d: The number of outdated themes. */ 467 _n( 468 'Your site has %d theme waiting to be updated.', 469 'Your site has %d themes waiting to be updated.', 470 $themes_need_updates 471 ) 472 ), 473 $themes_need_updates 474 ) 475 ); 476 } else { 477 // Give positive feedback about the site being good about keeping things up to date. 478 $result['description'] .= sprintf( 479 '<p>%s</p>', 480 sprintf( 481 esc_html( 482 /* translators: %d: The number of themes. */ 483 _n( 484 'Your site has %d installed theme, and it is up to date.', 485 'Your site has %d installed themes, and they are all up to date.', 486 $themes_total 487 ) 488 ), 489 $themes_total 490 ) 491 ); 492 } 493 494 if ( $has_unused_themes && $show_unused_themes ) { 495 496 // This is a child theme, so we want to be a bit more explicit in our messages. 497 if ( $active_theme->parent() ) { 498 // Recommend removing inactive themes, except a default theme, your current one, and the parent theme. 499 $result['status'] = 'recommended'; 500 501 $result['label'] = __( 'You should remove inactive themes' ); 502 503 if ( $using_default_theme ) { 504 $result['description'] .= sprintf( 505 '<p>%s</p>', 506 sprintf( 507 esc_html( 508 /* translators: %d: The number of inactive themes. */ 509 _n( 510 'Your site has %1$d inactive theme. To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep your current theme, %2$s, and %3$s, its parent theme.', 511 'Your site has %1$d inactive themes. To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep your current theme, %2$s, and %3$s, its parent theme.', 512 $themes_inactive 513 ) 514 ), 515 $themes_inactive, 516 $active_theme->name, 517 $active_theme->parent()->name 518 ) 519 ); 520 } else { 521 $result['description'] .= sprintf( 522 '<p>%s</p>', 523 sprintf( 524 esc_html( 525 /* translators: %1$d: The number of inactive themes. %2$s: The default theme for WordPress. %3$s: The currently active theme. %4$s: The active themes parent theme. */ 526 _n( 527 'Your site has %1$d inactive theme. To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep %2$s, the default WordPress theme, %3$s, your current theme and %4$s, its parent theme.', 528 'Your site has %1$d inactive themes. To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep %2$s, the default WordPress theme, %3$s, your current theme and %4$s, its parent theme.', 529 $themes_inactive 530 ) 531 ), 532 $themes_inactive, 533 WP_DEFAULT_THEME, 534 $active_theme->name, 535 $active_theme->parent()->name 536 ) 537 ); 538 } 539 } else { 540 // Recommend removing all inactive themes. 541 $result['status'] = 'recommended'; 542 543 $result['label'] = __( 'You should remove inactive themes' ); 544 545 if ( $using_default_theme ) { 546 $result['description'] .= sprintf( 547 '<p>%s</p>', 548 sprintf( 549 esc_html( 550 /* translators: %1$d: The amount of inactive themes. %2$s: The currently active theme. */ 551 _n( 552 'Your site has %1$d inactive theme, other than %2$s, your active theme. We recommend removing any unused themes to enhance your sites security.', 553 'Your site has %1$d inactive themes, other than %2$s, your active theme. We recommend removing any unused themes to enhance your sites security.', 554 $themes_inactive 555 ) 556 ), 557 $themes_inactive, 558 $active_theme->name 559 ) 560 ); 561 } else { 562 $result['description'] .= sprintf( 563 '<p>%s</p>', 564 sprintf( 565 esc_html( 566 /* translators: %1$d: The amount of inactive themes. %2$s: The default theme for WordPress. %3$s: The currently active theme. */ 567 _n( 568 'Your site has %1$d inactive theme, other than %2$s, the default WordPress theme, and %3$s, your active theme. We recommend removing any unused themes to enhance your sites security.', 569 'Your site has %1$d inactive themes, other than %2$s, the default WordPress theme, and %3$s, your active theme. We recommend removing any unused themes to enhance your sites security.', 570 $themes_inactive 571 ) 572 ), 573 $themes_inactive, 574 WP_DEFAULT_THEME, 575 $active_theme->name 576 ) 577 ); 578 } 579 } 580 } 581 582 // If not default Twenty* theme exists. 583 if ( ! $has_default_theme ) { 584 $result['status'] = 'recommended'; 585 586 $result['label'] = __( 'Have a default theme available' ); 587 588 $result['description'] .= sprintf( 589 '<p>%s</p>', 590 __( 'Your site does not have any default theme. Default themes are used by WordPress automatically if anything is wrong with your normal theme.' ) 591 ); 592 } 593 594 return $result; 595 } 596 597 /** 598 * Test if the supplied PHP version is supported. 599 * 600 * @since 5.2.0 601 * 602 * @return array The test results. 603 */ 604 public function get_test_php_version() { 605 $response = wp_check_php_version(); 606 607 $result = array( 608 'label' => sprintf( 609 // translators: %s: The current PHP version. 610 __( 'PHP is up to date (%s)' ), 611 PHP_VERSION 612 ), 613 'status' => 'good', 614 'badge' => array( 615 'label' => 'Security', 616 'color' => 'red', 617 ), 618 'description' => sprintf( 619 '<p>%s</p>', 620 __( 'PHP is the programming language we use to build and maintain WordPress. Newer versions of PHP are both faster and more secure, so updating will have a positive effect on your site’s performance.' ) 621 ), 622 'actions' => sprintf( 623 '<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', 624 esc_url( wp_get_update_php_url() ), 625 __( 'Learn more about updating PHP' ), 626 /* translators: accessibility text */ 627 __( '(opens in a new tab)' ) 628 ), 629 'test' => 'php_version', 630 ); 631 632 // PHP is up to date. 633 if ( ! $response || version_compare( PHP_VERSION, $response['recommended_version'], '>=' ) ) { 634 return $result; 635 } 636 637 // The PHP version is older than the recommended version, but still acceptable. 638 if ( $response['is_supported'] ) { 639 $result['label'] = __( 'We recommend that you update PHP' ); 640 $result['status'] = 'recommended'; 641 642 return $result; 643 } 644 645 // The PHP version is only recieving security fixes. 646 if ( $response['is_secure'] ) { 647 $result['label'] = __( 'Your PHP version should be updated' ); 648 $result['status'] = 'recommended'; 649 650 return $result; 651 } 652 653 // Anything no longer secure must be updated. 654 $result['label'] = __( 'Your PHP version requires an update' ); 655 $result['status'] = 'critical'; 656 657 return $result; 658 } 659 660 /** 661 * Check if the passed extension or function are available. 662 * 663 * Make the check for available PHP modules into a simple boolean operator for a cleaner test runner. 664 * 665 * @since 5.2.0 666 * 667 * @param string $extension Optional. The extension name to test. Default null. 668 * @param string $function Optional. The function name to test. Default null. 669 * 670 * @return bool Whether or not the extension and function are available. 671 */ 672 private function test_php_extension_availability( $extension = null, $function = null ) { 673 // If no extension or function is passed, claim to fail testing, as we have nothing to test against. 674 if ( ! $extension && ! $function ) { 675 return false; 676 } 677 678 if ( $extension && ! extension_loaded( $extension ) ) { 679 return false; 680 } 681 if ( $function && ! function_exists( $function ) ) { 682 return false; 683 } 684 685 return true; 686 } 687 688 /** 689 * Test if required PHP modules are installed on the host. 690 * 691 * This test builds on the recommendations made by the WordPress Hosting Team 692 * as seen at https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions 693 * 694 * @return array 695 */ 696 public function get_test_php_extensions() { 697 $result = array( 698 'label' => __( 'Required and recommended modules are installed' ), 699 'status' => 'good', 700 'badge' => array( 701 'label' => 'Performance', 702 'color' => 'orange', 703 ), 704 'description' => sprintf( 705 '<p>%s</p><p>%s</p>', 706 __( 'PHP modules perform most of the tasks on the server that make your site run.' ), 707 sprintf( 708 /* translators: %s: Link to the hosting group page about recommended PHP modules. */ 709 __( 'The Hosting team maintains a list of those modules, both recommended and required, in %s.' ), 710 sprintf( 711 '<a href="%s">%s</a>', 712 esc_url( _x( 'https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions', 'The address to describe PHP modules and their use.' ) ), 713 __( 'the team handbook' ) 714 ) 715 ) 716 ), 717 'actions' => '', 718 'test' => 'php_extensions', 719 ); 720 721 $modules = array( 722 'bcmath' => array( 723 'function' => 'bcadd', 724 'required' => false, 725 ), 726 'curl' => array( 727 'function' => 'curl_version', 728 'required' => false, 729 ), 730 'exif' => array( 731 'function' => 'exif_read_data', 732 'required' => false, 733 ), 734 'filter' => array( 735 'function' => 'filter_list', 736 'required' => false, 737 ), 738 'fileinfo' => array( 739 'function' => 'finfo_file', 740 'required' => false, 741 ), 742 'mod_xml' => array( 743 'extension' => 'libxml', 744 'required' => false, 745 ), 746 'mysqli' => array( 747 'function' => 'mysqli_connect', 748 'required' => false, 749 ), 750 'libsodium' => array( 751 'function' => 'sodium_compare', 752 'required' => false, 753 'php_bundled_version' => '7.2.0', 754 ), 755 'openssl' => array( 756 'function' => 'openssl_encrypt', 757 'required' => false, 758 ), 759 'pcre' => array( 760 'function' => 'preg_match', 761 'required' => false, 762 ), 763 'imagick' => array( 764 'extension' => 'imagick', 765 'required' => false, 766 ), 767 'gd' => array( 768 'extension' => 'gd', 769 'required' => false, 770 'fallback_for' => 'imagick', 771 ), 772 'mcrypt' => array( 773 'extension' => 'mcrypt', 774 'required' => false, 775 'fallback_for' => 'libsodium', 776 ), 777 'xmlreader' => array( 778 'extension' => 'xmlreader', 779 'required' => false, 780 'fallback_for' => 'xml', 781 ), 782 'zlib' => array( 783 'extension' => 'zlib', 784 'required' => false, 785 'fallback_for' => 'zip', 786 ), 787 ); 788 789 /** 790 * An array representing all the modules we wish to test for. 791 * 792 * @since 5.2.0 793 * 794 * @param array $modules { 795 * An associated array of modules to test for. 796 * 797 * array $module { 798 * An associated array of module properties used during testing. 799 * One of either `$function` or `$extension` must be provided, or they will fail by default. 800 * 801 * string $function Optional. A function name to test for the existence of. 802 * string $extension Optional. An extension to check if is loaded in PHP. 803 * bool $required Is this a required feature or not. 804 * string $fallback_for Optional. The module this module replaces as a fallback. 805 * } 806 * } 807 */ 808 $modules = apply_filters( 'site_status_test_php_modules', $modules ); 809 810 $failures = array(); 811 812 foreach ( $modules as $library => $module ) { 813 $extension = ( isset( $module['extension'] ) ? $module['extension'] : null ); 814 $function = ( isset( $module['function'] ) ? $module['function'] : null ); 815 816 // If this module is a fallback for another function, check if that other function passed. 817 if ( isset( $module['fallback_for'] ) ) { 818 /* 819 * If that other function has a failure, mark this module as required for normal operations. 820 * If that other function hasn't failed, skip this test as it's only a fallback. 821 */ 822 if ( isset( $failures[ $module['fallback_for'] ] ) ) { 823 $module['required'] = true; 824 } else { 825 continue; 826 } 827 } 828 829 if ( ! $this->test_php_extension_availability( $extension, $function ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) { 830 if ( $module['required'] ) { 831 $result['status'] = 'critical'; 832 833 $class = 'error'; 834 $screen_reader = __( 'Error' ); 835 $message = sprintf( 836 /* translators: %s: The module name. */ 837 __( 'The required module, %s, is not installed, or has been disabled.' ), 838 $library 839 ); 840 } else { 841 $class = 'warning'; 842 $screen_reader = __( 'Warning' ); 843 $message = sprintf( 844 /* translators: %s: The module name. */ 845 __( 'The optional module, %s, is not installed, or has been disabled.' ), 846 $library 847 ); 848 } 849 850 if ( ! $module['required'] && 'good' === $result['status'] ) { 851 $result['status'] = 'recommended'; 852 } 853 854 $failures[ $library ] = "<span class='$class'><span class='screen-reader-text'>$screen_reader</span></span> $message"; 855 } 856 } 857 858 if ( ! empty( $failures ) ) { 859 $output = '<ul>'; 860 861 foreach ( $failures as $failure ) { 862 $output .= sprintf( 863 '<li>%s</li>', 864 $failure 865 ); 866 } 867 868 $output .= '</ul>'; 869 } 870 871 if ( 'good' !== $result['status'] ) { 872 if ( 'recommended' === $result['status'] ) { 873 $result['label'] = __( 'One or more recommended modules are missing' ); 874 } 875 if ( 'critical' === $result['status'] ) { 876 $result['label'] = __( 'One or more required modules are missing' ); 877 } 878 879 $result['description'] .= sprintf( 880 '<p>%s</p>', 881 $output 882 ); 883 } 884 885 return $result; 886 } 887 888 /** 889 * Test if the SQL server is up to date. 890 * 891 * @since 5.2.0 892 * 893 * @return array The test results. 894 */ 895 public function get_test_sql_server() { 896 $result = array( 897 'label' => __( 'SQL server is up to date' ), 898 'status' => 'good', 899 'badge' => array( 900 'label' => 'Security', 901 'color' => 'red', 902 ), 903 'description' => sprintf( 904 '<p>%s</p>', 905 __( 'The SQL server is the database where WordPress stores all your site’s content and settings' ) 906 ), 907 'actions' => '', 908 'test' => 'sql_server', 909 ); 910 911 $db_dropin = file_exists( WP_CONTENT_DIR . '/db.php' ); 912 913 if ( ! $this->mysql_rec_version_check ) { 914 $result['status'] = 'recommended'; 915 916 $result['label'] = __( 'Outdated SQL server' ); 917 918 $result['description'] .= sprintf( 919 '<p>%s</p>', 920 sprintf( 921 /* translators: %1$s: The database engine in use (MySQL or MariaDB). %2$s: Database server recommended version number. */ 922 __( 'For optimal performance and security reasons, we recommend running %1$s version %2$s or higher. Contact your web hosting company to correct this.' ), 923 ( $this->mariadb ? 'MariaDB' : 'MySQL' ), 924 $this->health_check_mysql_rec_version 925 ) 926 ); 927 } 928 929 if ( ! $this->mysql_min_version_check ) { 930 $result['status'] = 'critical'; 931 932 $result['label'] = __( 'Severely outdated SQL server' ); 933 934 $result['description'] .= sprintf( 935 '<p>%s</p>', 936 sprintf( 937 /* translators: %1$s: The database engine in use (MySQL or MariaDB). %2$s: Database server minimum version number. */ 938 __( 'WordPress requires %1$s version %2$s or higher. Contact your web hosting company to correct this.' ), 939 ( $this->mariadb ? 'MariaDB' : 'MySQL' ), 940 $this->health_check_mysql_required_version 941 ) 942 ); 943 } 944 945 if ( $db_dropin ) { 946 $result['description'] .= sprintf( 947 '<p>%s</p>', 948 wp_kses( 949 sprintf( 950 /* translators: %s: The name of the database engine being used. */ 951 __( 'You are using a <code>wp-content/db.php</code> drop-in which might mean that a %s database is not being used.' ), 952 ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ) 953 ), 954 array( 955 'code' => true, 956 ) 957 ) 958 ); 959 } 960 961 return $result; 962 } 963 964 /** 965 * Test if the database server is capable of using utf8mb4. 966 * 967 * @since 5.2.0 968 * 969 * @return array The test results. 970 */ 971 public function get_test_utf8mb4_support() { 972 global $wpdb; 973 974 $result = array( 975 'label' => __( 'UTF8MB4 is supported' ), 976 'status' => 'good', 977 'badge' => array( 978 'label' => 'Performance', 979 'color' => 'orange', 980 ), 981 'description' => sprintf( 982 '<p>%s</p>', 983 __( 'UTF8MB4 is a database storage attribute that makes sure your site can store non-English text and other strings (for instance emoticons) without unexpected problems.' ) 984 ), 985 'actions' => '', 986 'test' => 'utf8mb4_support', 987 ); 988 989 if ( ! $this->is_mariadb ) { 990 if ( version_compare( $this->mysql_server_version, '5.5.3', '<' ) ) { 991 $result['status'] = 'recommended'; 992 993 $result['label'] = __( 'utf8mb4 requires a MySQL update' ); 994 995 $result['description'] .= sprintf( 996 '<p>%s</p>', 997 sprintf( 998 /* translators: %s: Version number. */ 999 __( 'WordPress’ utf8mb4 support requires MySQL version %s or greater.' ), 1000 '5.5.3' 1001 ) 1002 ); 1003 } else { 1004 $result['description'] .= sprintf( 1005 '<p>%s</p>', 1006 __( 'Your MySQL version supports utf8mb4.' ) 1007 ); 1008 } 1009 } else { // MariaDB introduced utf8mb4 support in 5.5.0 1010 if ( version_compare( $this->mysql_server_version, '5.5.0', '<' ) ) { 1011 $result['status'] = 'recommended'; 1012 1013 $result['label'] = __( 'utf8mb4 requires a MariaDB update' ); 1014 1015 $result['description'] .= sprintf( 1016 '<p>%s</p>', 1017 sprintf( 1018 /* translators: %s: Version number. */ 1019 __( 'WordPress’ utf8mb4 support requires MariaDB version %s or greater.' ), 1020 '5.5.0' 1021 ) 1022 ); 1023 } else { 1024 $result['description'] .= sprintf( 1025 '<p>%s</p>', 1026 __( 'Your MariaDB version supports utf8mb4.' ) 1027 ); 1028 } 1029 } 1030 1031 if ( $wpdb->use_mysqli ) { 1032 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info 1033 $mysql_client_version = mysqli_get_client_info(); 1034 } else { 1035 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info 1036 $mysql_client_version = mysql_get_client_info(); 1037 } 1038 1039 /* 1040 * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server. 1041 * mysqlnd has supported utf8mb4 since 5.0.9. 1042 */ 1043 if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) { 1044 $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version ); 1045 if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) { 1046 $result['status'] = 'recommended'; 1047 1048 $result['label'] = __( 'utf8mb4 requires a newer client library' ); 1049 1050 $result['description'] .= sprintf( 1051 '<p>%s</p>', 1052 sprintf( 1053 /* translators: %1$s: Name of the library, %2$s: Number of version. */ 1054 __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer.' ), 1055 'mysqlnd', 1056 '5.0.9' 1057 ) 1058 ); 1059 } 1060 } else { 1061 if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) { 1062 $result['status'] = 'recommended'; 1063 1064 $result['label'] = __( 'UTF8MB4 requires a newer client library' ); 1065 1066 $result['description'] .= sprintf( 1067 '<p>%s</p>', 1068 sprintf( 1069 /* translators: %1$s: Name of the library, %2$s: Number of version. */ 1070 __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer.' ), 1071 'libmysql', 1072 '5.5.3' 1073 ) 1074 ); 1075 } 1076 } 1077 1078 return $result; 1079 } 1080 1081 /** 1082 * Test if the site can communicate with WordPress.org. 1083 * 1084 * @since 5.2.0 1085 * 1086 * @return array The test results. 1087 */ 1088 public function get_test_dotorg_communication() { 1089 $result = array( 1090 'label' => __( 'Can communicate with WordPress.org' ), 1091 'status' => '', 1092 'badge' => array( 1093 'label' => 'Security', 1094 'color' => 'red', 1095 ), 1096 'description' => sprintf( 1097 '<p>%s</p>', 1098 __( 'Communicating with the WordPress servers is used to check for new versions, and to both install and update WordPress core, themes or plugins.' ) 1099 ), 1100 'actions' => '', 1101 'test' => 'dotorg_communication', 1102 ); 1103 1104 $wp_dotorg = wp_remote_get( 1105 'https://wordpress.org', 1106 array( 1107 'timeout' => 10, 1108 ) 1109 ); 1110 if ( ! is_wp_error( $wp_dotorg ) ) { 1111 $result['status'] = 'good'; 1112 } else { 1113 $result['status'] = 'critical'; 1114 1115 $result['label'] = __( 'Could not reach WordPress.org' ); 1116 1117 $result['description'] .= sprintf( 1118 '<p>%s</p>', 1119 sprintf( 1120 '<span class="error"><span class="screen-reader-text">%s</span></span> %s', 1121 __( 'Error' ), 1122 sprintf( 1123 /* translators: %1$s: The IP address WordPress.org resolves to. %2$s: The error returned by the lookup. */ 1124 __( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s' ), 1125 gethostbyname( 'wordpress.org' ), 1126 $wp_dotorg->get_error_message() 1127 ) 1128 ) 1129 ); 1130 } 1131 1132 return $result; 1133 } 1134 1135 /** 1136 * Test if debug information is enabled. 1137 * 1138 * When WP_DEBUG is enabled, errors and information may be disclosed to site visitors, or it may be 1139 * logged to a publicly accessible file. 1140 * 1141 * Debugging is also frequently left enabled after looking for errors on a site, as site owners do 1142 * not understand the implications of this. 1143 * 1144 * @since 5.2.0 1145 * 1146 * @return array The test results. 1147 */ 1148 public function get_test_is_in_debug_mode() { 1149 $result = array( 1150 'label' => __( 'Your site is not set to output debug information' ), 1151 'status' => 'good', 1152 'badge' => array( 1153 'label' => 'Security', 1154 'color' => 'red', 1155 ), 1156 'description' => sprintf( 1157 '<p>%s</p>', 1158 __( 'Debug mode is often enabled to gather more details about an error or site failure, but may contain sensitive information which should not be available on a publicly available website.' ) 1159 ), 1160 'actions' => '', 1161 'test' => 'is_in_debug_mode', 1162 ); 1163 1164 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 1165 if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { 1166 $result['label'] = __( 'Your site is set to log errors to a potentially public file.' ); 1167 1168 $result['status'] = 'critical'; 1169 1170 $result['description'] .= sprintf( 1171 '<p>%s</p>', 1172 __( 'The value, WP_DEBUG_LOG, has been added to this websites configuration file. This means any errors on the site will be written to a file which is potentially available to normal users.' ) 1173 ); 1174 } 1175 1176 if ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) { 1177 $result['label'] = __( 'Your site is set to display errors to site visitors' ); 1178 1179 $result['status'] = 'critical'; 1180 1181 $result['description'] .= sprintf( 1182 '<p>%s</p>', 1183 __( 'The value, WP_DEBUG_DISPLAY, has either been added to your configuration file, or left with its default value. This will make errors display on the front end of your site.' ) 1184 ); 1185 } 1186 } 1187 1188 return $result; 1189 } 1190 1191 /** 1192 * Test if your site is serving content over HTTPS. 1193 * 1194 * Many sites have varying degrees of HTTPS suppoort, the most common of which is sites that have it 1195 * enabled, but only if you visit the right site address. 1196 * 1197 * @since 5.2.0 1198 * 1199 * @return array The test results. 1200 */ 1201 public function get_test_https_status() { 1202 $result = array( 1203 'label' => '', 1204 'status' => '', 1205 'badge' => array( 1206 'label' => 'Security', 1207 'color' => 'red', 1208 ), 1209 'description' => '', 1210 'actions' => '', 1211 'test' => 'https_status', 1212 ); 1213 1214 if ( is_ssl() ) { 1215 $wp_url = get_bloginfo( 'wpurl' ); 1216 $site_url = get_bloginfo( 'url' ); 1217 1218 if ( 'https' !== substr( $wp_url, 0, 5 ) || 'https' !== substr( $site_url, 0, 5 ) ) { 1219 $result['status'] = 'recommended'; 1220 1221 $result['label'] = __( 'Only parts of your site are using HTTPS' ); 1222 1223 $result['description'] = sprintf( 1224 '<p>%s</p>', 1225 sprintf( 1226 /* translators: %s: URL to Settings > General to change options. */ 1227 __( 'You are accessing this website using HTTPS, but your <a href="%s">WordPress Address</a> is not set up to use HTTPS by default.' ), 1228 esc_url( admin_url( 'options-general.php' ) ) 1229 ) 1230 ); 1231 1232 $result['actions'] = sprintf( 1233 '<a href="%s">%s</a>', 1234 esc_url( admin_url( 'options-general.php' ) ), 1235 __( 'Update your site addresses' ) 1236 ); 1237 } else { 1238 $result['status'] = 'good'; 1239 1240 $result['label'] = __( 'Your website is using an active HTTPS connection.' ); 1241 } 1242 } else { 1243 $result['status'] = 'recommended'; 1244 1245 $result['label'] = __( 'Your site does not use HTTPS' ); 1246 1247 $result['description'] = sprintf( 1248 '<p>%s</p>', 1249 __( 'An HTTPS connection is needed for many features on the web today, it also gains the trust of your visitors by helping to protecting their online privacy.' ) 1250 ); 1251 1252 $result['actions'] = sprintf( 1253 '<a href="%s">%s</a>', 1254 esc_url( 1255 /* translators: Website for explaining HTTPS and why it should be used. */ 1256 __( 'https://www.cloudflare.com/learning/security/why-use-https/' ) 1257 ), 1258 __( 'Read more about why you should use HTTPS.' ) 1259 ); 1260 } 1261 1262 return $result; 1263 } 1264 1265 /** 1266 * Check if the HTTP API can handle SSL/TLS requests. 1267 * 1268 * @since 5.2.0 1269 * 1270 * @return array The test results. 1271 */ 1272 public function get_test_ssl_support() { 1273 $result = array( 1274 'label' => '', 1275 'status' => '', 1276 'badge' => array( 1277 'label' => 'Security', 1278 'color' => 'red', 1279 ), 1280 'description' => sprintf( 1281 '<p>%s</p>', 1282 __( 'Securely communicating between servers are needed for transactions such as fetching files, conducting sales on store sites, and much more.' ) 1283 ), 1284 'actions' => '', 1285 'test' => 'ssl_support', 1286 ); 1287 1288 $supports_https = wp_http_supports( array( 'ssl' ) ); 1289 1290 if ( $supports_https ) { 1291 $result['status'] = 'good'; 1292 1293 $result['label'] = __( 'Your site can communicate securely with other services' ); 1294 } else { 1295 $result['status'] = 'critical'; 1296 1297 $result['label'] = __( 'Your site is unable to communicate securely with other services' ); 1298 1299 $result['description'] .= sprintf( 1300 '<p>%s</p>', 1301 __( 'Talk to your web host about OpenSSL support for PHP.' ) 1302 ); 1303 } 1304 1305 return $result; 1306 } 1307 1308 /** 1309 * Test if scheduled events run as intended. 1310 * 1311 * If scheduled events are not running, this may indicate something with WP_Cron is not working as intended, 1312 * or that there are orphaned events hanging around from older code. 1313 * 1314 * @since 5.2.0 1315 * 1316 * @return array The test results. 1317 */ 1318 public function get_test_scheduled_events() { 1319 $result = array( 1320 'label' => __( 'Scheduled events are running' ), 1321 'status' => 'good', 1322 'badge' => array( 1323 'label' => 'Performance', 1324 'color' => 'orange', 1325 ), 1326 'description' => sprintf( 1327 '<p>%s</p>', 1328 __( 'Scheduled events are what periodically looks for updates to plugins, themes and WordPress it self. It is also what makes sure scheduled posts are published on time. It may also be used by various plugins to make sure that planned actions are executed.' ) 1329 ), 1330 'actions' => '', 1331 'test' => 'scheduled_events', 1332 ); 1333 1334 $this->wp_schedule_test_init(); 1335 1336 if ( is_wp_error( $this->has_missed_cron() ) ) { 1337 $result['status'] = 'critical'; 1338 1339 $result['label'] = __( 'It was not possible to check your scheduled events' ); 1340 1341 $result['description'] = sprintf( 1342 '<p>%s</p>', 1343 sprintf( 1344 /* translators: %s: The error message returned while from the cron scheduler. */ 1345 __( 'While trying to test your sites scheduled events, the following error was returned: %s' ), 1346 $this->has_missed_cron()->get_error_message() 1347 ) 1348 ); 1349 } else { 1350 if ( $this->has_missed_cron() ) { 1351 $result['status'] = 'recommended'; 1352 1353 $result['label'] = __( 'A scheduled event has failed' ); 1354 1355 $result['description'] = sprintf( 1356 '<p>%s</p>', 1357 sprintf( 1358 /* translators: %s: The name of the failed cron event. */ 1359 __( 'The scheduled event, %s, failed to run. Your site still works, but this may indicate that scheduling posts or automated updates may not work as intended.' ), 1360 $this->last_missed_cron 1361 ) 1362 ); 1363 } 1364 } 1365 1366 return $result; 1367 } 1368 1369 /** 1370 * Test if WordPress can run automated background updates. 1371 * 1372 * Background updates in WordPress are primarely used for minor releases and security updates. It's important 1373 * to either have these working, or be aware that they are intentionally disabled for whatever reason. 1374 * 1375 * @since 5.2.0 1376 * 1377 * @return array The test results. 1378 */ 1379 public function get_test_background_updates() { 1380 $result = array( 1381 'label' => __( 'Background updates are working' ), 1382 'status' => 'good', 1383 'badge' => array( 1384 'label' => 'Security', 1385 'color' => 'red', 1386 ), 1387 'description' => sprintf( 1388 '<p>%s</p>', 1389 __( 'Background updates ensure that WordPress can auto-update if a security update is released for the version you are currently using.' ) 1390 ), 1391 'actions' => '', 1392 'test' => 'background_updates', 1393 ); 1394 1395 if ( ! class_exists( 'WP_Site_Health_Auto_Updates' ) ) { 1396 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health-auto-updates.php' ); 1397 } 1398 1399 // Run the auto-update tests in a separate class, 1400 // as there are many considerations to be made. 1401 $automatic_updates = new WP_Site_Health_Auto_Updates(); 1402 $tests = $automatic_updates->run_tests(); 1403 1404 $output = '<ul>'; 1405 1406 foreach ( $tests as $test ) { 1407 $severity_string = __( 'Passed' ); 1408 1409 if ( 'fail' === $test->severity ) { 1410 $result['label'] = __( 'Background updates are not working as expected' ); 1411 1412 $result['status'] = 'critical'; 1413 1414 $severity_string = __( 'Error' ); 1415 } 1416 1417 if ( 'warning' === $test->severity && 'good' === $result['status'] ) { 1418 $result['label'] = __( 'Background updates may not be working properly' ); 1419 1420 $result['status'] = 'recommended'; 1421 1422 $severity_string = __( 'Warning' ); 1423 } 1424 1425 $output .= sprintf( 1426 '<li><span class="%s"><span class="screen-reader-text">%s</span></span> %s</li>', 1427 esc_attr( $test->severity ), 1428 $severity_string, 1429 $test->description 1430 ); 1431 } 1432 1433 $output .= '</ul>'; 1434 1435 if ( 'good' !== $result['status'] ) { 1436 $result['description'] .= sprintf( 1437 '<p>%s</p>', 1438 $output 1439 ); 1440 } 1441 1442 return $result; 1443 } 1444 1445 /** 1446 * Test if loopbacks work as expected. 1447 * 1448 * A loopback is when WordPress queries it self, for example to start a new WP_Cron instance, or when editing a 1449 * plugin or theme. This has shown it self to be a recurring issue as code can very easily break this interaction. 1450 * 1451 * @since 5.2.0 1452 * 1453 * @return array The test results. 1454 */ 1455 public function get_test_loopback_requests() { 1456 $result = array( 1457 'label' => __( 'Your site can perform loopback requests' ), 1458 'status' => 'good', 1459 'badge' => array( 1460 'label' => 'Performance', 1461 'color' => 'orange', 1462 ), 1463 'description' => sprintf( 1464 '<p>%s</p>', 1465 __( 'Loopback requests are used to run scheduled events, and are also used by the built-in editors for themes and plugins to verify code stability.' ) 1466 ), 1467 'actions' => '', 1468 'test' => 'loopback_requests', 1469 ); 1470 1471 $check_loopback = $this->can_perform_loopback(); 1472 1473 $result['status'] = $check_loopback->status; 1474 1475 if ( 'good' !== $check_loopback->status ) { 1476 $result['label'] = __( 'Your site could not complete a loopback request' ); 1477 1478 $result['description'] .= sprintf( 1479 '<p>%s</p>', 1480 $check_loopback->message 1481 ); 1482 } 1483 1484 return $result; 1485 } 1486 1487 /** 1488 * Test if HTTP requests are blocked. 1489 * 1490 * It's possible to block all outgoing communication (with the possibility of whitelisting hosts) via the 1491 * HTTP API. This may create problems for users as many features are running as services these days. 1492 * 1493 * @since 5.2.0 1494 * 1495 * @return array The test results. 1496 */ 1497 public function get_test_http_requests() { 1498 $result = array( 1499 'label' => __( 'HTTP requests seem to be working as expected' ), 1500 'status' => 'good', 1501 'badge' => array( 1502 'label' => 'Performance', 1503 'color' => 'orange', 1504 ), 1505 'description' => sprintf( 1506 '<p>%s</p>', 1507 __( 'It is possible for site maintainers to block all, or some, communication to other sites and services. If set up incorrectly, this may prevent plugins and themes from working as intended.' ) 1508 ), 1509 'actions' => '', 1510 'test' => 'http_requests', 1511 ); 1512 1513 $blocked = false; 1514 $hosts = array(); 1515 1516 if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) ) { 1517 $blocked = true; 1518 } 1519 1520 if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) { 1521 $hosts = explode( ',', WP_ACCESSIBLE_HOSTS ); 1522 } 1523 1524 if ( $blocked && 0 === sizeof( $hosts ) ) { 1525 $result['status'] = 'critical'; 1526 1527 $result['label'] = __( 'HTTP requests are blocked' ); 1528 1529 $result['description'] .= sprintf( 1530 '<p>%s</p>', 1531 __( 'HTTP requests have been blocked by the WP_HTTP_BLOCK_EXTERNAL constant, with no allowed hosts.' ) 1532 ); 1533 } 1534 1535 if ( $blocked && 0 < sizeof( $hosts ) ) { 1536 $result['status'] = 'recommended'; 1537 1538 $result['label'] = __( 'HTTP requests are partially blocked' ); 1539 1540 $result['description'] .= sprintf( 1541 '<p>%s</p>', 1542 sprintf( 1543 /* translators: %s: List of hostnames whitelisted. */ 1544 __( 'HTTP requests have been blocked by the WP_HTTP_BLOCK_EXTERNAL constant, with some hosts whitelisted: %s.' ), 1545 implode( ',', $hosts ) 1546 ) 1547 ); 1548 } 1549 1550 return $result; 1551 } 1552 1553 /** 1554 * Test if the REST API is accessible. 1555 * 1556 * Various security measures may block the REST API from working, or it may have been disabled in general. 1557 * This is required for the new block editor to work, so we explicitly test for this. 1558 * 1559 * @since 5.2.0 1560 * 1561 * @return array The test results. 1562 */ 1563 public function get_test_rest_availability() { 1564 $result = array( 1565 'label' => __( 'The REST API is available' ), 1566 'status' => 'good', 1567 'badge' => array( 1568 'label' => 'Performance', 1569 'color' => 'orange', 1570 ), 1571 'description' => sprintf( 1572 '<p>%s</p>', 1573 __( 'The REST API is one way WordPress, and other applications, communicate with the server. One example is the block editor screen, which relies on this to display, and save, your posts and pages.' ) 1574 ), 1575 'actions' => '', 1576 'test' => 'rest_availability', 1577 ); 1578 1579 $cookies = wp_unslash( $_COOKIE ); 1580 $timeout = 10; 1581 $headers = array( 1582 'Cache-Control' => 'no-cache', 1583 'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ), 1584 ); 1585 1586 // Include Basic auth in loopback requests. 1587 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { 1588 $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); 1589 } 1590 1591 $url = rest_url( 'wp/v2/types/post' ); 1592 1593 // The context for this is editing with the new block editor. 1594 $url = add_query_arg( 1595 array( 1596 'context' => 'edit', 1597 ), 1598 $url 1599 ); 1600 1601 $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) ); 1602 1603 if ( is_wp_error( $r ) ) { 1604 $result['status'] = 'critical'; 1605 1606 $result['label'] = __( 'The REST API encountered an error' ); 1607 1608 $result['description'] .= sprintf( 1609 '<p>%s</p>', 1610 sprintf( 1611 '%s<br>%s', 1612 __( 'The REST API request failed due to an error.' ), 1613 sprintf( 1614 /* translators: %1$d: The HTTP response code. %2$s: The error message returned. */ 1615 __( 'Error encountered: (%1$d) %2$s' ), 1616 wp_remote_retrieve_response_code( $r ), 1617 $r->get_error_message() 1618 ) 1619 ) 1620 ); 1621 } elseif ( 200 !== wp_remote_retrieve_response_code( $r ) ) { 1622 $result['status'] = 'recommended'; 1623 1624 $result['label'] = __( 'The REST API encountered an unexpected result' ); 1625 1626 $result['description'] .= sprintf( 1627 '<p>%s</p>', 1628 sprintf( 1629 /* translators: %1$d: The HTTP response code returned. %2$s: The error message returned. */ 1630 __( 'The REST API call gave the following unexpected result: (%1$d) %2$s.' ), 1631 wp_remote_retrieve_response_code( $r ), 1632 wp_remote_retrieve_body( $r ) 1633 ) 1634 ); 1635 } else { 1636 $json = json_decode( wp_remote_retrieve_body( $r ), true ); 1637 1638 if ( false !== $json && ! isset( $json['capabilities'] ) ) { 1639 $result['status'] = 'recommended'; 1640 1641 $result['label'] = __( 'The REST API did not behave correctly' ); 1642 1643 $result['description'] .= sprintf( 1644 '<p>%s</p>', 1645 sprintf( 1646 /* translators: %s: the name of the query parameter being tested. */ 1647 __( 'The REST API did not process the %s query parameter correctly.' ), 1648 '<code>context</code>' 1649 ) 1650 ); 1651 } 1652 } 1653 1654 return $result; 1655 } 1656 1657 /** 1658 * Return a set of tests that belong to the site status page. 1659 * 1660 * Each site status test is defined here, they may be `direct` tests, that run on page load, or `async` tests 1661 * which will run later down the line via JavaScript calls to improve page performance and hopefully also user 1662 * experiences. 1663 * 1664 * @since 5.2.0 1665 * 1666 * @return array The list of tests to run. 1667 */ 1668 public static function get_tests() { 1669 $tests = array( 1670 'direct' => array( 1671 'wordpress_version' => array( 1672 'label' => __( 'WordPress Version' ), 1673 'test' => 'wordpress_version', 1674 ), 1675 'plugin_version' => array( 1676 'label' => __( 'Plugin Versions' ), 1677 'test' => 'plugin_version', 1678 ), 1679 'theme_version' => array( 1680 'label' => __( 'Theme Versions' ), 1681 'test' => 'theme_version', 1682 ), 1683 'php_version' => array( 1684 'label' => __( 'PHP Version' ), 1685 'test' => 'php_version', 1686 ), 1687 'sql_server' => array( 1688 'label' => __( 'Database Server version' ), 1689 'test' => 'sql_server', 1690 ), 1691 'php_extensions' => array( 1692 'label' => __( 'PHP Extensions' ), 1693 'test' => 'php_extensions', 1694 ), 1695 'utf8mb4_support' => array( 1696 'label' => __( 'MySQL utf8mb4 support' ), 1697 'test' => 'utf8mb4_support', 1698 ), 1699 'https_status' => array( 1700 'label' => __( 'HTTPS status' ), 1701 'test' => 'https_status', 1702 ), 1703 'ssl_support' => array( 1704 'label' => __( 'Secure communication' ), 1705 'test' => 'ssl_support', 1706 ), 1707 'scheduled_events' => array( 1708 'label' => __( 'Scheduled events' ), 1709 'test' => 'scheduled_events', 1710 ), 1711 'http_requests' => array( 1712 'label' => __( 'HTTP Requests' ), 1713 'test' => 'http_requests', 1714 ), 1715 'debug_enabled' => array( 1716 'label' => __( 'Debugging enabled' ), 1717 'test' => 'is_in_debug_mode', 1718 ), 1719 ), 1720 'async' => array( 1721 'dotorg_communication' => array( 1722 'label' => __( 'Communication with WordPress.org' ), 1723 'test' => 'dotorg_communication', 1724 ), 1725 'background_updates' => array( 1726 'label' => __( 'Background updates' ), 1727 'test' => 'background_updates', 1728 ), 1729 'loopback_requests' => array( 1730 'label' => __( 'Loopback request' ), 1731 'test' => 'loopback_requests', 1732 ), 1733 ), 1734 ); 1735 1736 // Conditionally include REST rules if the function for it exists. 1737 if ( function_exists( 'rest_url' ) ) { 1738 $tests['direct']['rest_availability'] = array( 1739 'label' => __( 'REST API availability' ), 1740 'test' => 'rest_availability', 1741 ); 1742 } 1743 1744 /** 1745 * Add or modify which site status tests are ran on a site. 1746 * 1747 * The site health is determined by a set of tests based on best practices from 1748 * both the WordPress Hosting Team, but also web standards in general. 1749 * 1750 * Some sites may not have the same requirements, for example the automatic update 1751 * checks may be handled by a host, and are therefore disabled in core. 1752 * Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example. 1753 * 1754 * Test may be added either as direct, or asynchronous ones. Any test that may require some time 1755 * to complete should run asynchronously, to avoid extended loading periods within wp-admin. 1756 * 1757 * @since 5.2.0 1758 * 1759 * @param array $test_type { 1760 * An associative arraay, where the `$test_type` is either `direct` or 1761 * `async`, to declare if the test should run via AJAX calls after page load. 1762 * 1763 * @type array $identifier { 1764 * `$identifier` should be a unque identifier for the test that should run. 1765 * Plugins and themes are encouraged to prefix test identifiers with their slug 1766 * to avoid any collisions between tests. 1767 * 1768 * @type string $label A friendly label for your test to identify it by. 1769 * @type string $test The ajax action to be called to perform the tests. 1770 * } 1771 * } 1772 */ 1773 $tests = apply_filters( 'site_status_tests', $tests ); 1774 1775 return $tests; 1776 } 1777 1778 /** 1779 * Add a class to the body HTML tag. 1780 * 1781 * Filters the body class string for admin pages and adds our own class for easier styling. 1782 * 1783 * @since 5.2.0 1784 * 1785 * @param string $body_class The body class string. 1786 * @return string The modified body class string. 1787 */ 1788 public function admin_body_class( $body_class ) { 1789 $body_class .= ' site-health'; 1790 1791 return $body_class; 1792 } 1793 1794 /** 1795 * Initiate the WP_Cron schedule test cases. 1796 * 1797 * @since 5.2.0 1798 */ 1799 private function wp_schedule_test_init() { 1800 $this->schedules = wp_get_schedules(); 1801 $this->get_cron_tasks(); 1802 } 1803 1804 /** 1805 * Populate our list of cron events and store them to a class-wide variable. 1806 * 1807 * @since 5.2.0 1808 */ 1809 private function get_cron_tasks() { 1810 $cron_tasks = _get_cron_array(); 1811 1812 if ( empty( $cron_tasks ) ) { 1813 $this->crons = new WP_Error( 'no_tasks', __( 'No scheduled events exist on this site.' ) ); 1814 return; 1815 } 1816 1817 $this->crons = array(); 1818 1819 foreach ( $cron_tasks as $time => $cron ) { 1820 foreach ( $cron as $hook => $dings ) { 1821 foreach ( $dings as $sig => $data ) { 1822 1823 $this->crons[ "$hook-$sig-$time" ] = (object) array( 1824 'hook' => $hook, 1825 'time' => $time, 1826 'sig' => $sig, 1827 'args' => $data['args'], 1828 'schedule' => $data['schedule'], 1829 'interval' => isset( $data['interval'] ) ? $data['interval'] : null, 1830 ); 1831 1832 } 1833 } 1834 } 1835 } 1836 1837 /** 1838 * Check if any scheduled tasks have been missed. 1839 * 1840 * Returns a boolean value of `true` if a scheduled task has been missed and ends processing. If the list of 1841 * crons is an instance of WP_Error, return the instance instead of a boolean value. 1842 * 1843 * @since 5.2.0 1844 * 1845 * @return bool|WP_Error true if a cron was missed, false if it wasn't. WP_Error if the cron is set to that. 1846 */ 1847 public function has_missed_cron() { 1848 if ( is_wp_error( $this->crons ) ) { 1849 return $this->crons; 1850 } 1851 1852 foreach ( $this->crons as $id => $cron ) { 1853 if ( ( $cron->time - time() ) < 0 ) { 1854 $this->last_missed_cron = $cron->hook; 1855 return true; 1856 } 1857 } 1858 1859 return false; 1860 } 1861 1862 /** 1863 * Run a loopback test on our site. 1864 * 1865 * Loopbacks are what WordPress uses to communicate with it self to start up WP_Cron, scheduled posts, make 1866 * sure plugin or theme edits dont cause site failures and similar. 1867 * 1868 * @since 5.2.0 1869 * 1870 * @return object The test results. 1871 */ 1872 function can_perform_loopback() { 1873 $cookies = wp_unslash( $_COOKIE ); 1874 $timeout = 10; 1875 $headers = array( 1876 'Cache-Control' => 'no-cache', 1877 ); 1878 1879 // Include Basic auth in loopback requests. 1880 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) { 1881 $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) ); 1882 } 1883 1884 $url = admin_url(); 1885 1886 $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) ); 1887 1888 if ( is_wp_error( $r ) ) { 1889 return (object) array( 1890 'status' => 'critical', 1891 'message' => sprintf( 1892 '%s<br>%s', 1893 __( 'The loopback request to your site failed, this means features relying on them are not currently working as expected.' ), 1894 sprintf( 1895 // translators: %1$d: The HTTP response code. %2$s: The error message returned. 1896 __( 'Error encountered: (%1$d) %2$s' ), 1897 wp_remote_retrieve_response_code( $r ), 1898 $r->get_error_message() 1899 ) 1900 ), 1901 ); 1902 } 1903 1904 if ( 200 !== wp_remote_retrieve_response_code( $r ) ) { 1905 return (object) array( 1906 'status' => 'recommended', 1907 'message' => sprintf( 1908 // translators: %d: The HTTP response code returned. 1909 __( 'The loopback request returned an unexpected http status code, %d, it was not possible to determine if this will prevent features from working as expected.' ), 1910 wp_remote_retrieve_response_code( $r ) 1911 ), 1912 ); 1913 } 1914 1915 return (object) array( 1916 'status' => 'good', 1917 'message' => __( 'The loopback request to your site completed successfully.' ), 1918 ); 1919 } 1920 } -
src/wp-admin/menu.php
diff --git a/src/wp-admin/menu.php b/src/wp-admin/menu.php index f4490b7bf3..ca9357b89b 100644
a b $menu[75] = array( __( 'Tools' ), 'edit_posts', 'tools.php', 263 263 $submenu['tools.php'][5] = array( __( 'Available Tools' ), 'edit_posts', 'tools.php' ); 264 264 $submenu['tools.php'][10] = array( __( 'Import' ), 'import', 'import.php' ); 265 265 $submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' ); 266 $submenu['tools.php'][20] = array( __( 'Site Health' ), 'install_plugins', 'site-health.php' ); 266 267 if ( is_multisite() && ! is_main_site() ) { 267 268 $submenu['tools.php'][25] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' ); 268 269 } -
new file src/wp-admin/site-health-info.php
diff --git a/src/wp-admin/site-health-info.php b/src/wp-admin/site-health-info.php new file mode 100644 index 0000000000..12584f51c1
- + 1 <?php 2 /** 3 * Tools Administration Screen. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once( dirname( __FILE__ ) . '/admin.php' ); 11 12 if ( ! current_user_can( 'install_plugins' ) ) { 13 wp_die( __( 'Sorry, you do not have permission to access the debug data.' ), '', array( 'reponse' => 401 ) ); 14 } 15 16 wp_enqueue_style( 'site-health' ); 17 wp_enqueue_script( 'site-health' ); 18 19 if ( ! class_exists( 'WP_Debug_Data' ) ) { 20 require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' ); 21 } 22 if ( ! class_exists( 'WP_Site_Health' ) ) { 23 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 24 } 25 26 $health_check_site_status = new WP_Site_Health(); 27 28 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 29 ?> 30 31 <div class="wrap health-check-header"> 32 <div class="title-section"> 33 <h1> 34 <?php _ex( 'Site Health', 'Menu, Section and Page Title' ); ?> 35 </h1> 36 37 <div id="progressbar" class="loading" data-pct="0" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-valuetext="<?php esc_attr_e( 'Site tests are running, please wait a moment.' ); ?>"> 38 <svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg"> 39 <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle> 40 <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle> 41 </svg> 42 </div> 43 </div> 44 45 <nav class="tabs-wrapper" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>"> 46 <a href="<?php echo esc_url( admin_url( 'site-health.php' ) ); ?>" class="tab"> 47 <?php _e( 'Status' ); ?> 48 </a> 49 50 <a href="<?php echo esc_url( admin_url( 'site-health.php?tab=debug' ) ); ?>" class="tab active" aria-current="true"> 51 <?php _e( 'Info' ); ?> 52 </a> 53 </nav> 54 55 <div class="wp-clearfix"></div> 56 </div> 57 58 <div class="wrap health-check-body"> 59 <?php 60 WP_Debug_Data::check_for_updates(); 61 62 $info = WP_Debug_Data::debug_data(); 63 ?> 64 65 <h2> 66 <?php _e( 'Site Info' ); ?> 67 </h2> 68 69 <p> 70 <?php _e( 'You can export the information on this page so it can be easily copied and pasted in support requests such as on the WordPress.org forums, or shared with your website / theme / plugin developers.' ); ?> 71 </p> 72 73 <p> 74 <button type="button" class="button button-link health-check-toggle-copy-section"> 75 <?php _e( 'Show options for copying this information.' ); ?> 76 </button> 77 </p> 78 79 <div class="system-information-copy-wrapper hidden"> 80 <textarea id="system-information-default-copy-field" rows="10"><?php WP_Debug_Data::textarea_format( $info ); ?></textarea> 81 82 <?php 83 if ( 'en_US' !== get_locale() && version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) : 84 85 $english_info = WP_Debug_Data::debug_data( 'en_US' ); 86 ?> 87 <textarea id="system-information-english-copy-field" class="system-information-copy-wrapper" rows="10"><?php WP_Debug_Data::textarea_format( $english_info ); ?></textarea> 88 89 <?php endif; ?> 90 91 <div class="copy-button-wrapper"> 92 <button type="button" class="button button-primary health-check-copy-field" data-copy-field="default"><?php _e( 'Copy to clipboard' ); ?></button> 93 <span class="copy-field-success" aria-hidden="true">Copied!</span> 94 </div> 95 <?php if ( 'en_US' !== get_locale() && version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) : ?> 96 <div class="copy-button-wrapper"> 97 <button type="button" class="button health-check-copy-field" data-copy-field="english"><?php _e( 'Copy to clipboard (English)' ); ?></button> 98 <span class="copy-field-success" aria-hidden="true">Copied!</span> 99 </div> 100 <?php endif; ?> 101 </div> 102 103 <dl id="health-check-debug" role="presentation" class="health-check-accordion"> 104 105 <?php 106 foreach ( $info as $section => $details ) { 107 if ( ! isset( $details['fields'] ) || empty( $details['fields'] ) ) { 108 continue; 109 } 110 ?> 111 <dt role="heading" aria-level="3"> 112 <button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" id="health-check-accordion-heading-<?php echo esc_attr( $section ); ?>" type="button"> 113 <span class="title"> 114 <?php echo esc_html( $details['label'] ); ?> 115 116 <?php if ( isset( $details['show_count'] ) && $details['show_count'] ) : ?> 117 <?php printf( '(%d)', count( $details['fields'] ) ); ?> 118 <?php endif; ?> 119 </span> 120 <span class="icon"></span> 121 </button> 122 </dt> 123 124 <dd id="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" role="region" aria-labelledby="health-check-accordion-heading-<?php echo esc_attr( $section ); ?>" class="health-check-accordion-panel" hidden="hidden"> 125 <?php 126 if ( isset( $details['description'] ) && ! empty( $details['description'] ) ) { 127 printf( 128 '<p>%s</p>', 129 wp_kses( 130 $details['description'], 131 array( 132 'a' => array( 133 'href' => true, 134 ), 135 'strong' => true, 136 'em' => true, 137 ) 138 ) 139 ); 140 } 141 ?> 142 <table class="widefat striped health-check-table"> 143 <tbody> 144 <?php 145 foreach ( $details['fields'] as $field ) { 146 if ( is_array( $field['value'] ) ) { 147 $values = ''; 148 foreach ( $field['value'] as $name => $value ) { 149 $values .= sprintf( 150 '<li>%s: %s</li>', 151 esc_html( $name ), 152 esc_html( $value ) 153 ); 154 } 155 } else { 156 $values = esc_html( $field['value'] ); 157 } 158 159 printf( 160 '<tr><td>%s</td><td>%s</td></tr>', 161 esc_html( $field['label'] ), 162 $values 163 ); 164 } 165 ?> 166 </tbody> 167 </table> 168 </dd> 169 <?php } ?> 170 </dl> 171 </div> 172 173 <?php 174 include( ABSPATH . 'wp-admin/admin-footer.php' ); -
new file src/wp-admin/site-health.php
diff --git a/src/wp-admin/site-health.php b/src/wp-admin/site-health.php new file mode 100644 index 0000000000..11a27a45a4
- + 1 <?php 2 /** 3 * Tools Administration Screen. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 if ( isset( $_GET['tab'] ) && 'debug' === $_GET['tab'] ) { 10 require_once( dirname( __FILE__ ) . '/site-health-info.php' ); 11 return; 12 } 13 14 /** WordPress Administration Bootstrap */ 15 require_once( dirname( __FILE__ ) . '/admin.php' ); 16 17 if ( ! current_user_can( 'install_plugins' ) ) { 18 wp_die( __( 'Sorry, you do not have permission to access site health information.' ), '', array( 'reponse' => 401 ) ); 19 } 20 21 wp_enqueue_style( 'site-health' ); 22 wp_enqueue_script( 'site-health' ); 23 24 if ( ! class_exists( 'WP_Site_Health' ) ) { 25 require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' ); 26 } 27 28 $health_check_site_status = new WP_Site_Health(); 29 30 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 31 ?> 32 33 <div class="wrap health-check-header"> 34 <div class="title-section"> 35 <h1> 36 <?php _ex( 'Site Health', 'Menu, Section and Page Title' ); ?> 37 </h1> 38 39 <div id="progressbar" class="loading" data-pct="0" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-valuetext="<?php esc_attr_e( 'Site tests are running, please wait a moment.' ); ?>"> 40 <svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg"> 41 <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle> 42 <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle> 43 </svg> 44 </div> 45 </div> 46 47 <nav class="tabs-wrapper" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>"> 48 <a href="<?php echo esc_url( admin_url( 'site-health.php' ) ); ?>" class="tab active" aria-current="true"> 49 <?php _e( 'Status' ); ?> 50 </a> 51 52 <a href="<?php echo esc_url( admin_url( 'site-health.php?tab=debug' ) ); ?>" class="tab"> 53 <?php _e( 'Info' ); ?> 54 </a> 55 </nav> 56 57 <div class="wp-clearfix"></div> 58 </div> 59 60 <div class="wrap health-check-body"> 61 <div class="site-status-all-clear hide"> 62 <p class="icon"> 63 <span class="dashicons dashicons-yes"></span> 64 </p> 65 66 <p class="encouragement"> 67 <?php _e( 'Great job!' ); ?> 68 </p> 69 70 <p> 71 <?php _e( 'Everything is running smoothly here.' ); ?> 72 </p> 73 </div> 74 75 <div class="site-status-has-issues"> 76 <h2> 77 <?php _e( 'Site Health Status' ); ?> 78 </h2> 79 80 <div class="issues-wrapper" id="health-check-issues-critical"> 81 <h3> 82 <span class="issue-count">0</span> <?php _e( 'Critical issues' ); ?> 83 </h3> 84 85 <dl id="health-check-site-status-critical" role="presentation" class="health-check-accordion issues"></dl> 86 </div> 87 88 <div class="issues-wrapper" id="health-check-issues-recommended"> 89 <h3> 90 <span class="issue-count">0</span> <?php _e( 'Recommended improvements' ); ?> 91 </h3> 92 93 <dl id="health-check-site-status-recommended" role="presentation" class="health-check-accordion issues"></dl> 94 </div> 95 </div> 96 97 <div class="view-more"> 98 <button type="button" class="button button-link site-health-view-passed" aria-expanded="false"> 99 <?php _e( 'Show passed tests' ); ?> 100 </button> 101 </div> 102 103 <div class="issues-wrapper hidden" id="health-check-issues-good"> 104 <h3> 105 <span class="issue-count">0</span> <?php _e( 'Items with no issues detected' ); ?> 106 </h3> 107 108 <dl id="health-check-site-status-good" role="presentation" class="health-check-accordion issues"></dl> 109 </div> 110 </div> 111 112 <script id="tmpl-health-check-issue" type="text/template"> 113 <dt role="heading" aria-level="4"> 114 <button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" id="health-check-accordion-heading-{{ data.test }}" type="button"> 115 <span class="title">{{ data.label }}</span> 116 <span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span> 117 <span class="icon"></span> 118 </button> 119 </dt> 120 <dd id="health-check-accordion-block-{{ data.test }}" aria-labelledby="health-check-accordion-heading-{{ data.test }}" role="region" class="health-check-accordion-panel" hidden="hidden"> 121 {{ data.description }} 122 <div class="actions"> 123 <p class="button-container">{{ data.actions }}</p> 124 </div> 125 </dd> 126 </script> 127 128 <?php 129 include( ABSPATH . 'wp-admin/admin-footer.php' ); -
src/wp-includes/script-loader.php
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index a3ca60e75e..5bba581d8f 100644
a b function wp_default_scripts( &$scripts ) { 1688 1688 ) 1689 1689 ); 1690 1690 1691 $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); 1692 1691 1693 $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); 1692 1694 did_action( 'init' ) && $scripts->localize( 1693 1695 'updates', … … function wp_default_styles( &$styles ) { 1933 1935 $styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" ); 1934 1936 $styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" ); 1935 1937 $styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) ); 1938 $styles->add( 'site-health', "/wp-admin/css/site-health$suffix.css" ); 1936 1939 1937 1940 $styles->add( 'wp-admin', false, array( 'dashicons', 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n' ) ); 1938 1941