Make WordPress Core

Ticket #47264: 47264.2.diff

File 47264.2.diff, 145.8 KB (added by edocev, 6 years ago)
  • package-lock.json

     
    629629                                },
    630630                                "lodash": {
    631631                                        "version": "3.10.1",
    632                                         "resolved": "http://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz",
     632                                        "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz",
    633633                                        "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=",
    634634                                        "dev": true
    635635                                }
     
    660660                },
    661661                "archiver": {
    662662                        "version": "1.3.0",
    663                         "resolved": "http://registry.npmjs.org/archiver/-/archiver-1.3.0.tgz",
     663                        "resolved": "https://registry.npmjs.org/archiver/-/archiver-1.3.0.tgz",
    664664                        "integrity": "sha1-TyGU1tj5nfP1MeaIHxTxXVX6ryI=",
    665665                        "dev": true,
    666666                        "requires": {
     
    985985                },
    986986                "bin-build": {
    987987                        "version": "2.2.0",
    988                         "resolved": "http://registry.npmjs.org/bin-build/-/bin-build-2.2.0.tgz",
     988                        "resolved": "https://registry.npmjs.org/bin-build/-/bin-build-2.2.0.tgz",
    989989                        "integrity": "sha1-EfjdYfcP/Por3KpbRvXo/t1CIcw=",
    990990                        "dev": true,
    991991                        "optional": true,
     
    10311031                },
    10321032                "bin-version": {
    10331033                        "version": "1.0.4",
    1034                         "resolved": "http://registry.npmjs.org/bin-version/-/bin-version-1.0.4.tgz",
     1034                        "resolved": "https://registry.npmjs.org/bin-version/-/bin-version-1.0.4.tgz",
    10351035                        "integrity": "sha1-nrSY7m/Xb3q5p8FgQ2+JV5Q1144=",
    10361036                        "dev": true,
    10371037                        "optional": true,
     
    10411041                },
    10421042                "bin-version-check": {
    10431043                        "version": "2.1.0",
    1044                         "resolved": "http://registry.npmjs.org/bin-version-check/-/bin-version-check-2.1.0.tgz",
     1044                        "resolved": "https://registry.npmjs.org/bin-version-check/-/bin-version-check-2.1.0.tgz",
    10451045                        "integrity": "sha1-5OXfKQuQaffRETJAMe/BP90RpbA=",
    10461046                        "dev": true,
    10471047                        "optional": true,
     
    10541054                        "dependencies": {
    10551055                                "semver": {
    10561056                                        "version": "4.3.6",
    1057                                         "resolved": "http://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
     1057                                        "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",
    10581058                                        "integrity": "sha1-MAvG4OhjdPe6YQaLWx7NV/xlMto=",
    10591059                                        "dev": true,
    10601060                                        "optional": true
     
    10631063                },
    10641064                "bin-wrapper": {
    10651065                        "version": "3.0.2",
    1066                         "resolved": "http://registry.npmjs.org/bin-wrapper/-/bin-wrapper-3.0.2.tgz",
     1066                        "resolved": "https://registry.npmjs.org/bin-wrapper/-/bin-wrapper-3.0.2.tgz",
    10671067                        "integrity": "sha1-Z9MwYmLksaXy+I7iNGT2plVneus=",
    10681068                        "dev": true,
    10691069                        "optional": true,
     
    12751275                },
    12761276                "browserify-rsa": {
    12771277                        "version": "4.0.1",
    1278                         "resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
     1278                        "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
    12791279                        "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=",
    12801280                        "dev": true,
    12811281                        "requires": {
     
    15051505                },
    15061506                "camelcase-keys": {
    15071507                        "version": "2.1.0",
    1508                         "resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
     1508                        "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
    15091509                        "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
    15101510                        "dev": true,
    15111511                        "requires": {
     
    15721572                },
    15731573                "chalk": {
    15741574                        "version": "1.1.3",
    1575                         "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
     1575                        "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
    15761576                        "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
    15771577                        "dev": true,
    15781578                        "requires": {
     
    20432043                },
    20442044                "commander": {
    20452045                        "version": "2.8.1",
    2046                         "resolved": "http://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
     2046                        "resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
    20472047                        "integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=",
    20482048                        "dev": true,
    20492049                        "requires": {
     
    23972397                },
    23982398                "cson-parser": {
    23992399                        "version": "1.3.5",
    2400                         "resolved": "http://registry.npmjs.org/cson-parser/-/cson-parser-1.3.5.tgz",
     2400                        "resolved": "https://registry.npmjs.org/cson-parser/-/cson-parser-1.3.5.tgz",
    24012401                        "integrity": "sha1-fsZ14DkUVTO/KmqFYHPxWZ2cLSQ=",
    24022402                        "dev": true,
    24032403                        "requires": {
     
    29282928                        "dependencies": {
    29292929                                "domelementtype": {
    29302930                                        "version": "1.1.3",
    2931                                         "resolved": "http://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz",
     2931                                        "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz",
    29322932                                        "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=",
    29332933                                        "dev": true
    29342934                                },
     
    31023102                },
    31033103                "entities": {
    31043104                        "version": "1.0.0",
    3105                         "resolved": "http://registry.npmjs.org/entities/-/entities-1.0.0.tgz",
     3105                        "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz",
    31063106                        "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=",
    31073107                        "dev": true
    31083108                },
     
    31913191                },
    31923192                "eventemitter2": {
    31933193                        "version": "0.4.14",
    3194                         "resolved": "http://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz",
     3194                        "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz",
    31953195                        "integrity": "sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas=",
    31963196                        "dev": true
    31973197                },
     
    32083208                },
    32093209                "events": {
    32103210                        "version": "1.1.1",
    3211                         "resolved": "http://registry.npmjs.org/events/-/events-1.1.1.tgz",
     3211                        "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
    32123212                        "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=",
    32133213                        "dev": true
    32143214                },
     
    33533353                },
    33543354                "expand-range": {
    33553355                        "version": "1.8.2",
    3356                         "resolved": "http://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz",
     3356                        "resolved": "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz",
    33573357                        "integrity": "sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc=",
    33583358                        "dev": true,
    33593359                        "requires": {
     
    34163416                        "dependencies": {
    34173417                                "array-flatten": {
    34183418                                        "version": "1.1.1",
    3419                                         "resolved": "http://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
     3419                                        "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
    34203420                                        "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
    34213421                                        "dev": true
    34223422                                },
     
    36703670                },
    36713671                "find-versions": {
    36723672                        "version": "1.2.1",
    3673                         "resolved": "http://registry.npmjs.org/find-versions/-/find-versions-1.2.1.tgz",
     3673                        "resolved": "https://registry.npmjs.org/find-versions/-/find-versions-1.2.1.tgz",
    36743674                        "integrity": "sha1-y96fEuOFdaCvG+G5osXV/Y8Ya2I=",
    36753675                        "dev": true,
    36763676                        "optional": true,
     
    36933693                        "dependencies": {
    36943694                                "commander": {
    36953695                                        "version": "2.1.0",
    3696                                         "resolved": "http://registry.npmjs.org/commander/-/commander-2.1.0.tgz",
     3696                                        "resolved": "https://registry.npmjs.org/commander/-/commander-2.1.0.tgz",
    36973697                                        "integrity": "sha1-0SG7roYNmZKj1Re6lvVliOR8Z4E=",
    36983698                                        "dev": true
    36993699                                }
     
    39133913                                "balanced-match": {
    39143914                                        "version": "1.0.0",
    39153915                                        "bundled": true,
    3916                                         "dev": true
     3916                                        "dev": true,
     3917                                        "optional": true
    39173918                                },
    39183919                                "brace-expansion": {
    39193920                                        "version": "1.1.11",
    39203921                                        "bundled": true,
    39213922                                        "dev": true,
     3923                                        "optional": true,
    39223924                                        "requires": {
    39233925                                                "balanced-match": "^1.0.0",
    39243926                                                "concat-map": "0.0.1"
     
    39333935                                "code-point-at": {
    39343936                                        "version": "1.1.0",
    39353937                                        "bundled": true,
    3936                                         "dev": true
     3938                                        "dev": true,
     3939                                        "optional": true
    39373940                                },
    39383941                                "concat-map": {
    39393942                                        "version": "0.0.1",
    39403943                                        "bundled": true,
    3941                                         "dev": true
     3944                                        "dev": true,
     3945                                        "optional": true
    39423946                                },
    39433947                                "console-control-strings": {
    39443948                                        "version": "1.1.0",
    39453949                                        "bundled": true,
    3946                                         "dev": true
     3950                                        "dev": true,
     3951                                        "optional": true
    39473952                                },
    39483953                                "core-util-is": {
    39493954                                        "version": "1.0.2",
     
    40604065                                "inherits": {
    40614066                                        "version": "2.0.3",
    40624067                                        "bundled": true,
    4063                                         "dev": true
     4068                                        "dev": true,
     4069                                        "optional": true
    40644070                                },
    40654071                                "ini": {
    40664072                                        "version": "1.3.5",
     
    40724078                                        "version": "1.0.0",
    40734079                                        "bundled": true,
    40744080                                        "dev": true,
     4081                                        "optional": true,
    40754082                                        "requires": {
    40764083                                                "number-is-nan": "^1.0.0"
    40774084                                        }
     
    40864093                                        "version": "3.0.4",
    40874094                                        "bundled": true,
    40884095                                        "dev": true,
     4096                                        "optional": true,
    40894097                                        "requires": {
    40904098                                                "brace-expansion": "^1.1.7"
    40914099                                        }
     
    41974205                                "number-is-nan": {
    41984206                                        "version": "1.0.1",
    41994207                                        "bundled": true,
    4200                                         "dev": true
     4208                                        "dev": true,
     4209                                        "optional": true
    42014210                                },
    42024211                                "object-assign": {
    42034212                                        "version": "4.1.1",
     
    43304339                                        "version": "1.0.2",
    43314340                                        "bundled": true,
    43324341                                        "dev": true,
     4342                                        "optional": true,
    43334343                                        "requires": {
    43344344                                                "code-point-at": "^1.0.0",
    43354345                                                "is-fullwidth-code-point": "^1.0.0",
     
    44984508                },
    44994509                "get-stream": {
    45004510                        "version": "3.0.0",
    4501                         "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
     4511                        "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
    45024512                        "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=",
    45034513                        "dev": true
    45044514                },
     
    45254535                },
    45264536                "gifsicle": {
    45274537                        "version": "3.0.4",
    4528                         "resolved": "http://registry.npmjs.org/gifsicle/-/gifsicle-3.0.4.tgz",
     4538                        "resolved": "https://registry.npmjs.org/gifsicle/-/gifsicle-3.0.4.tgz",
    45294539                        "integrity": "sha1-9Fy17RAWW2ZdySng6TKLbIId+js=",
    45304540                        "dev": true,
    45314541                        "optional": true,
     
    47594769                },
    47604770                "got": {
    47614771                        "version": "5.7.1",
    4762                         "resolved": "http://registry.npmjs.org/got/-/got-5.7.1.tgz",
     4772                        "resolved": "https://registry.npmjs.org/got/-/got-5.7.1.tgz",
    47634773                        "integrity": "sha1-X4FjWmHkplifGAVp6k44FoClHzU=",
    47644774                        "dev": true,
    47654775                        "requires": {
     
    50075017                },
    50085018                "grunt-contrib-uglify": {
    50095019                        "version": "2.0.0",
    5010                         "resolved": "http://registry.npmjs.org/grunt-contrib-uglify/-/grunt-contrib-uglify-2.0.0.tgz",
     5020                        "resolved": "https://registry.npmjs.org/grunt-contrib-uglify/-/grunt-contrib-uglify-2.0.0.tgz",
    50115021                        "integrity": "sha1-jJlw1pCTbN5tJaoRk1Sb2SkBaTA=",
    50125022                        "dev": true,
    50135023                        "requires": {
     
    51675177                        "dependencies": {
    51685178                                "colors": {
    51695179                                        "version": "1.1.2",
    5170                                         "resolved": "http://registry.npmjs.org/colors/-/colors-1.1.2.tgz",
     5180                                        "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz",
    51715181                                        "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=",
    51725182                                        "dev": true
    51735183                                }
     
    55705580                },
    55715581                "handle-thing": {
    55725582                        "version": "1.2.5",
    5573                         "resolved": "http://registry.npmjs.org/handle-thing/-/handle-thing-1.2.5.tgz",
     5583                        "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-1.2.5.tgz",
    55745584                        "integrity": "sha1-/Xqtcmvxpf0W38KbL3pmAdJxOcQ=",
    55755585                        "dev": true
    55765586                },
     
    57935803                },
    57945804                "htmlparser2": {
    57955805                        "version": "3.8.3",
    5796                         "resolved": "http://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz",
     5806                        "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz",
    57975807                        "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=",
    57985808                        "dev": true,
    57995809                        "requires": {
     
    58125822                                },
    58135823                                "readable-stream": {
    58145824                                        "version": "1.1.14",
    5815                                         "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
     5825                                        "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
    58165826                                        "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
    58175827                                        "dev": true,
    58185828                                        "requires": {
     
    58245834                                },
    58255835                                "string_decoder": {
    58265836                                        "version": "0.10.31",
    5827                                         "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
     5837                                        "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
    58285838                                        "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
    58295839                                        "dev": true
    58305840                                }
     
    65386548                },
    65396549                "is-builtin-module": {
    65406550                        "version": "1.0.0",
    6541                         "resolved": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
     6551                        "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
    65426552                        "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=",
    65436553                        "dev": true,
    65446554                        "requires": {
     
    66346644                },
    66356645                "is-gif": {
    66366646                        "version": "1.0.0",
    6637                         "resolved": "http://registry.npmjs.org/is-gif/-/is-gif-1.0.0.tgz",
     6647                        "resolved": "https://registry.npmjs.org/is-gif/-/is-gif-1.0.0.tgz",
    66386648                        "integrity": "sha1-ptKumIkwB7/6l6HYwB1jIFgyCX4=",
    66396649                        "dev": true,
    66406650                        "optional": true
     
    66976707                },
    66986708                "is-obj": {
    66996709                        "version": "1.0.1",
    6700                         "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
     6710                        "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
    67016711                        "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
    67026712                        "dev": true
    67036713                },
     
    69016911                },
    69026912                "jpegtran-bin": {
    69036913                        "version": "3.2.0",
    6904                         "resolved": "http://registry.npmjs.org/jpegtran-bin/-/jpegtran-bin-3.2.0.tgz",
     6914                        "resolved": "https://registry.npmjs.org/jpegtran-bin/-/jpegtran-bin-3.2.0.tgz",
    69056915                        "integrity": "sha1-9g7PSumZwL2tLp+83ytvCYHnops=",
    69066916                        "dev": true,
    69076917                        "optional": true,
     
    70947104                },
    70957105                "json5": {
    70967106                        "version": "0.5.1",
    7097                         "resolved": "http://registry.npmjs.org/json5/-/json5-0.5.1.tgz",
     7107                        "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz",
    70987108                        "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=",
    70997109                        "dev": true
    71007110                },
    71017111                "jsonfile": {
    71027112                        "version": "2.4.0",
    7103                         "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
     7113                        "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
    71047114                        "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
    71057115                        "dev": true,
    71067116                        "requires": {
     
    71697179                },
    71707180                "lazy-req": {
    71717181                        "version": "1.1.0",
    7172                         "resolved": "http://registry.npmjs.org/lazy-req/-/lazy-req-1.1.0.tgz",
     7182                        "resolved": "https://registry.npmjs.org/lazy-req/-/lazy-req-1.1.0.tgz",
    71737183                        "integrity": "sha1-va6+rTD42CQDnODOFJ1Nqge6H6w=",
    71747184                        "dev": true,
    71757185                        "optional": true
     
    72007210                },
    72017211                "load-json-file": {
    72027212                        "version": "1.1.0",
    7203                         "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
     7213                        "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
    72047214                        "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
    72057215                        "dev": true,
    72067216                        "requires": {
     
    79037913                },
    79047914                "media-typer": {
    79057915                        "version": "0.3.0",
    7906                         "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
     7916                        "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
    79077917                        "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
    79087918                        "dev": true
    79097919                },
     
    79307940                },
    79317941                "meow": {
    79327942                        "version": "3.7.0",
    7933                         "resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
     7943                        "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
    79347944                        "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
    79357945                        "dev": true,
    79367946                        "requires": {
     
    81638173                },
    81648174                "mkdirp": {
    81658175                        "version": "0.5.1",
    8166                         "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
     8176                        "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
    81678177                        "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
    81688178                        "dev": true,
    81698179                        "requires": {
     
    82578267                                },
    82588268                                "readable-stream": {
    82598269                                        "version": "1.1.14",
    8260                                         "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
     8270                                        "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
    82618271                                        "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
    82628272                                        "dev": true,
    82638273                                        "requires": {
     
    82698279                                },
    82708280                                "string_decoder": {
    82718281                                        "version": "0.10.31",
    8272                                         "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
     8282                                        "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
    82738283                                        "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
    82748284                                        "dev": true
    82758285                                }
     
    86848694                },
    86858695                "node-status-codes": {
    86868696                        "version": "1.0.0",
    8687                         "resolved": "http://registry.npmjs.org/node-status-codes/-/node-status-codes-1.0.0.tgz",
     8697                        "resolved": "https://registry.npmjs.org/node-status-codes/-/node-status-codes-1.0.0.tgz",
    86888698                        "integrity": "sha1-WuVUHQJGRdMqWPzdyc7s6nrjrC8=",
    86898699                        "dev": true
    86908700                },
     
    89358945                },
    89368946                "onetime": {
    89378947                        "version": "1.1.0",
    8938                         "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
     8948                        "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
    89398949                        "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
    89408950                        "dev": true
    89418951                },
     
    90099019                },
    90109020                "os-tmpdir": {
    90119021                        "version": "1.0.2",
    9012                         "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
     9022                        "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
    90139023                        "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
    90149024                        "dev": true
    90159025                },
     
    92129222                },
    92139223                "path-is-absolute": {
    92149224                        "version": "1.0.1",
    9215                         "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
     9225                        "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
    92169226                        "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
    92179227                        "dev": true
    92189228                },
     
    1083110841                },
    1083210842                "shelljs": {
    1083310843                        "version": "0.3.0",
    10834                         "resolved": "http://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz",
     10844                        "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz",
    1083510845                        "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=",
    1083610846                        "dev": true
    1083710847                },
     
    1134611356                },
    1134711357                "stream-browserify": {
    1134811358                        "version": "2.0.1",
    11349                         "resolved": "http://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz",
     11359                        "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz",
    1135011360                        "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=",
    1135111361                        "dev": true,
    1135211362                        "requires": {
     
    1148711497                },
    1148811498                "strip-dirs": {
    1148911499                        "version": "1.1.1",
    11490                         "resolved": "http://registry.npmjs.org/strip-dirs/-/strip-dirs-1.1.1.tgz",
     11500                        "resolved": "https://registry.npmjs.org/strip-dirs/-/strip-dirs-1.1.1.tgz",
    1149111501                        "integrity": "sha1-lgu9EoeETzl1pFWKoQOoJV4kVqA=",
    1149211502                        "dev": true,
    1149311503                        "requires": {
     
    1150111511                },
    1150211512                "strip-eof": {
    1150311513                        "version": "1.0.0",
    11504                         "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
     11514                        "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
    1150511515                        "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
    1150611516                        "dev": true
    1150711517                },
     
    1156511575                        "dependencies": {
    1156611576                                "colors": {
    1156711577                                        "version": "1.1.2",
    11568                                         "resolved": "http://registry.npmjs.org/colors/-/colors-1.1.2.tgz",
     11578                                        "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz",
    1156911579                                        "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=",
    1157011580                                        "dev": true,
    1157111581                                        "optional": true
     
    1177911789                },
    1178011790                "through": {
    1178111791                        "version": "2.3.8",
    11782                         "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
     11792                        "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
    1178311793                        "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
    1178411794                        "dev": true
    1178511795                },
    1178611796                "through2": {
    1178711797                        "version": "0.6.5",
    11788                         "resolved": "http://registry.npmjs.org/through2/-/through2-0.6.5.tgz",
     11798                        "resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz",
    1178911799                        "integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=",
    1179011800                        "dev": true,
    1179111801                        "requires": {
     
    1180111811                                },
    1180211812                                "readable-stream": {
    1180311813                                        "version": "1.0.34",
    11804                                         "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
     11814                                        "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
    1180511815                                        "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
    1180611816                                        "dev": true,
    1180711817                                        "requires": {
     
    1181311823                                },
    1181411824                                "string_decoder": {
    1181511825                                        "version": "0.10.31",
    11816                                         "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
     11826                                        "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
    1181711827                                        "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
    1181811828                                        "dev": true
    1181911829                                }
     
    1212112131                },
    1212212132                "uglify-js": {
    1212312133                        "version": "2.7.5",
    12124                         "resolved": "http://registry.npmjs.org/uglify-js/-/uglify-js-2.7.5.tgz",
     12134                        "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.7.5.tgz",
    1212512135                        "integrity": "sha1-RhLAx7qu4rp8SH3kkErhIgefLKg=",
    1212612136                        "dev": true,
    1212712137                        "requires": {
     
    1213312143                        "dependencies": {
    1213412144                                "async": {
    1213512145                                        "version": "0.2.10",
    12136                                         "resolved": "http://registry.npmjs.org/async/-/async-0.2.10.tgz",
     12146                                        "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
    1213712147                                        "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=",
    1213812148                                        "dev": true
    1213912149                                },
     
    1330013310                },
    1330113311                "wrap-ansi": {
    1330213312                        "version": "2.1.0",
    13303                         "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
     13313                        "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
    1330413314                        "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=",
    1330513315                        "dev": true,
    1330613316                        "requires": {
     
    1332513335                },
    1332613336                "xmlbuilder": {
    1332713337                        "version": "8.2.2",
    13328                         "resolved": "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
     13338                        "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
    1332913339                        "integrity": "sha1-aSSGc0ELS6QuGmE2VR0pIjNap3M=",
    1333013340                        "dev": true
    1333113341                },
  • src/wp-admin/includes/class-wp-site-health.php

     
    1 <?php
    2 /**
    3  * Class for looking up a site's health based on a user's 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_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
    32 
    33                 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    34         }
    35 
    36         /**
    37          * Enqueues the site health scripts.
    38          *
    39          * @since 5.2.0
    40          */
    41         public function enqueue_scripts() {
    42                 $screen = get_current_screen();
    43                 if ( 'site-health' !== $screen->id ) {
    44                         return;
    45                 }
    46 
    47                 $health_check_js_variables = array(
    48                         'screen'      => $screen->id,
    49                         'nonce'       => array(
    50                                 'site_status'        => wp_create_nonce( 'health-check-site-status' ),
    51                                 'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ),
    52                         ),
    53                         'site_status' => array(
    54                                 'direct' => array(),
    55                                 'async'  => array(),
    56                                 'issues' => array(
    57                                         'good'        => 0,
    58                                         'recommended' => 0,
    59                                         'critical'    => 0,
    60                                 ),
    61                         ),
    62                 );
    63 
    64                 $issue_counts = get_transient( 'health-check-site-status-result' );
    65 
    66                 if ( false !== $issue_counts ) {
    67                         $issue_counts = json_decode( $issue_counts );
    68 
    69                         $health_check_js_variables['site_status']['issues'] = $issue_counts;
    70                 }
    71 
    72                 if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
    73                         $tests = WP_Site_Health::get_tests();
    74 
    75                         // Don't run https test on localhost
    76                         if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
    77                                 unset( $tests['direct']['https_status'] );
    78                         }
    79 
    80                         foreach ( $tests['direct'] as $test ) {
    81                                 if ( is_string( $test['test'] ) ) {
    82                                         $test_function = sprintf(
    83                                                 'get_test_%s',
    84                                                 $test['test']
    85                                         );
    86 
    87                                         if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
    88                                                 $health_check_js_variables['site_status']['direct'][] = call_user_func( array( $this, $test_function ) );
    89                                                 continue;
    90                                         }
    91                                 }
    92 
    93                                 if ( is_callable( $test['test'] ) ) {
    94                                         $health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] );
    95                                 }
    96                         }
    97 
    98                         foreach ( $tests['async'] as $test ) {
    99                                 if ( is_string( $test['test'] ) ) {
    100                                         $health_check_js_variables['site_status']['async'][] = array(
    101                                                 'test'      => $test['test'],
    102                                                 'completed' => false,
    103                                         );
    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' => __( 'Performance' ),
    184                                 'color' => 'blue',
    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['badge']['label'] = __( 'Security' );
    245                                                 $result['description']    = sprintf(
    246                                                         '<p>%s</p>',
    247                                                         __( 'A new minor update is available for your site. Because minor updates often address security, it&#8217;s important to install them.' )
    248                                                 );
    249                                         }
    250                                 } else {
    251                                         $result['status'] = 'good';
    252                                         $result['label']  = sprintf(
    253                                                 // translators: %s: The current version of WordPress installed on this site.
    254                                                 __( 'Your WordPress version is up to date (%s)' ),
    255                                                 $core_current_version
    256                                         );
    257 
    258                                         $result['description'] = sprintf(
    259                                                 '<p>%s</p>',
    260                                                 __( 'You are currently running the latest version of WordPress available, keep it up!' )
    261                                         );
    262                                 }
    263                         }
    264                 }
    265 
    266                 return $result;
    267         }
    268 
    269         /**
    270          * Test if plugins are outdated, or unnecessary.
    271          *
    272          * The tests checks if your plugins are up to date, and encourages you to remove any that are not in use.
    273          *
    274          * @since 5.2.0
    275          *
    276          * @return array The test result.
    277          */
    278         public function get_test_plugin_version() {
    279                 $result = array(
    280                         'label'       => __( 'Your plugins are up to date' ),
    281                         'status'      => 'good',
    282                         'badge'       => array(
    283                                 'label' => __( 'Security' ),
    284                                 'color' => 'blue',
    285                         ),
    286                         'description' => sprintf(
    287                                 '<p>%s</p>',
    288                                 __( 'Plugins extend your site&#8217;s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it&#8217;s vital to keep them up to date.' )
    289                         ),
    290                         'actions'     => sprintf(
    291                                 '<p><a href="%s">%s</a></p>',
    292                                 esc_url( admin_url( 'plugins.php' ) ),
    293                                 __( 'Manage your plugins' )
    294                         ),
    295                         'test'        => 'plugin_version',
    296                 );
    297 
    298                 $plugins        = get_plugins();
    299                 $plugin_updates = get_plugin_updates();
    300 
    301                 $plugins_have_updates = false;
    302                 $plugins_active       = 0;
    303                 $plugins_total        = 0;
    304                 $plugins_need_update  = 0;
    305 
    306                 // Loop over the available plugins and check their versions and active state.
    307                 foreach ( $plugins as $plugin_path => $plugin ) {
    308                         $plugins_total++;
    309 
    310                         if ( is_plugin_active( $plugin_path ) ) {
    311                                 $plugins_active++;
    312                         }
    313 
    314                         $plugin_version = $plugin['Version'];
    315 
    316                         if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
    317                                 $plugins_need_update++;
    318                                 $plugins_have_updates = true;
    319                         }
    320                 }
    321 
    322                 // Add a notice if there are outdated plugins.
    323                 if ( $plugins_need_update > 0 ) {
    324                         $result['status'] = 'critical';
    325 
    326                         $result['label'] = __( 'You have plugins waiting to be updated' );
    327 
    328                         $result['description'] .= sprintf(
    329                                 '<p>%s</p>',
    330                                 sprintf(
    331                                         /* translators: %d: The number of outdated plugins. */
    332                                         _n(
    333                                                 'Your site has %d plugin waiting to be updated.',
    334                                                 'Your site has %d plugins waiting to be updated.',
    335                                                 $plugins_need_update
    336                                         ),
    337                                         $plugins_need_update
    338                                 )
    339                         );
    340 
    341                         $result['actions'] .= sprintf(
    342                                 '<p><a href="%s">%s</a></p>',
    343                                 esc_url( admin_url( 'plugins.php?plugin_status=upgrade' ) ),
    344                                 __( 'Update your plugins' )
    345                         );
    346                 } else {
    347                         if ( 1 === $plugins_active ) {
    348                                 $result['description'] .= sprintf(
    349                                         '<p>%s</p>',
    350                                         __( 'Your site has 1 active plugin, and it is up to date.' )
    351                                 );
    352                         } else {
    353                                 $result['description'] .= sprintf(
    354                                         '<p>%s</p>',
    355                                         sprintf(
    356                                                 /* translators: %d: The number of active plugins. */
    357                                                 _n(
    358                                                         'Your site has %d active plugin, and they are all up to date.',
    359                                                         'Your site has %d active plugins, and they are all up to date.',
    360                                                         $plugins_active
    361                                                 ),
    362                                                 $plugins_active
    363                                         )
    364                                 );
    365                         }
    366                 }
    367 
    368                 // Check if there are inactive plugins.
    369                 if ( $plugins_total > $plugins_active && ! is_multisite() ) {
    370                         $unused_plugins = $plugins_total - $plugins_active;
    371 
    372                         $result['status'] = 'recommended';
    373 
    374                         $result['label'] = __( 'You should remove inactive plugins' );
    375 
    376                         $result['description'] .= sprintf(
    377                                 '<p>%s %s</p>',
    378                                 sprintf(
    379                                         /* translators: %d: The number of inactive plugins. */
    380                                         _n(
    381                                                 'Your site has %d inactive plugin.',
    382                                                 'Your site has %d inactive plugins.',
    383                                                 $unused_plugins
    384                                         ),
    385                                         $unused_plugins
    386                                 ),
    387                                 __( 'Inactive plugins are tempting targets for attackers. If you&#8217;re not going to use a plugin, we recommend you remove it.' )
    388                         );
    389 
    390                         $result['actions'] .= sprintf(
    391                                 '<p><a href="%s">%s</a></p>',
    392                                 esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
    393                                 __( 'Manage inactive plugins' )
    394                         );
    395                 }
    396 
    397                 return $result;
    398         }
    399 
    400         /**
    401          * Test if themes are outdated, or unnecessary.
    402          *
    403          * The tests checks if your site has a default theme (to fall back on if there is a need), if your themes
    404          * are up to date and, finally, encourages you to remove any themes that are not needed.
    405          *
    406          * @since 5.2.0
    407          *
    408          * @return array The test results.
    409          */
    410         public function get_test_theme_version() {
    411                 $result = array(
    412                         'label'       => __( 'Your themes are up to date' ),
    413                         'status'      => 'good',
    414                         'badge'       => array(
    415                                 'label' => __( 'Security' ),
    416                                 'color' => 'blue',
    417                         ),
    418                         'description' => sprintf(
    419                                 '<p>%s</p>',
    420                                 __( 'Themes add your site&#8217;s look and feel. It&#8217;s important to keep them up to date, to stay consistent with your brand and keep your site secure.' )
    421                         ),
    422                         'actions'     => sprintf(
    423                                 '<p><a href="%s">%s</a></p>',
    424                                 esc_url( admin_url( 'themes.php' ) ),
    425                                 __( 'Manage your themes' )
    426                         ),
    427                         'test'        => 'theme_version',
    428                 );
    429 
    430                 $theme_updates = get_theme_updates();
    431 
    432                 $themes_total        = 0;
    433                 $themes_need_updates = 0;
    434                 $themes_inactive     = 0;
    435 
    436                 // This value is changed during processing to determine how many themes are considered a reasonable amount.
    437                 $allowed_theme_count = 1;
    438 
    439                 $has_default_theme   = false;
    440                 $has_unused_themes   = false;
    441                 $show_unused_themes  = true;
    442                 $using_default_theme = false;
    443 
    444                 // Populate a list of all themes available in the install.
    445                 $all_themes   = wp_get_themes();
    446                 $active_theme = wp_get_theme();
    447 
    448                 foreach ( $all_themes as $theme_slug => $theme ) {
    449                         $themes_total++;
    450 
    451                         if ( WP_DEFAULT_THEME === $theme_slug ) {
    452                                 $has_default_theme = true;
    453 
    454                                 if ( get_stylesheet() === $theme_slug ) {
    455                                         $using_default_theme = true;
    456                                 }
    457                         }
    458 
    459                         if ( array_key_exists( $theme_slug, $theme_updates ) ) {
    460                                 $themes_need_updates++;
    461                         }
    462                 }
    463 
    464                 // If this is a child theme, increase the allowed theme count by one, to account for the parent.
    465                 if ( $active_theme->parent() ) {
    466                         $allowed_theme_count++;
    467 
    468                         if ( $active_theme->get_template() === WP_DEFAULT_THEME ) {
    469                                 $using_default_theme = true;
    470                         }
    471                 }
    472 
    473                 // If there's a default theme installed and not in use, we count that as allowed as well.
    474                 if ( $has_default_theme && ! $using_default_theme ) {
    475                         $allowed_theme_count++;
    476                 }
    477 
    478                 if ( $themes_total > $allowed_theme_count ) {
    479                         $has_unused_themes = true;
    480                         $themes_inactive   = ( $themes_total - $allowed_theme_count );
    481                 }
    482 
    483                 // Check if any themes need to be updated.
    484                 if ( $themes_need_updates > 0 ) {
    485                         $result['status'] = 'critical';
    486 
    487                         $result['label'] = __( 'You have themes waiting to be updated' );
    488 
    489                         $result['description'] .= sprintf(
    490                                 '<p>%s</p>',
    491                                 sprintf(
    492                                         /* translators: %d: The number of outdated themes. */
    493                                         _n(
    494                                                 'Your site has %d theme waiting to be updated.',
    495                                                 'Your site has %d themes waiting to be updated.',
    496                                                 $themes_need_updates
    497                                         ),
    498                                         $themes_need_updates
    499                                 )
    500                         );
    501                 } else {
    502                         // Give positive feedback about the site being good about keeping things up to date.
    503                         if ( 1 === $themes_total ) {
    504                                 $result['description'] .= sprintf(
    505                                         '<p>%s</p>',
    506                                         __( 'Your site has 1 installed theme, and it is up to date.' )
    507                                 );
    508                         } else {
    509                                 $result['description'] .= sprintf(
    510                                         '<p>%s</p>',
    511                                         sprintf(
    512                                                 /* translators: %d: The number of themes. */
    513                                                 _n(
    514                                                         'Your site has %d installed theme, and they are all up to date.',
    515                                                         'Your site has %d installed themes, and they are all up to date.',
    516                                                         $themes_total
    517                                                 ),
    518                                                 $themes_total
    519                                         )
    520                                 );
    521                         }
    522                 }
    523 
    524                 if ( $has_unused_themes && $show_unused_themes && ! is_multisite() ) {
    525 
    526                         // This is a child theme, so we want to be a bit more explicit in our messages.
    527                         if ( $active_theme->parent() ) {
    528                                 // Recommend removing inactive themes, except a default theme, your current one, and the parent theme.
    529                                 $result['status'] = 'recommended';
    530 
    531                                 $result['label'] = __( 'You should remove inactive themes' );
    532 
    533                                 if ( $using_default_theme ) {
    534                                         $result['description'] .= sprintf(
    535                                                 '<p>%s %s</p>',
    536                                                 sprintf(
    537                                                         /* translators: %d: The number of inactive themes. */
    538                                                         _n(
    539                                                                 'Your site has %d inactive theme.',
    540                                                                 'Your site has %d inactive themes.',
    541                                                                 $themes_inactive
    542                                                         ),
    543                                                         $themes_inactive
    544                                                 ),
    545                                                 sprintf(
    546                                                         /* translators: 1: The currently active theme. 2: The active theme's parent theme. */
    547                                                         __( 'To enhance your site&#8217;s security, we recommend you remove any themes you&#8217;re not using. You should keep your current theme, %1$s, and %2$s, its parent theme.' ),
    548                                                         $active_theme->name,
    549                                                         $active_theme->parent()->name
    550                                                 )
    551                                         );
    552                                 } else {
    553                                         $result['description'] .= sprintf(
    554                                                 '<p>%s %s</p>',
    555                                                 sprintf(
    556                                                         /* translators: %d: The number of inactive themes. */
    557                                                         _n(
    558                                                                 'Your site has %d inactive theme.',
    559                                                                 'Your site has %d inactive themes.',
    560                                                                 $themes_inactive
    561                                                         ),
    562                                                         $themes_inactive
    563                                                 ),
    564                                                 sprintf(
    565                                                         /* translators: 1: The default theme for WordPress. 2: The currently active theme. 3: The active theme's parent theme. */
    566                                                         __( 'To enhance your site&#8217;s security, we recommend you remove any themes you&#8217;re not using. You should keep %1$s, the default WordPress theme, %2$s, your current theme, and %3$s, its parent theme.' ),
    567                                                         WP_DEFAULT_THEME,
    568                                                         $active_theme->name,
    569                                                         $active_theme->parent()->name
    570                                                 )
    571                                         );
    572                                 }
    573                         } else {
    574                                 // Recommend removing all inactive themes.
    575                                 $result['status'] = 'recommended';
    576 
    577                                 $result['label'] = __( 'You should remove inactive themes' );
    578 
    579                                 if ( $using_default_theme ) {
    580                                         $result['description'] .= sprintf(
    581                                                 '<p>%s %s</p>',
    582                                                 sprintf(
    583                                                         /* translators: 1: The amount of inactive themes. 2: The currently active theme. */
    584                                                         _n(
    585                                                                 'Your site has %1$d inactive theme, other than %2$s, your active theme.',
    586                                                                 'Your site has %1$d inactive themes, other than %2$s, your active theme.',
    587                                                                 $themes_inactive
    588                                                         ),
    589                                                         $themes_inactive,
    590                                                         $active_theme->name
    591                                                 ),
    592                                                 __( 'We recommend removing any unused themes to enhance your site&#8217;s security.' )
    593                                         );
    594                                 } else {
    595                                         $result['description'] .= sprintf(
    596                                                 '<p>%s %s</p>',
    597                                                 sprintf(
    598                                                         /* translators: 1: The amount of inactive themes. 2: The default theme for WordPress. 3: The currently active theme. */
    599                                                         _n(
    600                                                                 'Your site has %1$d inactive theme, other than %2$s, the default WordPress theme, and %3$s, your active theme.',
    601                                                                 'Your site has %1$d inactive themes, other than %2$s, the default WordPress theme, and %3$s, your active theme.',
    602                                                                 $themes_inactive
    603                                                         ),
    604                                                         $themes_inactive,
    605                                                         WP_DEFAULT_THEME,
    606                                                         $active_theme->name
    607                                                 ),
    608                                                 __( 'We recommend removing any unused themes to enhance your site&#8217;s security.' )
    609                                         );
    610                                 }
    611                         }
    612                 }
    613 
    614                 // If not default Twenty* theme exists.
    615                 if ( ! $has_default_theme ) {
    616                         $result['status'] = 'recommended';
    617 
    618                         $result['label'] = __( 'Have a default theme available' );
    619 
    620                         $result['description'] .= sprintf(
    621                                 '<p>%s</p>',
    622                                 __( 'Your site does not have any default theme. Default themes are used by WordPress automatically if anything is wrong with your normal theme.' )
    623                         );
    624                 }
    625 
    626                 return $result;
    627         }
    628 
    629         /**
    630          * Test if the supplied PHP version is supported.
    631          *
    632          * @since 5.2.0
    633          *
    634          * @return array The test results.
    635          */
    636         public function get_test_php_version() {
    637                 $response = wp_check_php_version();
    638 
    639                 $result = array(
    640                         'label'       => sprintf(
    641                                 // translators: %s: The current PHP version.
    642                                 __( 'PHP is up to date (%s)' ),
    643                                 PHP_VERSION
    644                         ),
    645                         'status'      => 'good',
    646                         'badge'       => array(
    647                                 'label' => __( 'Performance' ),
    648                                 'color' => 'blue',
    649                         ),
    650                         'description' => sprintf(
    651                                 '<p>%s</p>',
    652                                 __( '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&#8217;s performance.' )
    653                         ),
    654                         'actions'     => sprintf(
    655                                 '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
    656                                 esc_url( wp_get_update_php_url() ),
    657                                 __( 'Learn more about updating PHP' ),
    658                                 /* translators: accessibility text */
    659                                 __( '(opens in a new tab)' )
    660                         ),
    661                         'test'        => 'php_version',
    662                 );
    663 
    664                 // PHP is up to date.
    665                 if ( ! $response || version_compare( PHP_VERSION, $response['recommended_version'], '>=' ) ) {
    666                         return $result;
    667                 }
    668 
    669                 // The PHP version is older than the recommended version, but still acceptable.
    670                 if ( $response['is_supported'] ) {
    671                         $result['label']  = __( 'We recommend that you update PHP' );
    672                         $result['status'] = 'recommended';
    673 
    674                         return $result;
    675                 }
    676 
    677                 // The PHP version is only receiving security fixes.
    678                 if ( $response['is_secure'] ) {
    679                         $result['label']  = __( 'Your PHP version should be updated' );
    680                         $result['status'] = 'recommended';
    681 
    682                         return $result;
    683                 }
    684 
    685                 // Anything no longer secure must be updated.
    686                 $result['label']          = __( 'Your PHP version requires an update' );
    687                 $result['status']         = 'critical';
    688                 $result['badge']['label'] = __( 'Security' );
    689 
    690                 return $result;
    691         }
    692 
    693         /**
    694          * Check if the passed extension or function are available.
    695          *
    696          * Make the check for available PHP modules into a simple boolean operator for a cleaner test runner.
    697          *
    698          * @since 5.2.0
    699          *
    700          * @param string $extension Optional. The extension name to test. Default null.
    701          * @param string $function  Optional. The function name to test. Default null.
    702          *
    703          * @return bool Whether or not the extension and function are available.
    704          */
    705         private function test_php_extension_availability( $extension = null, $function = null ) {
    706                 // If no extension or function is passed, claim to fail testing, as we have nothing to test against.
    707                 if ( ! $extension && ! $function ) {
    708                         return false;
    709                 }
    710 
    711                 if ( $extension && ! extension_loaded( $extension ) ) {
    712                         return false;
    713                 }
    714                 if ( $function && ! function_exists( $function ) ) {
    715                         return false;
    716                 }
    717 
    718                 return true;
    719         }
    720 
    721         /**
    722          * Test if required PHP modules are installed on the host.
    723          *
    724          * This test builds on the recommendations made by the WordPress Hosting Team
    725          * as seen at https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions
    726          *
    727          * @since 5.2.0
    728          *
    729          * @return array
    730          */
    731         public function get_test_php_extensions() {
    732                 $result = array(
    733                         'label'       => __( 'Required and recommended modules are installed' ),
    734                         'status'      => 'good',
    735                         'badge'       => array(
    736                                 'label' => __( 'Performance' ),
    737                                 'color' => 'blue',
    738                         ),
    739                         'description' => sprintf(
    740                                 '<p>%s</p><p>%s</p>',
    741                                 __( 'PHP modules perform most of the tasks on the server that make your site run. Any changes to these must be made by your server administrator.' ),
    742                                 sprintf(
    743                                         /* translators: %s: Link to the hosting group page about recommended PHP modules. */
    744                                         __( 'The WordPress Hosting Team maintains a list of those modules, both recommended and required, in %s.' ),
    745                                         sprintf(
    746                                                 '<a 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>',
    747                                                 /* translators: Localized team handbook, if one exists. */
    748                                                 esc_url( __( 'https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions' ) ),
    749                                                 __( 'the team handbook' ),
    750                                                 /* translators: accessibility text */
    751                                                 __( '(opens in a new tab)' )
    752                                         )
    753                                 )
    754                         ),
    755                         'actions'     => '',
    756                         'test'        => 'php_extensions',
    757                 );
    758 
    759                 $modules = array(
    760                         'bcmath'    => array(
    761                                 'function' => 'bcadd',
    762                                 'required' => false,
    763                         ),
    764                         'curl'      => array(
    765                                 'function' => 'curl_version',
    766                                 'required' => false,
    767                         ),
    768                         'exif'      => array(
    769                                 'function' => 'exif_read_data',
    770                                 'required' => false,
    771                         ),
    772                         'filter'    => array(
    773                                 'function' => 'filter_list',
    774                                 'required' => false,
    775                         ),
    776                         'fileinfo'  => array(
    777                                 'function' => 'finfo_file',
    778                                 'required' => false,
    779                         ),
    780                         'mod_xml'   => array(
    781                                 'extension' => 'libxml',
    782                                 'required'  => false,
    783                         ),
    784                         'mysqli'    => array(
    785                                 'function' => 'mysqli_connect',
    786                                 'required' => false,
    787                         ),
    788                         'libsodium' => array(
    789                                 'function'            => 'sodium_compare',
    790                                 'required'            => false,
    791                                 'php_bundled_version' => '7.2.0',
    792                         ),
    793                         'openssl'   => array(
    794                                 'function' => 'openssl_encrypt',
    795                                 'required' => false,
    796                         ),
    797                         'pcre'      => array(
    798                                 'function' => 'preg_match',
    799                                 'required' => false,
    800                         ),
    801                         'imagick'   => array(
    802                                 'extension' => 'imagick',
    803                                 'required'  => false,
    804                         ),
    805                         'gd'        => array(
    806                                 'extension'    => 'gd',
    807                                 'required'     => false,
    808                                 'fallback_for' => 'imagick',
    809                         ),
    810                         'mcrypt'    => array(
    811                                 'extension'    => 'mcrypt',
    812                                 'required'     => false,
    813                                 'fallback_for' => 'libsodium',
    814                         ),
    815                         'xmlreader' => array(
    816                                 'extension'    => 'xmlreader',
    817                                 'required'     => false,
    818                                 'fallback_for' => 'xml',
    819                         ),
    820                         'zlib'      => array(
    821                                 'extension'    => 'zlib',
    822                                 'required'     => false,
    823                                 'fallback_for' => 'zip',
    824                         ),
    825                 );
    826 
    827                 /**
    828                  * An array representing all the modules we wish to test for.
    829                  *
    830                  * @since 5.2.0
    831                  *
    832                  * @param array $modules {
    833                  *     An associated array of modules to test for.
    834                  *
    835                  *     array $module {
    836                  *         An associated array of module properties used during testing.
    837                  *         One of either `$function` or `$extension` must be provided, or they will fail by default.
    838                  *
    839                  *         string $function     Optional. A function name to test for the existence of.
    840                  *         string $extension    Optional. An extension to check if is loaded in PHP.
    841                  *         bool   $required     Is this a required feature or not.
    842                  *         string $fallback_for Optional. The module this module replaces as a fallback.
    843                  *     }
    844                  * }
    845                  */
    846                 $modules = apply_filters( 'site_status_test_php_modules', $modules );
    847 
    848                 $failures = array();
    849 
    850                 foreach ( $modules as $library => $module ) {
    851                         $extension = ( isset( $module['extension'] ) ? $module['extension'] : null );
    852                         $function  = ( isset( $module['function'] ) ? $module['function'] : null );
    853 
    854                         // If this module is a fallback for another function, check if that other function passed.
    855                         if ( isset( $module['fallback_for'] ) ) {
    856                                 /*
    857                                  * If that other function has a failure, mark this module as required for normal operations.
    858                                  * If that other function hasn't failed, skip this test as it's only a fallback.
    859                                  */
    860                                 if ( isset( $failures[ $module['fallback_for'] ] ) ) {
    861                                         $module['required'] = true;
    862                                 } else {
    863                                         continue;
    864                                 }
    865                         }
    866 
    867                         if ( ! $this->test_php_extension_availability( $extension, $function ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
    868                                 if ( $module['required'] ) {
    869                                         $result['status'] = 'critical';
    870 
    871                                         $class         = 'error';
    872                                         $screen_reader = __( 'Error' );
    873                                         $message       = sprintf(
    874                                                 /* translators: %s: The module name. */
    875                                                 __( 'The required module, %s, is not installed, or has been disabled.' ),
    876                                                 $library
    877                                         );
    878                                 } else {
    879                                         $class         = 'warning';
    880                                         $screen_reader = __( 'Warning' );
    881                                         $message       = sprintf(
    882                                                 /* translators: %s: The module name. */
    883                                                 __( 'The optional module, %s, is not installed, or has been disabled.' ),
    884                                                 $library
    885                                         );
    886                                 }
    887 
    888                                 if ( ! $module['required'] && 'good' === $result['status'] ) {
    889                                         $result['status'] = 'recommended';
    890                                 }
    891 
    892                                 $failures[ $library ] = "<span class='$class'><span class='screen-reader-text'>$screen_reader</span></span> $message";
    893                         }
    894                 }
    895 
    896                 if ( ! empty( $failures ) ) {
    897                         $output = '<ul>';
    898 
    899                         foreach ( $failures as $failure ) {
    900                                 $output .= sprintf(
    901                                         '<li>%s</li>',
    902                                         $failure
    903                                 );
    904                         }
    905 
    906                         $output .= '</ul>';
    907                 }
    908 
    909                 if ( 'good' !== $result['status'] ) {
    910                         if ( 'recommended' === $result['status'] ) {
    911                                 $result['label'] = __( 'One or more recommended modules are missing' );
    912                         }
    913                         if ( 'critical' === $result['status'] ) {
    914                                 $result['label'] = __( 'One or more required modules are missing' );
    915                         }
    916 
    917                         $result['description'] .= sprintf(
    918                                 '<p>%s</p>',
    919                                 $output
    920                         );
    921                 }
    922 
    923                 return $result;
    924         }
    925 
    926         /**
    927          * Test if the SQL server is up to date.
    928          *
    929          * @since 5.2.0
    930          *
    931          * @return array The test results.
    932          */
    933         public function get_test_sql_server() {
    934                 $result = array(
    935                         'label'       => __( 'SQL server is up to date' ),
    936                         'status'      => 'good',
    937                         'badge'       => array(
    938                                 'label' => __( 'Performance' ),
    939                                 'color' => 'blue',
    940                         ),
    941                         'description' => sprintf(
    942                                 '<p>%s</p>',
    943                                 __( 'The SQL server is a required piece of software for the database WordPress uses to store all your site&#8217;s content and settings.' )
    944                         ),
    945                         'actions'     => sprintf(
    946                                 '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
    947                                 /* translators: Localized version of WordPress requirements if one exists. */
    948                                 esc_url( __( 'https://wordpress.org/about/requirements/' ) ),
    949                                 __( 'Read more about what WordPress requires to run.' ),
    950                                 /* translators: accessibility text */
    951                                 __( '(opens in a new tab)' )
    952                         ),
    953                         'test'        => 'sql_server',
    954                 );
    955 
    956                 $db_dropin = file_exists( WP_CONTENT_DIR . '/db.php' );
    957 
    958                 if ( ! $this->mysql_rec_version_check ) {
    959                         $result['status'] = 'recommended';
    960 
    961                         $result['label'] = __( 'Outdated SQL server' );
    962 
    963                         $result['description'] .= sprintf(
    964                                 '<p>%s</p>',
    965                                 sprintf(
    966                                         /* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server recommended version number. */
    967                                         __( 'For optimal performance and security reasons, we recommend running %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
    968                                         ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
    969                                         $this->health_check_mysql_rec_version
    970                                 )
    971                         );
    972                 }
    973 
    974                 if ( ! $this->mysql_min_version_check ) {
    975                         $result['status'] = 'critical';
    976 
    977                         $result['label']          = __( 'Severely outdated SQL server' );
    978                         $result['badge']['label'] = __( 'Security' );
    979 
    980                         $result['description'] .= sprintf(
    981                                 '<p>%s</p>',
    982                                 sprintf(
    983                                         /* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server minimum version number. */
    984                                         __( 'WordPress requires %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
    985                                         ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
    986                                         $this->health_check_mysql_required_version
    987                                 )
    988                         );
    989                 }
    990 
    991                 if ( $db_dropin ) {
    992                         $result['description'] .= sprintf(
    993                                 '<p>%s</p>',
    994                                 wp_kses(
    995                                         sprintf(
    996                                                 /* translators: 1: The name of the drop-in. 2: The name of the database engine. */
    997                                                 __( 'You are using a %1$s drop-in which might mean that a %2$s database is not being used.' ),
    998                                                 '<code>wp-content/db.php</code>',
    999                                                 ( $this->is_mariadb ? 'MariaDB' : 'MySQL' )
    1000                                         ),
    1001                                         array(
    1002                                                 'code' => true,
    1003                                         )
    1004                                 )
    1005                         );
    1006                 }
    1007 
    1008                 return $result;
    1009         }
    1010 
    1011         /**
    1012          * Test if the database server is capable of using utf8mb4.
    1013          *
    1014          * @since 5.2.0
    1015          *
    1016          * @return array The test results.
    1017          */
    1018         public function get_test_utf8mb4_support() {
    1019                 global $wpdb;
    1020 
    1021                 $result = array(
    1022                         'label'       => __( 'UTF8MB4 is supported' ),
    1023                         'status'      => 'good',
    1024                         'badge'       => array(
    1025                                 'label' => __( 'Performance' ),
    1026                                 'color' => 'blue',
    1027                         ),
    1028                         'description' => sprintf(
    1029                                 '<p>%s</p>',
    1030                                 __( '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.' )
    1031                         ),
    1032                         'actions'     => '',
    1033                         'test'        => 'utf8mb4_support',
    1034                 );
    1035 
    1036                 if ( ! $this->is_mariadb ) {
    1037                         if ( version_compare( $this->mysql_server_version, '5.5.3', '<' ) ) {
    1038                                 $result['status'] = 'recommended';
    1039 
    1040                                 $result['label'] = __( 'utf8mb4 requires a MySQL update' );
    1041 
    1042                                 $result['description'] .= sprintf(
    1043                                         '<p>%s</p>',
    1044                                         sprintf(
    1045                                                 /* translators: %s: Version number. */
    1046                                                 __( 'WordPress&#8217; utf8mb4 support requires MySQL version %s or greater. Please contact your server administrator.' ),
    1047                                                 '5.5.3'
    1048                                         )
    1049                                 );
    1050                         } else {
    1051                                 $result['description'] .= sprintf(
    1052                                         '<p>%s</p>',
    1053                                         __( 'Your MySQL version supports utf8mb4.' )
    1054                                 );
    1055                         }
    1056                 } else { // MariaDB introduced utf8mb4 support in 5.5.0
    1057                         if ( version_compare( $this->mysql_server_version, '5.5.0', '<' ) ) {
    1058                                 $result['status'] = 'recommended';
    1059 
    1060                                 $result['label'] = __( 'utf8mb4 requires a MariaDB update' );
    1061 
    1062                                 $result['description'] .= sprintf(
    1063                                         '<p>%s</p>',
    1064                                         sprintf(
    1065                                                 /* translators: %s: Version number. */
    1066                                                 __( 'WordPress&#8217; utf8mb4 support requires MariaDB version %s or greater. Please contact your server administrator.' ),
    1067                                                 '5.5.0'
    1068                                         )
    1069                                 );
    1070                         } else {
    1071                                 $result['description'] .= sprintf(
    1072                                         '<p>%s</p>',
    1073                                         __( 'Your MariaDB version supports utf8mb4.' )
    1074                                 );
    1075                         }
    1076                 }
    1077 
    1078                 if ( $wpdb->use_mysqli ) {
    1079                         // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info
    1080                         $mysql_client_version = mysqli_get_client_info();
    1081                 } else {
    1082                         // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info
    1083                         $mysql_client_version = mysql_get_client_info();
    1084                 }
    1085 
    1086                 /*
    1087                  * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
    1088                  * mysqlnd has supported utf8mb4 since 5.0.9.
    1089                  */
    1090                 if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) {
    1091                         $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );
    1092                         if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {
    1093                                 $result['status'] = 'recommended';
    1094 
    1095                                 $result['label'] = __( 'utf8mb4 requires a newer client library' );
    1096 
    1097                                 $result['description'] .= sprintf(
    1098                                         '<p>%s</p>',
    1099                                         sprintf(
    1100                                                 /* translators: 1: Name of the library, 2: Number of version. */
    1101                                                 __( 'WordPress&#8217; utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
    1102                                                 'mysqlnd',
    1103                                                 '5.0.9'
    1104                                         )
    1105                                 );
    1106                         }
    1107                 } else {
    1108                         if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) {
    1109                                 $result['status'] = 'recommended';
    1110 
    1111                                 $result['label'] = __( 'utf8mb4 requires a newer client library' );
    1112 
    1113                                 $result['description'] .= sprintf(
    1114                                         '<p>%s</p>',
    1115                                         sprintf(
    1116                                                 /* translators: 1: Name of the library, 2: Number of version. */
    1117                                                 __( 'WordPress&#8217; utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
    1118                                                 'libmysql',
    1119                                                 '5.5.3'
    1120                                         )
    1121                                 );
    1122                         }
    1123                 }
    1124 
    1125                 return $result;
    1126         }
    1127 
    1128         /**
    1129          * Test if the site can communicate with WordPress.org.
    1130          *
    1131          * @since 5.2.0
    1132          *
    1133          * @return array The test results.
    1134          */
    1135         public function get_test_dotorg_communication() {
    1136                 $result = array(
    1137                         'label'       => __( 'Can communicate with WordPress.org' ),
    1138                         'status'      => '',
    1139                         'badge'       => array(
    1140                                 'label' => __( 'Security' ),
    1141                                 'color' => 'blue',
    1142                         ),
    1143                         'description' => sprintf(
    1144                                 '<p>%s</p>',
    1145                                 __( 'Communicating with the WordPress servers is used to check for new versions, and to both install and update WordPress core, themes or plugins.' )
    1146                         ),
    1147                         'actions'     => '',
    1148                         'test'        => 'dotorg_communication',
    1149                 );
    1150 
    1151                 $wp_dotorg = wp_remote_get(
    1152                         'https://api.wordpress.org',
    1153                         array(
    1154                                 'timeout' => 10,
    1155                         )
    1156                 );
    1157                 if ( ! is_wp_error( $wp_dotorg ) ) {
    1158                         $result['status'] = 'good';
    1159                 } else {
    1160                         $result['status'] = 'critical';
    1161 
    1162                         $result['label'] = __( 'Could not reach WordPress.org' );
    1163 
    1164                         $result['description'] .= sprintf(
    1165                                 '<p>%s</p>',
    1166                                 sprintf(
    1167                                         '<span class="error"><span class="screen-reader-text">%s</span></span> %s',
    1168                                         __( 'Error' ),
    1169                                         sprintf(
    1170                                                 /* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
    1171                                                 __( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s' ),
    1172                                                 gethostbyname( 'api.wordpress.org' ),
    1173                                                 $wp_dotorg->get_error_message()
    1174                                         )
    1175                                 )
    1176                         );
    1177 
    1178                         $result['actions'] = sprintf(
    1179                                 '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
    1180                                 /* translators: Localized Support reference. */
    1181                                 esc_url( __( 'https://wordpress.org/support' ) ),
    1182                                 __( 'Get help resolving this issue.' ),
    1183                                 /* translators: accessibility text */
    1184                                 __( '(opens in a new tab)' )
    1185                         );
    1186                 }
    1187 
    1188                 return $result;
    1189         }
    1190 
    1191         /**
    1192          * Test if debug information is enabled.
    1193          *
    1194          * When WP_DEBUG is enabled, errors and information may be disclosed to site visitors, or it may be
    1195          * logged to a publicly accessible file.
    1196          *
    1197          * Debugging is also frequently left enabled after looking for errors on a site, as site owners do
    1198          * not understand the implications of this.
    1199          *
    1200          * @since 5.2.0
    1201          *
    1202          * @return array The test results.
    1203          */
    1204         public function get_test_is_in_debug_mode() {
    1205                 $result = array(
    1206                         'label'       => __( 'Your site is not set to output debug information' ),
    1207                         'status'      => 'good',
    1208                         'badge'       => array(
    1209                                 'label' => __( 'Security' ),
    1210                                 'color' => 'blue',
    1211                         ),
    1212                         'description' => sprintf(
    1213                                 '<p>%s</p>',
    1214                                 __( '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.' )
    1215                         ),
    1216                         'actions'     => sprintf(
    1217                                 '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
    1218                                 /* translators: Documentation explaining debugging in WordPress. */
    1219                                 esc_url( __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) ),
    1220                                 __( 'Read about debugging in WordPress.' ),
    1221                                 /* translators: accessibility text */
    1222                                 __( '(opens in a new tab)' )
    1223                         ),
    1224                         'test'        => 'is_in_debug_mode',
    1225                 );
    1226 
    1227                 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
    1228                         if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
    1229                                 $result['label'] = __( 'Your site is set to log errors to a potentially public file.' );
    1230 
    1231                                 $result['status'] = 'critical';
    1232 
    1233                                 $result['description'] .= sprintf(
    1234                                         '<p>%s</p>',
    1235                                         sprintf(
    1236                                                 /* translators: %s: WP_DEBUG_LOG */
    1237                                                 __( 'The value, %s, has been added to this website&#8217;s configuration file. This means any errors on the site will be written to a file which is potentially available to normal users.' ),
    1238                                                 '<code>WP_DEBUG_LOG</code>'
    1239                                         )
    1240                                 );
    1241                         }
    1242 
    1243                         if ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) {
    1244                                 $result['label'] = __( 'Your site is set to display errors to site visitors' );
    1245 
    1246                                 $result['status'] = 'critical';
    1247 
    1248                                 $result['description'] .= sprintf(
    1249                                         '<p>%s</p>',
    1250                                         sprintf(
    1251                                                 /* translators: 1: WP_DEBUG_DISPLAY, 2: WP_DEBUG */
    1252                                                 __( 'The value, %1$s, has either been enabled by %2$s or added to your configuration file. This will make errors display on the front end of your site.' ),
    1253                                                 '<code>WP_DEBUG_DISPLAY</code>',
    1254                                                 '<code>WP_DEBUG</code>'
    1255                                         )
    1256                                 );
    1257                         }
    1258                 }
    1259 
    1260                 return $result;
    1261         }
    1262 
    1263         /**
    1264          * Test if your site is serving content over HTTPS.
    1265          *
    1266          * Many sites have varying degrees of HTTPS support, the most common of which is sites that have it
    1267          * enabled, but only if you visit the right site address.
    1268          *
    1269          * @since 5.2.0
    1270          *
    1271          * @return array The test results.
    1272          */
    1273         public function get_test_https_status() {
    1274                 $result = array(
    1275                         'label'       => __( 'Your website is using an active HTTPS connection.' ),
    1276                         'status'      => 'good',
    1277                         'badge'       => array(
    1278                                 'label' => __( 'Security' ),
    1279                                 'color' => 'blue',
    1280                         ),
    1281                         'description' => sprintf(
    1282                                 '<p>%s</p>',
    1283                                 __( '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.' )
    1284                         ),
    1285                         'actions'     => sprintf(
    1286                                 '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
    1287                                 /* translators: Documentation explaining HTTPS and why it should be used. */
    1288                                 esc_url( __( 'https://wordpress.org/support/article/why-should-i-use-https/' ) ),
    1289                                 __( 'Read more about why you should use HTTPS' ),
    1290                                 /* translators: accessibility text */
    1291                                 __( '(opens in a new tab)' )
    1292                         ),
    1293                         'test'        => 'https_status',
    1294                 );
    1295 
    1296                 if ( is_ssl() ) {
    1297                         $wp_url   = get_bloginfo( 'wpurl' );
    1298                         $site_url = get_bloginfo( 'url' );
    1299 
    1300                         if ( 'https' !== substr( $wp_url, 0, 5 ) || 'https' !== substr( $site_url, 0, 5 ) ) {
    1301                                 $result['status'] = 'recommended';
    1302 
    1303                                 $result['label'] = __( 'Only parts of your site are using HTTPS' );
    1304 
    1305                                 $result['description'] = sprintf(
    1306                                         '<p>%s</p>',
    1307                                         sprintf(
    1308                                                 /* translators: %s: URL to Settings > General to change options. */
    1309                                                 __( 'You are accessing this website using HTTPS, but your <a href="%s">WordPress Address</a> is not set up to use HTTPS by default.' ),
    1310                                                 esc_url( admin_url( 'options-general.php' ) )
    1311                                         )
    1312                                 );
    1313 
    1314                                 $result['actions'] .= sprintf(
    1315                                         '<p><a href="%s">%s</a></p>',
    1316                                         esc_url( admin_url( 'options-general.php' ) ),
    1317                                         __( 'Update your site addresses' )
    1318                                 );
    1319                         }
    1320                 } else {
    1321                         $result['status'] = 'recommended';
    1322 
    1323                         $result['label'] = __( 'Your site does not use HTTPS' );
    1324                 }
    1325 
    1326                 return $result;
    1327         }
    1328 
    1329         /**
    1330          * Check if the HTTP API can handle SSL/TLS requests.
    1331          *
    1332          * @since 5.2.0
    1333          *
    1334          * @return array The test results.
    1335          */
    1336         public function get_test_ssl_support() {
    1337                 $result = array(
    1338                         'label'       => '',
    1339                         'status'      => '',
    1340                         'badge'       => array(
    1341                                 'label' => __( 'Security' ),
    1342                                 'color' => 'blue',
    1343                         ),
    1344                         'description' => sprintf(
    1345                                 '<p>%s</p>',
    1346                                 __( 'Securely communicating between servers are needed for transactions such as fetching files, conducting sales on store sites, and much more.' )
    1347                         ),
    1348                         'actions'     => '',
    1349                         'test'        => 'ssl_support',
    1350                 );
    1351 
    1352                 $supports_https = wp_http_supports( array( 'ssl' ) );
    1353 
    1354                 if ( $supports_https ) {
    1355                         $result['status'] = 'good';
    1356 
    1357                         $result['label'] = __( 'Your site can communicate securely with other services' );
    1358                 } else {
    1359                         $result['status'] = 'critical';
    1360 
    1361                         $result['label'] = __( 'Your site is unable to communicate securely with other services' );
    1362 
    1363                         $result['description'] .= sprintf(
    1364                                 '<p>%s</p>',
    1365                                 __( 'Talk to your web host about OpenSSL support for PHP.' )
    1366                         );
    1367                 }
    1368 
    1369                 return $result;
    1370         }
    1371 
    1372         /**
    1373          * Test if scheduled events run as intended.
    1374          *
    1375          * If scheduled events are not running, this may indicate something with WP_Cron is not working as intended,
    1376          * or that there are orphaned events hanging around from older code.
    1377          *
    1378          * @since 5.2.0
    1379          *
    1380          * @return array The test results.
    1381          */
    1382         public function get_test_scheduled_events() {
    1383                 $result = array(
    1384                         'label'       => __( 'Scheduled events are running' ),
    1385                         'status'      => 'good',
    1386                         'badge'       => array(
    1387                                 'label' => __( 'Performance' ),
    1388                                 'color' => 'blue',
    1389                         ),
    1390                         'description' => sprintf(
    1391                                 '<p>%s</p>',
    1392                                 __( 'Scheduled events are what periodically looks for updates to plugins, themes and WordPress itself. 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.' )
    1393                         ),
    1394                         'actions'     => '',
    1395                         'test'        => 'scheduled_events',
    1396                 );
    1397 
    1398                 $this->wp_schedule_test_init();
    1399 
    1400                 if ( is_wp_error( $this->has_missed_cron() ) ) {
    1401                         $result['status'] = 'critical';
    1402 
    1403                         $result['label'] = __( 'It was not possible to check your scheduled events' );
    1404 
    1405                         $result['description'] = sprintf(
    1406                                 '<p>%s</p>',
    1407                                 sprintf(
    1408                                         /* translators: %s: The error message returned while from the cron scheduler. */
    1409                                         __( 'While trying to test your site&#8217;s scheduled events, the following error was returned: %s' ),
    1410                                         $this->has_missed_cron()->get_error_message()
    1411                                 )
    1412                         );
    1413                 } else {
    1414                         if ( $this->has_missed_cron() ) {
    1415                                 $result['status'] = 'recommended';
    1416 
    1417                                 $result['label'] = __( 'A scheduled event has failed' );
    1418 
    1419                                 $result['description'] = sprintf(
    1420                                         '<p>%s</p>',
    1421                                         sprintf(
    1422                                                 /* translators: %s: The name of the failed cron event. */
    1423                                                 __( '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.' ),
    1424                                                 $this->last_missed_cron
    1425                                         )
    1426                                 );
    1427                         }
    1428                 }
    1429 
    1430                 return $result;
    1431         }
    1432 
    1433         /**
    1434          * Test if WordPress can run automated background updates.
    1435          *
    1436          * Background updates in WordPress are primarily used for minor releases and security updates. It's important
    1437          * to either have these working, or be aware that they are intentionally disabled for whatever reason.
    1438          *
    1439          * @since 5.2.0
    1440          *
    1441          * @return array The test results.
    1442          */
    1443         public function get_test_background_updates() {
    1444                 $result = array(
    1445                         'label'       => __( 'Background updates are working' ),
    1446                         'status'      => 'good',
    1447                         'badge'       => array(
    1448                                 'label' => __( 'Security' ),
    1449                                 'color' => 'blue',
    1450                         ),
    1451                         'description' => sprintf(
    1452                                 '<p>%s</p>',
    1453                                 __( 'Background updates ensure that WordPress can auto-update if a security update is released for the version you are currently using.' )
    1454                         ),
    1455                         'actions'     => '',
    1456                         'test'        => 'background_updates',
    1457                 );
    1458 
    1459                 if ( ! class_exists( 'WP_Site_Health_Auto_Updates' ) ) {
    1460                         require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health-auto-updates.php' );
    1461                 }
    1462 
    1463                 // Run the auto-update tests in a separate class,
    1464                 // as there are many considerations to be made.
    1465                 $automatic_updates = new WP_Site_Health_Auto_Updates();
    1466                 $tests             = $automatic_updates->run_tests();
    1467 
    1468                 $output = '<ul>';
    1469 
    1470                 foreach ( $tests as $test ) {
    1471                         $severity_string = __( 'Passed' );
    1472 
    1473                         if ( 'fail' === $test->severity ) {
    1474                                 $result['label'] = __( 'Background updates are not working as expected' );
    1475 
    1476                                 $result['status'] = 'critical';
    1477 
    1478                                 $severity_string = __( 'Error' );
    1479                         }
    1480 
    1481                         if ( 'warning' === $test->severity && 'good' === $result['status'] ) {
    1482                                 $result['label'] = __( 'Background updates may not be working properly' );
    1483 
    1484                                 $result['status'] = 'recommended';
    1485 
    1486                                 $severity_string = __( 'Warning' );
    1487                         }
    1488 
    1489                         $output .= sprintf(
    1490                                 '<li><span class="%s"><span class="screen-reader-text">%s</span></span> %s</li>',
    1491                                 esc_attr( $test->severity ),
    1492                                 $severity_string,
    1493                                 $test->description
    1494                         );
    1495                 }
    1496 
    1497                 $output .= '</ul>';
    1498 
    1499                 if ( 'good' !== $result['status'] ) {
    1500                         $result['description'] .= sprintf(
    1501                                 '<p>%s</p>',
    1502                                 $output
    1503                         );
    1504                 }
    1505 
    1506                 return $result;
    1507         }
    1508 
    1509         /**
    1510          * Test if loopbacks work as expected.
    1511          *
    1512          * A loopback is when WordPress queries itself, for example to start a new WP_Cron instance, or when editing a
    1513          * plugin or theme. This has shown itself to be a recurring issue as code can very easily break this interaction.
    1514          *
    1515          * @since 5.2.0
    1516          *
    1517          * @return array The test results.
    1518          */
    1519         public function get_test_loopback_requests() {
    1520                 $result = array(
    1521                         'label'       => __( 'Your site can perform loopback requests' ),
    1522                         'status'      => 'good',
    1523                         'badge'       => array(
    1524                                 'label' => __( 'Performance' ),
    1525                                 'color' => 'blue',
    1526                         ),
    1527                         'description' => sprintf(
    1528                                 '<p>%s</p>',
    1529                                 __( '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.' )
    1530                         ),
    1531                         'actions'     => '',
    1532                         'test'        => 'loopback_requests',
    1533                 );
    1534 
    1535                 $check_loopback = $this->can_perform_loopback();
    1536 
    1537                 $result['status'] = $check_loopback->status;
    1538 
    1539                 if ( 'good' !== $check_loopback->status ) {
    1540                         $result['label'] = __( 'Your site could not complete a loopback request' );
    1541 
    1542                         $result['description'] .= sprintf(
    1543                                 '<p>%s</p>',
    1544                                 $check_loopback->message
    1545                         );
    1546                 }
    1547 
    1548                 return $result;
    1549         }
    1550 
    1551         /**
    1552          * Test if HTTP requests are blocked.
    1553          *
    1554          * It's possible to block all outgoing communication (with the possibility of whitelisting hosts) via the
    1555          * HTTP API. This may create problems for users as many features are running as services these days.
    1556          *
    1557          * @since 5.2.0
    1558          *
    1559          * @return array The test results.
    1560          */
    1561         public function get_test_http_requests() {
    1562                 $result = array(
    1563                         'label'       => __( 'HTTP requests seem to be working as expected' ),
    1564                         'status'      => 'good',
    1565                         'badge'       => array(
    1566                                 'label' => __( 'Performance' ),
    1567                                 'color' => 'blue',
    1568                         ),
    1569                         'description' => sprintf(
    1570                                 '<p>%s</p>',
    1571                                 __( '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.' )
    1572                         ),
    1573                         'actions'     => '',
    1574                         'test'        => 'http_requests',
    1575                 );
    1576 
    1577                 $blocked = false;
    1578                 $hosts   = array();
    1579 
    1580                 if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) ) {
    1581                         $blocked = true;
    1582                 }
    1583 
    1584                 if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
    1585                         $hosts = explode( ',', WP_ACCESSIBLE_HOSTS );
    1586                 }
    1587 
    1588                 if ( $blocked && 0 === sizeof( $hosts ) ) {
    1589                         $result['status'] = 'critical';
    1590 
    1591                         $result['label'] = __( 'HTTP requests are blocked' );
    1592 
    1593                         $result['description'] .= sprintf(
    1594                                 '<p>%s</p>',
    1595                                 sprintf(
    1596                                         /* translators: %s: Name of the constant used. */
    1597                                         __( 'HTTP requests have been blocked by the %s constant, with no allowed hosts.' ),
    1598                                         '<code>WP_HTTP_BLOCK_EXTERNAL</code>'
    1599                                 )
    1600                         );
    1601                 }
    1602 
    1603                 if ( $blocked && 0 < sizeof( $hosts ) ) {
    1604                         $result['status'] = 'recommended';
    1605 
    1606                         $result['label'] = __( 'HTTP requests are partially blocked' );
    1607 
    1608                         $result['description'] .= sprintf(
    1609                                 '<p>%s</p>',
    1610                                 sprintf(
    1611                                         /* translators: 1: Name of the constant used. 2: List of hostnames whitelisted. */
    1612                                         __( 'HTTP requests have been blocked by the %1$s constant, with some hosts whitelisted: %2$s.' ),
    1613                                         '<code>WP_HTTP_BLOCK_EXTERNAL</code>',
    1614                                         implode( ',', $hosts )
    1615                                 )
    1616                         );
    1617                 }
    1618 
    1619                 return $result;
    1620         }
    1621 
    1622         /**
    1623          * Test if the REST API is accessible.
    1624          *
    1625          * Various security measures may block the REST API from working, or it may have been disabled in general.
    1626          * This is required for the new block editor to work, so we explicitly test for this.
    1627          *
    1628          * @since 5.2.0
    1629          *
    1630          * @return array The test results.
    1631          */
    1632         public function get_test_rest_availability() {
    1633                 $result = array(
    1634                         'label'       => __( 'The REST API is available' ),
    1635                         'status'      => 'good',
    1636                         'badge'       => array(
    1637                                 'label' => __( 'Performance' ),
    1638                                 'color' => 'blue',
    1639                         ),
    1640                         'description' => sprintf(
    1641                                 '<p>%s</p>',
    1642                                 __( '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.' )
    1643                         ),
    1644                         'actions'     => '',
    1645                         'test'        => 'rest_availability',
    1646                 );
    1647 
    1648                 $cookies = wp_unslash( $_COOKIE );
    1649                 $timeout = 10;
    1650                 $headers = array(
    1651                         'Cache-Control' => 'no-cache',
    1652                         'X-WP-Nonce'    => wp_create_nonce( 'wp_rest' ),
    1653                 );
    1654 
    1655                 // Include Basic auth in loopback requests.
    1656                 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
    1657                         $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
    1658                 }
    1659 
    1660                 $url = rest_url( 'wp/v2/types/post' );
    1661 
    1662                 // The context for this is editing with the new block editor.
    1663                 $url = add_query_arg(
    1664                         array(
    1665                                 'context' => 'edit',
    1666                         ),
    1667                         $url
    1668                 );
    1669 
    1670                 $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
    1671 
    1672                 if ( is_wp_error( $r ) ) {
    1673                         $result['status'] = 'critical';
    1674 
    1675                         $result['label'] = __( 'The REST API encountered an error' );
    1676 
    1677                         $result['description'] .= sprintf(
    1678                                 '<p>%s</p>',
    1679                                 sprintf(
    1680                                         '%s<br>%s',
    1681                                         __( 'The REST API request failed due to an error.' ),
    1682                                         sprintf(
    1683                                                 /* translators: 1: The HTTP response code. 2: The error message returned. */
    1684                                                 __( 'Error: [%1$s] %2$s' ),
    1685                                                 wp_remote_retrieve_response_code( $r ),
    1686                                                 $r->get_error_message()
    1687                                         )
    1688                                 )
    1689                         );
    1690                 } elseif ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
    1691                         $result['status'] = 'recommended';
    1692 
    1693                         $result['label'] = __( 'The REST API encountered an unexpected result' );
    1694 
    1695                         $result['description'] .= sprintf(
    1696                                 '<p>%s</p>',
    1697                                 sprintf(
    1698                                         /* translators: 1: The HTTP response code returned. 2: The error message returned. */
    1699                                         __( 'The REST API call gave the following unexpected result: (%1$d) %2$s.' ),
    1700                                         wp_remote_retrieve_response_code( $r ),
    1701                                         wp_remote_retrieve_body( $r )
    1702                                 )
    1703                         );
    1704                 } else {
    1705                         $json = json_decode( wp_remote_retrieve_body( $r ), true );
    1706 
    1707                         if ( false !== $json && ! isset( $json['capabilities'] ) ) {
    1708                                 $result['status'] = 'recommended';
    1709 
    1710                                 $result['label'] = __( 'The REST API did not behave correctly' );
    1711 
    1712                                 $result['description'] .= sprintf(
    1713                                         '<p>%s</p>',
    1714                                         sprintf(
    1715                                                 /* translators: %s: the name of the query parameter being tested. */
    1716                                                 __( 'The REST API did not process the %s query parameter correctly.' ),
    1717                                                 '<code>context</code>'
    1718                                         )
    1719                                 );
    1720                         }
    1721                 }
    1722 
    1723                 return $result;
    1724         }
    1725 
    1726         /**
    1727          * Return a set of tests that belong to the site status page.
    1728          *
    1729          * Each site status test is defined here, they may be `direct` tests, that run on page load, or `async` tests
    1730          * which will run later down the line via JavaScript calls to improve page performance and hopefully also user
    1731          * experiences.
    1732          *
    1733          * @since 5.2.0
    1734          *
    1735          * @return array The list of tests to run.
    1736          */
    1737         public static function get_tests() {
    1738                 $tests = array(
    1739                         'direct' => array(
    1740                                 'wordpress_version' => array(
    1741                                         'label' => __( 'WordPress Version' ),
    1742                                         'test'  => 'wordpress_version',
    1743                                 ),
    1744                                 'plugin_version'    => array(
    1745                                         'label' => __( 'Plugin Versions' ),
    1746                                         'test'  => 'plugin_version',
    1747                                 ),
    1748                                 'theme_version'     => array(
    1749                                         'label' => __( 'Theme Versions' ),
    1750                                         'test'  => 'theme_version',
    1751                                 ),
    1752                                 'php_version'       => array(
    1753                                         'label' => __( 'PHP Version' ),
    1754                                         'test'  => 'php_version',
    1755                                 ),
    1756                                 'sql_server'        => array(
    1757                                         'label' => __( 'Database Server version' ),
    1758                                         'test'  => 'sql_server',
    1759                                 ),
    1760                                 'php_extensions'    => array(
    1761                                         'label' => __( 'PHP Extensions' ),
    1762                                         'test'  => 'php_extensions',
    1763                                 ),
    1764                                 'utf8mb4_support'   => array(
    1765                                         'label' => __( 'MySQL utf8mb4 support' ),
    1766                                         'test'  => 'utf8mb4_support',
    1767                                 ),
    1768                                 'https_status'      => array(
    1769                                         'label' => __( 'HTTPS status' ),
    1770                                         'test'  => 'https_status',
    1771                                 ),
    1772                                 'ssl_support'       => array(
    1773                                         'label' => __( 'Secure communication' ),
    1774                                         'test'  => 'ssl_support',
    1775                                 ),
    1776                                 'scheduled_events'  => array(
    1777                                         'label' => __( 'Scheduled events' ),
    1778                                         'test'  => 'scheduled_events',
    1779                                 ),
    1780                                 'http_requests'     => array(
    1781                                         'label' => __( 'HTTP Requests' ),
    1782                                         'test'  => 'http_requests',
    1783                                 ),
    1784                                 'debug_enabled'     => array(
    1785                                         'label' => __( 'Debugging enabled' ),
    1786                                         'test'  => 'is_in_debug_mode',
    1787                                 ),
    1788                         ),
    1789                         'async'  => array(
    1790                                 'dotorg_communication' => array(
    1791                                         'label' => __( 'Communication with WordPress.org' ),
    1792                                         'test'  => 'dotorg_communication',
    1793                                 ),
    1794                                 'background_updates'   => array(
    1795                                         'label' => __( 'Background updates' ),
    1796                                         'test'  => 'background_updates',
    1797                                 ),
    1798                                 'loopback_requests'    => array(
    1799                                         'label' => __( 'Loopback request' ),
    1800                                         'test'  => 'loopback_requests',
    1801                                 ),
    1802                         ),
    1803                 );
    1804 
    1805                 // Conditionally include REST rules if the function for it exists.
    1806                 if ( function_exists( 'rest_url' ) ) {
    1807                         $tests['direct']['rest_availability'] = array(
    1808                                 'label' => __( 'REST API availability' ),
    1809                                 'test'  => 'rest_availability',
    1810                         );
    1811                 }
    1812 
    1813                 /**
    1814                  * Add or modify which site status tests are run on a site.
    1815                  *
    1816                  * The site health is determined by a set of tests based on best practices from
    1817                  * both the WordPress Hosting Team, but also web standards in general.
    1818                  *
    1819                  * Some sites may not have the same requirements, for example the automatic update
    1820                  * checks may be handled by a host, and are therefore disabled in core.
    1821                  * Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example.
    1822                  *
    1823                  * Tests may be added either as direct, or asynchronous ones. Any test that may require some time
    1824                  * to complete should run asynchronously, to avoid extended loading periods within wp-admin.
    1825                  *
    1826                  * @since 5.2.0
    1827                  *
    1828                  * @param array $test_type {
    1829                  *     An associative array, where the `$test_type` is either `direct` or
    1830                  *     `async`, to declare if the test should run via AJAX calls after page load.
    1831                  *
    1832                  *     @type array $identifier {
    1833                  *         `$identifier` should be a unique identifier for the test that should run.
    1834                  *         Plugins and themes are encouraged to prefix test identifiers with their slug
    1835                  *         to avoid any collisions between tests.
    1836                  *
    1837                  *         @type string $label A friendly label for your test to identify it by.
    1838                  *         @type mixed  $test  A callable to perform a direct test, or a string AJAX action to be called
    1839                  *                             to perform an async test.
    1840                  *     }
    1841                  * }
    1842                  */
    1843                 $tests = apply_filters( 'site_status_tests', $tests );
    1844 
    1845                 return $tests;
    1846         }
    1847 
    1848         /**
    1849          * Add a class to the body HTML tag.
    1850          *
    1851          * Filters the body class string for admin pages and adds our own class for easier styling.
    1852          *
    1853          * @since 5.2.0
    1854          *
    1855          * @param string $body_class The body class string.
    1856          * @return string The modified body class string.
    1857          */
    1858         public function admin_body_class( $body_class ) {
    1859                 $body_class .= ' site-health';
    1860 
    1861                 return $body_class;
    1862         }
    1863 
    1864         /**
    1865          * Initiate the WP_Cron schedule test cases.
    1866          *
    1867          * @since 5.2.0
    1868          */
    1869         private function wp_schedule_test_init() {
    1870                 $this->schedules = wp_get_schedules();
    1871                 $this->get_cron_tasks();
    1872         }
    1873 
    1874         /**
    1875          * Populate our list of cron events and store them to a class-wide variable.
    1876          *
    1877          * @since 5.2.0
    1878          */
    1879         private function get_cron_tasks() {
    1880                 $cron_tasks = _get_cron_array();
    1881 
    1882                 if ( empty( $cron_tasks ) ) {
    1883                         $this->crons = new WP_Error( 'no_tasks', __( 'No scheduled events exist on this site.' ) );
    1884                         return;
    1885                 }
    1886 
    1887                 $this->crons = array();
    1888 
    1889                 foreach ( $cron_tasks as $time => $cron ) {
    1890                         foreach ( $cron as $hook => $dings ) {
    1891                                 foreach ( $dings as $sig => $data ) {
    1892 
    1893                                         $this->crons[ "$hook-$sig-$time" ] = (object) array(
    1894                                                 'hook'     => $hook,
    1895                                                 'time'     => $time,
    1896                                                 'sig'      => $sig,
    1897                                                 'args'     => $data['args'],
    1898                                                 'schedule' => $data['schedule'],
    1899                                                 'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
    1900                                         );
    1901 
    1902                                 }
    1903                         }
    1904                 }
    1905         }
    1906 
    1907         /**
    1908          * Check if any scheduled tasks have been missed.
    1909          *
    1910          * Returns a boolean value of `true` if a scheduled task has been missed and ends processing. If the list of
    1911          * crons is an instance of WP_Error, return the instance instead of a boolean value.
    1912          *
    1913          * @since 5.2.0
    1914          *
    1915          * @return bool|WP_Error true if a cron was missed, false if it wasn't. WP_Error if the cron is set to that.
    1916          */
    1917         public function has_missed_cron() {
    1918                 if ( is_wp_error( $this->crons ) ) {
    1919                         return $this->crons;
    1920                 }
    1921 
    1922                 foreach ( $this->crons as $id => $cron ) {
    1923                         if ( ( $cron->time - time() ) < 0 ) {
    1924                                 $this->last_missed_cron = $cron->hook;
    1925                                 return true;
    1926                         }
    1927                 }
    1928 
    1929                 return false;
    1930         }
    1931 
    1932         /**
    1933          * Run a loopback test on our site.
    1934          *
    1935          * Loopbacks are what WordPress uses to communicate with itself to start up WP_Cron, scheduled posts,
    1936          * make sure plugin or theme edits don't cause site failures and similar.
    1937          *
    1938          * @since 5.2.0
    1939          *
    1940          * @return object The test results.
    1941          */
    1942         function can_perform_loopback() {
    1943                 $cookies = wp_unslash( $_COOKIE );
    1944                 $timeout = 10;
    1945                 $headers = array(
    1946                         'Cache-Control' => 'no-cache',
    1947                 );
    1948 
    1949                 // Include Basic auth in loopback requests.
    1950                 if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
    1951                         $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
    1952                 }
    1953 
    1954                 $url = admin_url();
    1955 
    1956                 $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
    1957 
    1958                 if ( is_wp_error( $r ) ) {
    1959                         return (object) array(
    1960                                 'status'  => 'critical',
    1961                                 'message' => sprintf(
    1962                                         '%s<br>%s',
    1963                                         __( 'The loopback request to your site failed, this means features relying on them are not currently working as expected.' ),
    1964                                         sprintf(
    1965                                                 // translators: 1: The HTTP response code. 2: The error message returned.
    1966                                                 __( 'Error: [%1$s] %2$s' ),
    1967                                                 wp_remote_retrieve_response_code( $r ),
    1968                                                 $r->get_error_message()
    1969                                         )
    1970                                 ),
    1971                         );
    1972                 }
    1973 
    1974                 if ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
    1975                         return (object) array(
    1976                                 'status'  => 'recommended',
    1977                                 'message' => sprintf(
    1978                                         // translators: %d: The HTTP response code returned.
    1979                                         __( '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.' ),
    1980                                         wp_remote_retrieve_response_code( $r )
    1981                                 ),
    1982                         );
    1983                 }
    1984 
    1985                 return (object) array(
    1986                         'status'  => 'good',
    1987                         'message' => __( 'The loopback request to your site completed successfully.' ),
    1988                 );
    1989         }
    1990 }
     1Index: class-wp-site-health.php
     2===================================================================
     3--- class-wp-site-health.php    (revision 45302)
     4+++ class-wp-site-health.php    (working copy)
     5@@ -1,1990 +0,0 @@
     6-<?php
     7-/**
     8- * Class for looking up a site's health based on a user's WordPress environment.
     9- *
     10- * @package WordPress
     11- * @subpackage Site_Health
     12- * @since 5.2.0
     13- */
     14-
     15-class WP_Site_Health {
     16-       private $mysql_min_version_check;
     17-       private $mysql_rec_version_check;
     18-
     19-       public  $is_mariadb                          = false;
     20-       private $mysql_server_version                = '';
     21-       private $health_check_mysql_required_version = '5.5';
     22-       private $health_check_mysql_rec_version      = '';
     23-
     24-       public $schedules;
     25-       public $crons;
     26-       public $last_missed_cron = null;
     27-
     28-       /**
     29-        * WP_Site_Health constructor.
     30-        *
     31-        * @since 5.2.0
     32-        */
     33-       public function __construct() {
     34-               $this->prepare_sql_data();
     35-
     36-               add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
     37-
     38-               add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
     39-       }
     40-
     41-       /**
     42-        * Enqueues the site health scripts.
     43-        *
     44-        * @since 5.2.0
     45-        */
     46-       public function enqueue_scripts() {
     47-               $screen = get_current_screen();
     48-               if ( 'site-health' !== $screen->id ) {
     49-                       return;
     50-               }
     51-
     52-               $health_check_js_variables = array(
     53-                       'screen'      => $screen->id,
     54-                       'nonce'       => array(
     55-                               'site_status'        => wp_create_nonce( 'health-check-site-status' ),
     56-                               'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ),
     57-                       ),
     58-                       'site_status' => array(
     59-                               'direct' => array(),
     60-                               'async'  => array(),
     61-                               'issues' => array(
     62-                                       'good'        => 0,
     63-                                       'recommended' => 0,
     64-                                       'critical'    => 0,
     65-                               ),
     66-                       ),
     67-               );
     68-
     69-               $issue_counts = get_transient( 'health-check-site-status-result' );
     70-
     71-               if ( false !== $issue_counts ) {
     72-                       $issue_counts = json_decode( $issue_counts );
     73-
     74-                       $health_check_js_variables['site_status']['issues'] = $issue_counts;
     75-               }
     76-
     77-               if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
     78-                       $tests = WP_Site_Health::get_tests();
     79-
     80-                       // Don't run https test on localhost
     81-                       if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
     82-                               unset( $tests['direct']['https_status'] );
     83-                       }
     84-
     85-                       foreach ( $tests['direct'] as $test ) {
     86-                               if ( is_string( $test['test'] ) ) {
     87-                                       $test_function = sprintf(
     88-                                               'get_test_%s',
     89-                                               $test['test']
     90-                                       );
     91-
     92-                                       if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
     93-                                               $health_check_js_variables['site_status']['direct'][] = call_user_func( array( $this, $test_function ) );
     94-                                               continue;
     95-                                       }
     96-                               }
     97-
     98-                               if ( is_callable( $test['test'] ) ) {
     99-                                       $health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] );
     100-                               }
     101-                       }
     102-
     103-                       foreach ( $tests['async'] as $test ) {
     104-                               if ( is_string( $test['test'] ) ) {
     105-                                       $health_check_js_variables['site_status']['async'][] = array(
     106-                                               'test'      => $test['test'],
     107-                                               'completed' => false,
     108-                                       );
     109-                               }
     110-                       }
     111-               }
     112-
     113-               wp_localize_script( 'site-health', 'SiteHealth', $health_check_js_variables );
     114-       }
     115-
     116-       /**
     117-        * Run the SQL version checks.
     118-        *
     119-        * These values are used in later tests, but the part of preparing them is more easily managed early
     120-        * in the class for ease of access and discovery.
     121-        *
     122-        * @since 5.2.0
     123-        *
     124-        * @global wpdb $wpdb WordPress database abstraction object.
     125-        */
     126-       private function prepare_sql_data() {
     127-               global $wpdb;
     128-
     129-               if ( method_exists( $wpdb, 'db_version' ) ) {
     130-                       if ( $wpdb->use_mysqli ) {
     131-                               // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info
     132-                               $mysql_server_type = mysqli_get_server_info( $wpdb->dbh );
     133-                       } else {
     134-                               // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info
     135-                               $mysql_server_type = mysql_get_server_info( $wpdb->dbh );
     136-                       }
     137-
     138-                       $this->mysql_server_version = $wpdb->get_var( 'SELECT VERSION()' );
     139-               }
     140-
     141-               $this->health_check_mysql_rec_version = '5.6';
     142-
     143-               if ( stristr( $mysql_server_type, 'mariadb' ) ) {
     144-                       $this->is_mariadb                     = true;
     145-                       $this->health_check_mysql_rec_version = '10.0';
     146-               }
     147-
     148-               $this->mysql_min_version_check = version_compare( '5.5', $this->mysql_server_version, '<=' );
     149-               $this->mysql_rec_version_check = version_compare( $this->health_check_mysql_rec_version, $this->mysql_server_version, '<=' );
     150-       }
     151-
     152-       /**
     153-        * Test if `wp_version_check` is blocked.
     154-        *
     155-        * It's possible to block updates with the `wp_version_check` filter, but this can't be checked during an
     156-        * AJAX call, as the filter is never introduced then.
     157-        *
     158-        * This filter overrides a normal page request if it's made by an admin through the AJAX call with the
     159-        * right query argument to check for this.
     160-        *
     161-        * @since 5.2.0
     162-        */
     163-       public function check_wp_version_check_exists() {
     164-               if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'update_core' ) || ! isset( $_GET['health-check-test-wp_version_check'] ) ) {
     165-                       return;
     166-               }
     167-
     168-               echo ( has_filter( 'wp_version_check', 'wp_version_check' ) ? 'yes' : 'no' );
     169-
     170-               die();
     171-       }
     172-
     173-       /**
     174-        * Tests for WordPress version and outputs it.
     175-        *
     176-        * Gives various results depending on what kind of updates are available, if any, to encourage the
     177-        * user to install security updates as a priority.
     178-        *
     179-        * @since 5.2.0
     180-        *
     181-        * @return array The test result.
     182-        */
     183-       public function get_test_wordpress_version() {
     184-               $result = array(
     185-                       'label'       => '',
     186-                       'status'      => '',
     187-                       'badge'       => array(
     188-                               'label' => __( 'Performance' ),
     189-                               'color' => 'blue',
     190-                       ),
     191-                       'description' => '',
     192-                       'actions'     => '',
     193-                       'test'        => 'wordpress_version',
     194-               );
     195-
     196-               $core_current_version = get_bloginfo( 'version' );
     197-               $core_updates         = get_core_updates();
     198-
     199-               if ( ! is_array( $core_updates ) ) {
     200-                       $result['status'] = 'recommended';
     201-
     202-                       $result['label'] = sprintf(
     203-                               // translators: %s: Your current version of WordPress.
     204-                               __( 'WordPress version %s' ),
     205-                               $core_current_version
     206-                       );
     207-
     208-                       $result['description'] = sprintf(
     209-                               '<p>%s</p>',
     210-                               __( 'We were unable to check if any new versions of WordPress are available.' )
     211-                       );
     212-
     213-                       $result['actions'] = sprintf(
     214-                               '<a href="%s">%s</a>',
     215-                               esc_url( admin_url( 'update-core.php?force-check=1' ) ),
     216-                               __( 'Check for updates manually' )
     217-                       );
     218-               } else {
     219-                       foreach ( $core_updates as $core => $update ) {
     220-                               if ( 'upgrade' === $update->response ) {
     221-                                       $current_version = explode( '.', $core_current_version );
     222-                                       $new_version     = explode( '.', $update->version );
     223-
     224-                                       $current_major = $current_version[0] . '.' . $current_version[1];
     225-                                       $new_major     = $new_version[0] . '.' . $new_version[1];
     226-
     227-                                       $result['label'] = sprintf(
     228-                                               // translators: %s: The latest version of WordPress available.
     229-                                               __( 'WordPress update available (%s)' ),
     230-                                               $update->version
     231-                                       );
     232-
     233-                                       $result['actions'] = sprintf(
     234-                                               '<a href="%s">%s</a>',
     235-                                               esc_url( admin_url( 'update-core.php' ) ),
     236-                                               __( 'Install the latest version of WordPress' )
     237-                                       );
     238-
     239-                                       if ( $current_major !== $new_major ) {
     240-                                               // This is a major version mismatch.
     241-                                               $result['status']      = 'recommended';
     242-                                               $result['description'] = sprintf(
     243-                                                       '<p>%s</p>',
     244-                                                       __( 'A new version of WordPress is available.' )
     245-                                               );
     246-                                       } else {
     247-                                               // This is a minor version, sometimes considered more critical.
     248-                                               $result['status']         = 'critical';
     249-                                               $result['badge']['label'] = __( 'Security' );
     250-                                               $result['description']    = sprintf(
     251-                                                       '<p>%s</p>',
     252-                                                       __( 'A new minor update is available for your site. Because minor updates often address security, it&#8217;s important to install them.' )
     253-                                               );
     254-                                       }
     255-                               } else {
     256-                                       $result['status'] = 'good';
     257-                                       $result['label']  = sprintf(
     258-                                               // translators: %s: The current version of WordPress installed on this site.
     259-                                               __( 'Your WordPress version is up to date (%s)' ),
     260-                                               $core_current_version
     261-                                       );
     262-
     263-                                       $result['description'] = sprintf(
     264-                                               '<p>%s</p>',
     265-                                               __( 'You are currently running the latest version of WordPress available, keep it up!' )
     266-                                       );
     267-                               }
     268-                       }
     269-               }
     270-
     271-               return $result;
     272-       }
     273-
     274-       /**
     275-        * Test if plugins are outdated, or unnecessary.
     276-        *
     277-        * The tests checks if your plugins are up to date, and encourages you to remove any that are not in use.
     278-        *
     279-        * @since 5.2.0
     280-        *
     281-        * @return array The test result.
     282-        */
     283-       public function get_test_plugin_version() {
     284-               $result = array(
     285-                       'label'       => __( 'Your plugins are up to date' ),
     286-                       'status'      => 'good',
     287-                       'badge'       => array(
     288-                               'label' => __( 'Security' ),
     289-                               'color' => 'blue',
     290-                       ),
     291-                       'description' => sprintf(
     292-                               '<p>%s</p>',
     293-                               __( 'Plugins extend your site&#8217;s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it&#8217;s vital to keep them up to date.' )
     294-                       ),
     295-                       'actions'     => sprintf(
     296-                               '<p><a href="%s">%s</a></p>',
     297-                               esc_url( admin_url( 'plugins.php' ) ),
     298-                               __( 'Manage your plugins' )
     299-                       ),
     300-                       'test'        => 'plugin_version',
     301-               );
     302-
     303-               $plugins        = get_plugins();
     304-               $plugin_updates = get_plugin_updates();
     305-
     306-               $plugins_have_updates = false;
     307-               $plugins_active       = 0;
     308-               $plugins_total        = 0;
     309-               $plugins_need_update  = 0;
     310-
     311-               // Loop over the available plugins and check their versions and active state.
     312-               foreach ( $plugins as $plugin_path => $plugin ) {
     313-                       $plugins_total++;
     314-
     315-                       if ( is_plugin_active( $plugin_path ) ) {
     316-                               $plugins_active++;
     317-                       }
     318-
     319-                       $plugin_version = $plugin['Version'];
     320-
     321-                       if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
     322-                               $plugins_need_update++;
     323-                               $plugins_have_updates = true;
     324-                       }
     325-               }
     326-
     327-               // Add a notice if there are outdated plugins.
     328-               if ( $plugins_need_update > 0 ) {
     329-                       $result['status'] = 'critical';
     330-
     331-                       $result['label'] = __( 'You have plugins waiting to be updated' );
     332-
     333-                       $result['description'] .= sprintf(
     334-                               '<p>%s</p>',
     335-                               sprintf(
     336-                                       /* translators: %d: The number of outdated plugins. */
     337-                                       _n(
     338-                                               'Your site has %d plugin waiting to be updated.',
     339-                                               'Your site has %d plugins waiting to be updated.',
     340-                                               $plugins_need_update
     341-                                       ),
     342-                                       $plugins_need_update
     343-                               )
     344-                       );
     345-
     346-                       $result['actions'] .= sprintf(
     347-                               '<p><a href="%s">%s</a></p>',
     348-                               esc_url( admin_url( 'plugins.php?plugin_status=upgrade' ) ),
     349-                               __( 'Update your plugins' )
     350-                       );
     351-               } else {
     352-                       if ( 1 === $plugins_active ) {
     353-                               $result['description'] .= sprintf(
     354-                                       '<p>%s</p>',
     355-                                       __( 'Your site has 1 active plugin, and it is up to date.' )
     356-                               );
     357-                       } else {
     358-                               $result['description'] .= sprintf(
     359-                                       '<p>%s</p>',
     360-                                       sprintf(
     361-                                               /* translators: %d: The number of active plugins. */
     362-                                               _n(
     363-                                                       'Your site has %d active plugin, and they are all up to date.',
     364-                                                       'Your site has %d active plugins, and they are all up to date.',
     365-                                                       $plugins_active
     366-                                               ),
     367-                                               $plugins_active
     368-                                       )
     369-                               );
     370-                       }
     371-               }
     372-
     373-               // Check if there are inactive plugins.
     374-               if ( $plugins_total > $plugins_active && ! is_multisite() ) {
     375-                       $unused_plugins = $plugins_total - $plugins_active;
     376-
     377-                       $result['status'] = 'recommended';
     378-
     379-                       $result['label'] = __( 'You should remove inactive plugins' );
     380-
     381-                       $result['description'] .= sprintf(
     382-                               '<p>%s %s</p>',
     383-                               sprintf(
     384-                                       /* translators: %d: The number of inactive plugins. */
     385-                                       _n(
     386-                                               'Your site has %d inactive plugin.',
     387-                                               'Your site has %d inactive plugins.',
     388-                                               $unused_plugins
     389-                                       ),
     390-                                       $unused_plugins
     391-                               ),
     392-                               __( 'Inactive plugins are tempting targets for attackers. If you&#8217;re not going to use a plugin, we recommend you remove it.' )
     393-                       );
     394-
     395-                       $result['actions'] .= sprintf(
     396-                               '<p><a href="%s">%s</a></p>',
     397-                               esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
     398-                               __( 'Manage inactive plugins' )
     399-                       );
     400-               }
     401-
     402-               return $result;
     403-       }
     404-
     405-       /**
     406-        * Test if themes are outdated, or unnecessary.
     407-        *
     408-        * The tests checks if your site has a default theme (to fall back on if there is a need), if your themes
     409-        * are up to date and, finally, encourages you to remove any themes that are not needed.
     410-        *
     411-        * @since 5.2.0
     412-        *
     413-        * @return array The test results.
     414-        */
     415-       public function get_test_theme_version() {
     416-               $result = array(
     417-                       'label'       => __( 'Your themes are up to date' ),
     418-                       'status'      => 'good',
     419-                       'badge'       => array(
     420-                               'label' => __( 'Security' ),
     421-                               'color' => 'blue',
     422-                       ),
     423-                       'description' => sprintf(
     424-                               '<p>%s</p>',
     425-                               __( 'Themes add your site&#8217;s look and feel. It&#8217;s important to keep them up to date, to stay consistent with your brand and keep your site secure.' )
     426-                       ),
     427-                       'actions'     => sprintf(
     428-                               '<p><a href="%s">%s</a></p>',
     429-                               esc_url( admin_url( 'themes.php' ) ),
     430-                               __( 'Manage your themes' )
     431-                       ),
     432-                       'test'        => 'theme_version',
     433-               );
     434-
     435-               $theme_updates = get_theme_updates();
     436-
     437-               $themes_total        = 0;
     438-               $themes_need_updates = 0;
     439-               $themes_inactive     = 0;
     440-
     441-               // This value is changed during processing to determine how many themes are considered a reasonable amount.
     442-               $allowed_theme_count = 1;
     443-
     444-               $has_default_theme   = false;
     445-               $has_unused_themes   = false;
     446-               $show_unused_themes  = true;
     447-               $using_default_theme = false;
     448-
     449-               // Populate a list of all themes available in the install.
     450-               $all_themes   = wp_get_themes();
     451-               $active_theme = wp_get_theme();
     452-
     453-               foreach ( $all_themes as $theme_slug => $theme ) {
     454-                       $themes_total++;
     455-
     456-                       if ( WP_DEFAULT_THEME === $theme_slug ) {
     457-                               $has_default_theme = true;
     458-
     459-                               if ( get_stylesheet() === $theme_slug ) {
     460-                                       $using_default_theme = true;
     461-                               }
     462-                       }
     463-
     464-                       if ( array_key_exists( $theme_slug, $theme_updates ) ) {
     465-                               $themes_need_updates++;
     466-                       }
     467-               }
     468-
     469-               // If this is a child theme, increase the allowed theme count by one, to account for the parent.
     470-               if ( $active_theme->parent() ) {
     471-                       $allowed_theme_count++;
     472-
     473-                       if ( $active_theme->get_template() === WP_DEFAULT_THEME ) {
     474-                               $using_default_theme = true;
     475-                       }
     476-               }
     477-
     478-               // If there's a default theme installed and not in use, we count that as allowed as well.
     479-               if ( $has_default_theme && ! $using_default_theme ) {
     480-                       $allowed_theme_count++;
     481-               }
     482-
     483-               if ( $themes_total > $allowed_theme_count ) {
     484-                       $has_unused_themes = true;
     485-                       $themes_inactive   = ( $themes_total - $allowed_theme_count );
     486-               }
     487-
     488-               // Check if any themes need to be updated.
     489-               if ( $themes_need_updates > 0 ) {
     490-                       $result['status'] = 'critical';
     491-
     492-                       $result['label'] = __( 'You have themes waiting to be updated' );
     493-
     494-                       $result['description'] .= sprintf(
     495-                               '<p>%s</p>',
     496-                               sprintf(
     497-                                       /* translators: %d: The number of outdated themes. */
     498-                                       _n(
     499-                                               'Your site has %d theme waiting to be updated.',
     500-                                               'Your site has %d themes waiting to be updated.',
     501-                                               $themes_need_updates
     502-                                       ),
     503-                                       $themes_need_updates
     504-                               )
     505-                       );
     506-               } else {
     507-                       // Give positive feedback about the site being good about keeping things up to date.
     508-                       if ( 1 === $themes_total ) {
     509-                               $result['description'] .= sprintf(
     510-                                       '<p>%s</p>',
     511-                                       __( 'Your site has 1 installed theme, and it is up to date.' )
     512-                               );
     513-                       } else {
     514-                               $result['description'] .= sprintf(
     515-                                       '<p>%s</p>',
     516-                                       sprintf(
     517-                                               /* translators: %d: The number of themes. */
     518-                                               _n(
     519-                                                       'Your site has %d installed theme, and they are all up to date.',
     520-                                                       'Your site has %d installed themes, and they are all up to date.',
     521-                                                       $themes_total
     522-                                               ),
     523-                                               $themes_total
     524-                                       )
     525-                               );
     526-                       }
     527-               }
     528-
     529-               if ( $has_unused_themes && $show_unused_themes && ! is_multisite() ) {
     530-
     531-                       // This is a child theme, so we want to be a bit more explicit in our messages.
     532-                       if ( $active_theme->parent() ) {
     533-                               // Recommend removing inactive themes, except a default theme, your current one, and the parent theme.
     534-                               $result['status'] = 'recommended';
     535-
     536-                               $result['label'] = __( 'You should remove inactive themes' );
     537-
     538-                               if ( $using_default_theme ) {
     539-                                       $result['description'] .= sprintf(
     540-                                               '<p>%s %s</p>',
     541-                                               sprintf(
     542-                                                       /* translators: %d: The number of inactive themes. */
     543-                                                       _n(
     544-                                                               'Your site has %d inactive theme.',
     545-                                                               'Your site has %d inactive themes.',
     546-                                                               $themes_inactive
     547-                                                       ),
     548-                                                       $themes_inactive
     549-                                               ),
     550-                                               sprintf(
     551-                                                       /* translators: 1: The currently active theme. 2: The active theme's parent theme. */
     552-                                                       __( 'To enhance your site&#8217;s security, we recommend you remove any themes you&#8217;re not using. You should keep your current theme, %1$s, and %2$s, its parent theme.' ),
     553-                                                       $active_theme->name,
     554-                                                       $active_theme->parent()->name
     555-                                               )
     556-                                       );
     557-                               } else {
     558-                                       $result['description'] .= sprintf(
     559-                                               '<p>%s %s</p>',
     560-                                               sprintf(
     561-                                                       /* translators: %d: The number of inactive themes. */
     562-                                                       _n(
     563-                                                               'Your site has %d inactive theme.',
     564-                                                               'Your site has %d inactive themes.',
     565-                                                               $themes_inactive
     566-                                                       ),
     567-                                                       $themes_inactive
     568-                                               ),
     569-                                               sprintf(
     570-                                                       /* translators: 1: The default theme for WordPress. 2: The currently active theme. 3: The active theme's parent theme. */
     571-                                                       __( 'To enhance your site&#8217;s security, we recommend you remove any themes you&#8217;re not using. You should keep %1$s, the default WordPress theme, %2$s, your current theme, and %3$s, its parent theme.' ),
     572-                                                       WP_DEFAULT_THEME,
     573-                                                       $active_theme->name,
     574-                                                       $active_theme->parent()->name
     575-                                               )
     576-                                       );
     577-                               }
     578-                       } else {
     579-                               // Recommend removing all inactive themes.
     580-                               $result['status'] = 'recommended';
     581-
     582-                               $result['label'] = __( 'You should remove inactive themes' );
     583-
     584-                               if ( $using_default_theme ) {
     585-                                       $result['description'] .= sprintf(
     586-                                               '<p>%s %s</p>',
     587-                                               sprintf(
     588-                                                       /* translators: 1: The amount of inactive themes. 2: The currently active theme. */
     589-                                                       _n(
     590-                                                               'Your site has %1$d inactive theme, other than %2$s, your active theme.',
     591-                                                               'Your site has %1$d inactive themes, other than %2$s, your active theme.',
     592-                                                               $themes_inactive
     593-                                                       ),
     594-                                                       $themes_inactive,
     595-                                                       $active_theme->name
     596-                                               ),
     597-                                               __( 'We recommend removing any unused themes to enhance your site&#8217;s security.' )
     598-                                       );
     599-                               } else {
     600-                                       $result['description'] .= sprintf(
     601-                                               '<p>%s %s</p>',
     602-                                               sprintf(
     603-                                                       /* translators: 1: The amount of inactive themes. 2: The default theme for WordPress. 3: The currently active theme. */
     604-                                                       _n(
     605-                                                               'Your site has %1$d inactive theme, other than %2$s, the default WordPress theme, and %3$s, your active theme.',
     606-                                                               'Your site has %1$d inactive themes, other than %2$s, the default WordPress theme, and %3$s, your active theme.',
     607-                                                               $themes_inactive
     608-                                                       ),
     609-                                                       $themes_inactive,
     610-                                                       WP_DEFAULT_THEME,
     611-                                                       $active_theme->name
     612-                                               ),
     613-                                               __( 'We recommend removing any unused themes to enhance your site&#8217;s security.' )
     614-                                       );
     615-                               }
     616-                       }
     617-               }
     618-
     619-               // If not default Twenty* theme exists.
     620-               if ( ! $has_default_theme ) {
     621-                       $result['status'] = 'recommended';
     622-
     623-                       $result['label'] = __( 'Have a default theme available' );
     624-
     625-                       $result['description'] .= sprintf(
     626-                               '<p>%s</p>',
     627-                               __( 'Your site does not have any default theme. Default themes are used by WordPress automatically if anything is wrong with your normal theme.' )
     628-                       );
     629-               }
     630-
     631-               return $result;
     632-       }
     633-
     634-       /**
     635-        * Test if the supplied PHP version is supported.
     636-        *
     637-        * @since 5.2.0
     638-        *
     639-        * @return array The test results.
     640-        */
     641-       public function get_test_php_version() {
     642-               $response = wp_check_php_version();
     643-
     644-               $result = array(
     645-                       'label'       => sprintf(
     646-                               // translators: %s: The current PHP version.
     647-                               __( 'PHP is up to date (%s)' ),
     648-                               PHP_VERSION
     649-                       ),
     650-                       'status'      => 'good',
     651-                       'badge'       => array(
     652-                               'label' => __( 'Performance' ),
     653-                               'color' => 'blue',
     654-                       ),
     655-                       'description' => sprintf(
     656-                               '<p>%s</p>',
     657-                               __( '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&#8217;s performance.' )
     658-                       ),
     659-                       'actions'     => sprintf(
     660-                               '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
     661-                               esc_url( wp_get_update_php_url() ),
     662-                               __( 'Learn more about updating PHP' ),
     663-                               /* translators: accessibility text */
     664-                               __( '(opens in a new tab)' )
     665-                       ),
     666-                       'test'        => 'php_version',
     667-               );
     668-
     669-               // PHP is up to date.
     670-               if ( ! $response || version_compare( PHP_VERSION, $response['recommended_version'], '>=' ) ) {
     671-                       return $result;
     672-               }
     673-
     674-               // The PHP version is older than the recommended version, but still acceptable.
     675-               if ( $response['is_supported'] ) {
     676-                       $result['label']  = __( 'We recommend that you update PHP' );
     677-                       $result['status'] = 'recommended';
     678-
     679-                       return $result;
     680-               }
     681-
     682-               // The PHP version is only receiving security fixes.
     683-               if ( $response['is_secure'] ) {
     684-                       $result['label']  = __( 'Your PHP version should be updated' );
     685-                       $result['status'] = 'recommended';
     686-
     687-                       return $result;
     688-               }
     689-
     690-               // Anything no longer secure must be updated.
     691-               $result['label']          = __( 'Your PHP version requires an update' );
     692-               $result['status']         = 'critical';
     693-               $result['badge']['label'] = __( 'Security' );
     694-
     695-               return $result;
     696-       }
     697-
     698-       /**
     699-        * Check if the passed extension or function are available.
     700-        *
     701-        * Make the check for available PHP modules into a simple boolean operator for a cleaner test runner.
     702-        *
     703-        * @since 5.2.0
     704-        *
     705-        * @param string $extension Optional. The extension name to test. Default null.
     706-        * @param string $function  Optional. The function name to test. Default null.
     707-        *
     708-        * @return bool Whether or not the extension and function are available.
     709-        */
     710-       private function test_php_extension_availability( $extension = null, $function = null ) {
     711-               // If no extension or function is passed, claim to fail testing, as we have nothing to test against.
     712-               if ( ! $extension && ! $function ) {
     713-                       return false;
     714-               }
     715-
     716-               if ( $extension && ! extension_loaded( $extension ) ) {
     717-                       return false;
     718-               }
     719-               if ( $function && ! function_exists( $function ) ) {
     720-                       return false;
     721-               }
     722-
     723-               return true;
     724-       }
     725-
     726-       /**
     727-        * Test if required PHP modules are installed on the host.
     728-        *
     729-        * This test builds on the recommendations made by the WordPress Hosting Team
     730-        * as seen at https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions
     731-        *
     732-        * @since 5.2.0
     733-        *
     734-        * @return array
     735-        */
     736-       public function get_test_php_extensions() {
     737-               $result = array(
     738-                       'label'       => __( 'Required and recommended modules are installed' ),
     739-                       'status'      => 'good',
     740-                       'badge'       => array(
     741-                               'label' => __( 'Performance' ),
     742-                               'color' => 'blue',
     743-                       ),
     744-                       'description' => sprintf(
     745-                               '<p>%s</p><p>%s</p>',
     746-                               __( 'PHP modules perform most of the tasks on the server that make your site run. Any changes to these must be made by your server administrator.' ),
     747-                               sprintf(
     748-                                       /* translators: %s: Link to the hosting group page about recommended PHP modules. */
     749-                                       __( 'The WordPress Hosting Team maintains a list of those modules, both recommended and required, in %s.' ),
     750-                                       sprintf(
     751-                                               '<a 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>',
     752-                                               /* translators: Localized team handbook, if one exists. */
     753-                                               esc_url( __( 'https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions' ) ),
     754-                                               __( 'the team handbook' ),
     755-                                               /* translators: accessibility text */
     756-                                               __( '(opens in a new tab)' )
     757-                                       )
     758-                               )
     759-                       ),
     760-                       'actions'     => '',
     761-                       'test'        => 'php_extensions',
     762-               );
     763-
     764-               $modules = array(
     765-                       'bcmath'    => array(
     766-                               'function' => 'bcadd',
     767-                               'required' => false,
     768-                       ),
     769-                       'curl'      => array(
     770-                               'function' => 'curl_version',
     771-                               'required' => false,
     772-                       ),
     773-                       'exif'      => array(
     774-                               'function' => 'exif_read_data',
     775-                               'required' => false,
     776-                       ),
     777-                       'filter'    => array(
     778-                               'function' => 'filter_list',
     779-                               'required' => false,
     780-                       ),
     781-                       'fileinfo'  => array(
     782-                               'function' => 'finfo_file',
     783-                               'required' => false,
     784-                       ),
     785-                       'mod_xml'   => array(
     786-                               'extension' => 'libxml',
     787-                               'required'  => false,
     788-                       ),
     789-                       'mysqli'    => array(
     790-                               'function' => 'mysqli_connect',
     791-                               'required' => false,
     792-                       ),
     793-                       'libsodium' => array(
     794-                               'function'            => 'sodium_compare',
     795-                               'required'            => false,
     796-                               'php_bundled_version' => '7.2.0',
     797-                       ),
     798-                       'openssl'   => array(
     799-                               'function' => 'openssl_encrypt',
     800-                               'required' => false,
     801-                       ),
     802-                       'pcre'      => array(
     803-                               'function' => 'preg_match',
     804-                               'required' => false,
     805-                       ),
     806-                       'imagick'   => array(
     807-                               'extension' => 'imagick',
     808-                               'required'  => false,
     809-                       ),
     810-                       'gd'        => array(
     811-                               'extension'    => 'gd',
     812-                               'required'     => false,
     813-                               'fallback_for' => 'imagick',
     814-                       ),
     815-                       'mcrypt'    => array(
     816-                               'extension'    => 'mcrypt',
     817-                               'required'     => false,
     818-                               'fallback_for' => 'libsodium',
     819-                       ),
     820-                       'xmlreader' => array(
     821-                               'extension'    => 'xmlreader',
     822-                               'required'     => false,
     823-                               'fallback_for' => 'xml',
     824-                       ),
     825-                       'zlib'      => array(
     826-                               'extension'    => 'zlib',
     827-                               'required'     => false,
     828-                               'fallback_for' => 'zip',
     829-                       ),
     830-               );
     831-
     832-               /**
     833-                * An array representing all the modules we wish to test for.
     834-                *
     835-                * @since 5.2.0
     836-                *
     837-                * @param array $modules {
     838-                *     An associated array of modules to test for.
     839-                *
     840-                *     array $module {
     841-                *         An associated array of module properties used during testing.
     842-                *         One of either `$function` or `$extension` must be provided, or they will fail by default.
     843-                *
     844-                *         string $function     Optional. A function name to test for the existence of.
     845-                *         string $extension    Optional. An extension to check if is loaded in PHP.
     846-                *         bool   $required     Is this a required feature or not.
     847-                *         string $fallback_for Optional. The module this module replaces as a fallback.
     848-                *     }
     849-                * }
     850-                */
     851-               $modules = apply_filters( 'site_status_test_php_modules', $modules );
     852-
     853-               $failures = array();
     854-
     855-               foreach ( $modules as $library => $module ) {
     856-                       $extension = ( isset( $module['extension'] ) ? $module['extension'] : null );
     857-                       $function  = ( isset( $module['function'] ) ? $module['function'] : null );
     858-
     859-                       // If this module is a fallback for another function, check if that other function passed.
     860-                       if ( isset( $module['fallback_for'] ) ) {
     861-                               /*
     862-                                * If that other function has a failure, mark this module as required for normal operations.
     863-                                * If that other function hasn't failed, skip this test as it's only a fallback.
     864-                                */
     865-                               if ( isset( $failures[ $module['fallback_for'] ] ) ) {
     866-                                       $module['required'] = true;
     867-                               } else {
     868-                                       continue;
     869-                               }
     870-                       }
     871-
     872-                       if ( ! $this->test_php_extension_availability( $extension, $function ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
     873-                               if ( $module['required'] ) {
     874-                                       $result['status'] = 'critical';
     875-
     876-                                       $class         = 'error';
     877-                                       $screen_reader = __( 'Error' );
     878-                                       $message       = sprintf(
     879-                                               /* translators: %s: The module name. */
     880-                                               __( 'The required module, %s, is not installed, or has been disabled.' ),
     881-                                               $library
     882-                                       );
     883-                               } else {
     884-                                       $class         = 'warning';
     885-                                       $screen_reader = __( 'Warning' );
     886-                                       $message       = sprintf(
     887-                                               /* translators: %s: The module name. */
     888-                                               __( 'The optional module, %s, is not installed, or has been disabled.' ),
     889-                                               $library
     890-                                       );
     891-                               }
     892-
     893-                               if ( ! $module['required'] && 'good' === $result['status'] ) {
     894-                                       $result['status'] = 'recommended';
     895-                               }
     896-
     897-                               $failures[ $library ] = "<span class='$class'><span class='screen-reader-text'>$screen_reader</span></span> $message";
     898-                       }
     899-               }
     900-
     901-               if ( ! empty( $failures ) ) {
     902-                       $output = '<ul>';
     903-
     904-                       foreach ( $failures as $failure ) {
     905-                               $output .= sprintf(
     906-                                       '<li>%s</li>',
     907-                                       $failure
     908-                               );
     909-                       }
     910-
     911-                       $output .= '</ul>';
     912-               }
     913-
     914-               if ( 'good' !== $result['status'] ) {
     915-                       if ( 'recommended' === $result['status'] ) {
     916-                               $result['label'] = __( 'One or more recommended modules are missing' );
     917-                       }
     918-                       if ( 'critical' === $result['status'] ) {
     919-                               $result['label'] = __( 'One or more required modules are missing' );
     920-                       }
     921-
     922-                       $result['description'] .= sprintf(
     923-                               '<p>%s</p>',
     924-                               $output
     925-                       );
     926-               }
     927-
     928-               return $result;
     929-       }
     930-
     931-       /**
     932-        * Test if the SQL server is up to date.
     933-        *
     934-        * @since 5.2.0
     935-        *
     936-        * @return array The test results.
     937-        */
     938-       public function get_test_sql_server() {
     939-               $result = array(
     940-                       'label'       => __( 'SQL server is up to date' ),
     941-                       'status'      => 'good',
     942-                       'badge'       => array(
     943-                               'label' => __( 'Performance' ),
     944-                               'color' => 'blue',
     945-                       ),
     946-                       'description' => sprintf(
     947-                               '<p>%s</p>',
     948-                               __( 'The SQL server is a required piece of software for the database WordPress uses to store all your site&#8217;s content and settings.' )
     949-                       ),
     950-                       'actions'     => sprintf(
     951-                               '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
     952-                               /* translators: Localized version of WordPress requirements if one exists. */
     953-                               esc_url( __( 'https://wordpress.org/about/requirements/' ) ),
     954-                               __( 'Read more about what WordPress requires to run.' ),
     955-                               /* translators: accessibility text */
     956-                               __( '(opens in a new tab)' )
     957-                       ),
     958-                       'test'        => 'sql_server',
     959-               );
     960-
     961-               $db_dropin = file_exists( WP_CONTENT_DIR . '/db.php' );
     962-
     963-               if ( ! $this->mysql_rec_version_check ) {
     964-                       $result['status'] = 'recommended';
     965-
     966-                       $result['label'] = __( 'Outdated SQL server' );
     967-
     968-                       $result['description'] .= sprintf(
     969-                               '<p>%s</p>',
     970-                               sprintf(
     971-                                       /* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server recommended version number. */
     972-                                       __( 'For optimal performance and security reasons, we recommend running %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
     973-                                       ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
     974-                                       $this->health_check_mysql_rec_version
     975-                               )
     976-                       );
     977-               }
     978-
     979-               if ( ! $this->mysql_min_version_check ) {
     980-                       $result['status'] = 'critical';
     981-
     982-                       $result['label']          = __( 'Severely outdated SQL server' );
     983-                       $result['badge']['label'] = __( 'Security' );
     984-
     985-                       $result['description'] .= sprintf(
     986-                               '<p>%s</p>',
     987-                               sprintf(
     988-                                       /* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server minimum version number. */
     989-                                       __( 'WordPress requires %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
     990-                                       ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
     991-                                       $this->health_check_mysql_required_version
     992-                               )
     993-                       );
     994-               }
     995-
     996-               if ( $db_dropin ) {
     997-                       $result['description'] .= sprintf(
     998-                               '<p>%s</p>',
     999-                               wp_kses(
     1000-                                       sprintf(
     1001-                                               /* translators: 1: The name of the drop-in. 2: The name of the database engine. */
     1002-                                               __( 'You are using a %1$s drop-in which might mean that a %2$s database is not being used.' ),
     1003-                                               '<code>wp-content/db.php</code>',
     1004-                                               ( $this->is_mariadb ? 'MariaDB' : 'MySQL' )
     1005-                                       ),
     1006-                                       array(
     1007-                                               'code' => true,
     1008-                                       )
     1009-                               )
     1010-                       );
     1011-               }
     1012-
     1013-               return $result;
     1014-       }
     1015-
     1016-       /**
     1017-        * Test if the database server is capable of using utf8mb4.
     1018-        *
     1019-        * @since 5.2.0
     1020-        *
     1021-        * @return array The test results.
     1022-        */
     1023-       public function get_test_utf8mb4_support() {
     1024-               global $wpdb;
     1025-
     1026-               $result = array(
     1027-                       'label'       => __( 'UTF8MB4 is supported' ),
     1028-                       'status'      => 'good',
     1029-                       'badge'       => array(
     1030-                               'label' => __( 'Performance' ),
     1031-                               'color' => 'blue',
     1032-                       ),
     1033-                       'description' => sprintf(
     1034-                               '<p>%s</p>',
     1035-                               __( '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.' )
     1036-                       ),
     1037-                       'actions'     => '',
     1038-                       'test'        => 'utf8mb4_support',
     1039-               );
     1040-
     1041-               if ( ! $this->is_mariadb ) {
     1042-                       if ( version_compare( $this->mysql_server_version, '5.5.3', '<' ) ) {
     1043-                               $result['status'] = 'recommended';
     1044-
     1045-                               $result['label'] = __( 'utf8mb4 requires a MySQL update' );
     1046-
     1047-                               $result['description'] .= sprintf(
     1048-                                       '<p>%s</p>',
     1049-                                       sprintf(
     1050-                                               /* translators: %s: Version number. */
     1051-                                               __( 'WordPress&#8217; utf8mb4 support requires MySQL version %s or greater. Please contact your server administrator.' ),
     1052-                                               '5.5.3'
     1053-                                       )
     1054-                               );
     1055-                       } else {
     1056-                               $result['description'] .= sprintf(
     1057-                                       '<p>%s</p>',
     1058-                                       __( 'Your MySQL version supports utf8mb4.' )
     1059-                               );
     1060-                       }
     1061-               } else { // MariaDB introduced utf8mb4 support in 5.5.0
     1062-                       if ( version_compare( $this->mysql_server_version, '5.5.0', '<' ) ) {
     1063-                               $result['status'] = 'recommended';
     1064-
     1065-                               $result['label'] = __( 'utf8mb4 requires a MariaDB update' );
     1066-
     1067-                               $result['description'] .= sprintf(
     1068-                                       '<p>%s</p>',
     1069-                                       sprintf(
     1070-                                               /* translators: %s: Version number. */
     1071-                                               __( 'WordPress&#8217; utf8mb4 support requires MariaDB version %s or greater. Please contact your server administrator.' ),
     1072-                                               '5.5.0'
     1073-                                       )
     1074-                               );
     1075-                       } else {
     1076-                               $result['description'] .= sprintf(
     1077-                                       '<p>%s</p>',
     1078-                                       __( 'Your MariaDB version supports utf8mb4.' )
     1079-                               );
     1080-                       }
     1081-               }
     1082-
     1083-               if ( $wpdb->use_mysqli ) {
     1084-                       // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info
     1085-                       $mysql_client_version = mysqli_get_client_info();
     1086-               } else {
     1087-                       // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info
     1088-                       $mysql_client_version = mysql_get_client_info();
     1089-               }
     1090-
     1091-               /*
     1092-                * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
     1093-                * mysqlnd has supported utf8mb4 since 5.0.9.
     1094-                */
     1095-               if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) {
     1096-                       $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );
     1097-                       if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {
     1098-                               $result['status'] = 'recommended';
     1099-
     1100-                               $result['label'] = __( 'utf8mb4 requires a newer client library' );
     1101-
     1102-                               $result['description'] .= sprintf(
     1103-                                       '<p>%s</p>',
     1104-                                       sprintf(
     1105-                                               /* translators: 1: Name of the library, 2: Number of version. */
     1106-                                               __( 'WordPress&#8217; utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
     1107-                                               'mysqlnd',
     1108-                                               '5.0.9'
     1109-                                       )
     1110-                               );
     1111-                       }
     1112-               } else {
     1113-                       if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) {
     1114-                               $result['status'] = 'recommended';
     1115-
     1116-                               $result['label'] = __( 'utf8mb4 requires a newer client library' );
     1117-
     1118-                               $result['description'] .= sprintf(
     1119-                                       '<p>%s</p>',
     1120-                                       sprintf(
     1121-                                               /* translators: 1: Name of the library, 2: Number of version. */
     1122-                                               __( 'WordPress&#8217; utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
     1123-                                               'libmysql',
     1124-                                               '5.5.3'
     1125-                                       )
     1126-                               );
     1127-                       }
     1128-               }
     1129-
     1130-               return $result;
     1131-       }
     1132-
     1133-       /**
     1134-        * Test if the site can communicate with WordPress.org.
     1135-        *
     1136-        * @since 5.2.0
     1137-        *
     1138-        * @return array The test results.
     1139-        */
     1140-       public function get_test_dotorg_communication() {
     1141-               $result = array(
     1142-                       'label'       => __( 'Can communicate with WordPress.org' ),
     1143-                       'status'      => '',
     1144-                       'badge'       => array(
     1145-                               'label' => __( 'Security' ),
     1146-                               'color' => 'blue',
     1147-                       ),
     1148-                       'description' => sprintf(
     1149-                               '<p>%s</p>',
     1150-                               __( 'Communicating with the WordPress servers is used to check for new versions, and to both install and update WordPress core, themes or plugins.' )
     1151-                       ),
     1152-                       'actions'     => '',
     1153-                       'test'        => 'dotorg_communication',
     1154-               );
     1155-
     1156-               $wp_dotorg = wp_remote_get(
     1157-                       'https://api.wordpress.org',
     1158-                       array(
     1159-                               'timeout' => 10,
     1160-                       )
     1161-               );
     1162-               if ( ! is_wp_error( $wp_dotorg ) ) {
     1163-                       $result['status'] = 'good';
     1164-               } else {
     1165-                       $result['status'] = 'critical';
     1166-
     1167-                       $result['label'] = __( 'Could not reach WordPress.org' );
     1168-
     1169-                       $result['description'] .= sprintf(
     1170-                               '<p>%s</p>',
     1171-                               sprintf(
     1172-                                       '<span class="error"><span class="screen-reader-text">%s</span></span> %s',
     1173-                                       __( 'Error' ),
     1174-                                       sprintf(
     1175-                                               /* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
     1176-                                               __( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s' ),
     1177-                                               gethostbyname( 'api.wordpress.org' ),
     1178-                                               $wp_dotorg->get_error_message()
     1179-                                       )
     1180-                               )
     1181-                       );
     1182-
     1183-                       $result['actions'] = sprintf(
     1184-                               '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
     1185-                               /* translators: Localized Support reference. */
     1186-                               esc_url( __( 'https://wordpress.org/support' ) ),
     1187-                               __( 'Get help resolving this issue.' ),
     1188-                               /* translators: accessibility text */
     1189-                               __( '(opens in a new tab)' )
     1190-                       );
     1191-               }
     1192-
     1193-               return $result;
     1194-       }
     1195-
     1196-       /**
     1197-        * Test if debug information is enabled.
     1198-        *
     1199-        * When WP_DEBUG is enabled, errors and information may be disclosed to site visitors, or it may be
     1200-        * logged to a publicly accessible file.
     1201-        *
     1202-        * Debugging is also frequently left enabled after looking for errors on a site, as site owners do
     1203-        * not understand the implications of this.
     1204-        *
     1205-        * @since 5.2.0
     1206-        *
     1207-        * @return array The test results.
     1208-        */
     1209-       public function get_test_is_in_debug_mode() {
     1210-               $result = array(
     1211-                       'label'       => __( 'Your site is not set to output debug information' ),
     1212-                       'status'      => 'good',
     1213-                       'badge'       => array(
     1214-                               'label' => __( 'Security' ),
     1215-                               'color' => 'blue',
     1216-                       ),
     1217-                       'description' => sprintf(
     1218-                               '<p>%s</p>',
     1219-                               __( '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.' )
     1220-                       ),
     1221-                       'actions'     => sprintf(
     1222-                               '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
     1223-                               /* translators: Documentation explaining debugging in WordPress. */
     1224-                               esc_url( __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) ),
     1225-                               __( 'Read about debugging in WordPress.' ),
     1226-                               /* translators: accessibility text */
     1227-                               __( '(opens in a new tab)' )
     1228-                       ),
     1229-                       'test'        => 'is_in_debug_mode',
     1230-               );
     1231-
     1232-               if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
     1233-                       if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
     1234-                               $result['label'] = __( 'Your site is set to log errors to a potentially public file.' );
     1235-
     1236-                               $result['status'] = 'critical';
     1237-
     1238-                               $result['description'] .= sprintf(
     1239-                                       '<p>%s</p>',
     1240-                                       sprintf(
     1241-                                               /* translators: %s: WP_DEBUG_LOG */
     1242-                                               __( 'The value, %s, has been added to this website&#8217;s configuration file. This means any errors on the site will be written to a file which is potentially available to normal users.' ),
     1243-                                               '<code>WP_DEBUG_LOG</code>'
     1244-                                       )
     1245-                               );
     1246-                       }
     1247-
     1248-                       if ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) {
     1249-                               $result['label'] = __( 'Your site is set to display errors to site visitors' );
     1250-
     1251-                               $result['status'] = 'critical';
     1252-
     1253-                               $result['description'] .= sprintf(
     1254-                                       '<p>%s</p>',
     1255-                                       sprintf(
     1256-                                               /* translators: 1: WP_DEBUG_DISPLAY, 2: WP_DEBUG */
     1257-                                               __( 'The value, %1$s, has either been enabled by %2$s or added to your configuration file. This will make errors display on the front end of your site.' ),
     1258-                                               '<code>WP_DEBUG_DISPLAY</code>',
     1259-                                               '<code>WP_DEBUG</code>'
     1260-                                       )
     1261-                               );
     1262-                       }
     1263-               }
     1264-
     1265-               return $result;
     1266-       }
     1267-
     1268-       /**
     1269-        * Test if your site is serving content over HTTPS.
     1270-        *
     1271-        * Many sites have varying degrees of HTTPS support, the most common of which is sites that have it
     1272-        * enabled, but only if you visit the right site address.
     1273-        *
     1274-        * @since 5.2.0
     1275-        *
     1276-        * @return array The test results.
     1277-        */
     1278-       public function get_test_https_status() {
     1279-               $result = array(
     1280-                       'label'       => __( 'Your website is using an active HTTPS connection.' ),
     1281-                       'status'      => 'good',
     1282-                       'badge'       => array(
     1283-                               'label' => __( 'Security' ),
     1284-                               'color' => 'blue',
     1285-                       ),
     1286-                       'description' => sprintf(
     1287-                               '<p>%s</p>',
     1288-                               __( '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.' )
     1289-                       ),
     1290-                       'actions'     => sprintf(
     1291-                               '<p><a href="%s" target="_blank" rel="noopener noreferrer">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
     1292-                               /* translators: Documentation explaining HTTPS and why it should be used. */
     1293-                               esc_url( __( 'https://wordpress.org/support/article/why-should-i-use-https/' ) ),
     1294-                               __( 'Read more about why you should use HTTPS' ),
     1295-                               /* translators: accessibility text */
     1296-                               __( '(opens in a new tab)' )
     1297-                       ),
     1298-                       'test'        => 'https_status',
     1299-               );
     1300-
     1301-               if ( is_ssl() ) {
     1302-                       $wp_url   = get_bloginfo( 'wpurl' );
     1303-                       $site_url = get_bloginfo( 'url' );
     1304-
     1305-                       if ( 'https' !== substr( $wp_url, 0, 5 ) || 'https' !== substr( $site_url, 0, 5 ) ) {
     1306-                               $result['status'] = 'recommended';
     1307-
     1308-                               $result['label'] = __( 'Only parts of your site are using HTTPS' );
     1309-
     1310-                               $result['description'] = sprintf(
     1311-                                       '<p>%s</p>',
     1312-                                       sprintf(
     1313-                                               /* translators: %s: URL to Settings > General to change options. */
     1314-                                               __( 'You are accessing this website using HTTPS, but your <a href="%s">WordPress Address</a> is not set up to use HTTPS by default.' ),
     1315-                                               esc_url( admin_url( 'options-general.php' ) )
     1316-                                       )
     1317-                               );
     1318-
     1319-                               $result['actions'] .= sprintf(
     1320-                                       '<p><a href="%s">%s</a></p>',
     1321-                                       esc_url( admin_url( 'options-general.php' ) ),
     1322-                                       __( 'Update your site addresses' )
     1323-                               );
     1324-                       }
     1325-               } else {
     1326-                       $result['status'] = 'recommended';
     1327-
     1328-                       $result['label'] = __( 'Your site does not use HTTPS' );
     1329-               }
     1330-
     1331-               return $result;
     1332-       }
     1333-
     1334-       /**
     1335-        * Check if the HTTP API can handle SSL/TLS requests.
     1336-        *
     1337-        * @since 5.2.0
     1338-        *
     1339-        * @return array The test results.
     1340-        */
     1341-       public function get_test_ssl_support() {
     1342-               $result = array(
     1343-                       'label'       => '',
     1344-                       'status'      => '',
     1345-                       'badge'       => array(
     1346-                               'label' => __( 'Security' ),
     1347-                               'color' => 'blue',
     1348-                       ),
     1349-                       'description' => sprintf(
     1350-                               '<p>%s</p>',
     1351-                               __( 'Securely communicating between servers are needed for transactions such as fetching files, conducting sales on store sites, and much more.' )
     1352-                       ),
     1353-                       'actions'     => '',
     1354-                       'test'        => 'ssl_support',
     1355-               );
     1356-
     1357-               $supports_https = wp_http_supports( array( 'ssl' ) );
     1358-
     1359-               if ( $supports_https ) {
     1360-                       $result['status'] = 'good';
     1361-
     1362-                       $result['label'] = __( 'Your site can communicate securely with other services' );
     1363-               } else {
     1364-                       $result['status'] = 'critical';
     1365-
     1366-                       $result['label'] = __( 'Your site is unable to communicate securely with other services' );
     1367-
     1368-                       $result['description'] .= sprintf(
     1369-                               '<p>%s</p>',
     1370-                               __( 'Talk to your web host about OpenSSL support for PHP.' )
     1371-                       );
     1372-               }
     1373-
     1374-               return $result;
     1375-       }
     1376-
     1377-       /**
     1378-        * Test if scheduled events run as intended.
     1379-        *
     1380-        * If scheduled events are not running, this may indicate something with WP_Cron is not working as intended,
     1381-        * or that there are orphaned events hanging around from older code.
     1382-        *
     1383-        * @since 5.2.0
     1384-        *
     1385-        * @return array The test results.
     1386-        */
     1387-       public function get_test_scheduled_events() {
     1388-               $result = array(
     1389-                       'label'       => __( 'Scheduled events are running' ),
     1390-                       'status'      => 'good',
     1391-                       'badge'       => array(
     1392-                               'label' => __( 'Performance' ),
     1393-                               'color' => 'blue',
     1394-                       ),
     1395-                       'description' => sprintf(
     1396-                               '<p>%s</p>',
     1397-                               __( 'Scheduled events are what periodically looks for updates to plugins, themes and WordPress itself. 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.' )
     1398-                       ),
     1399-                       'actions'     => '',
     1400-                       'test'        => 'scheduled_events',
     1401-               );
     1402-
     1403-               $this->wp_schedule_test_init();
     1404-
     1405-               if ( is_wp_error( $this->has_missed_cron() ) ) {
     1406-                       $result['status'] = 'critical';
     1407-
     1408-                       $result['label'] = __( 'It was not possible to check your scheduled events' );
     1409-
     1410-                       $result['description'] = sprintf(
     1411-                               '<p>%s</p>',
     1412-                               sprintf(
     1413-                                       /* translators: %s: The error message returned while from the cron scheduler. */
     1414-                                       __( 'While trying to test your site&#8217;s scheduled events, the following error was returned: %s' ),
     1415-                                       $this->has_missed_cron()->get_error_message()
     1416-                               )
     1417-                       );
     1418-               } else {
     1419-                       if ( $this->has_missed_cron() ) {
     1420-                               $result['status'] = 'recommended';
     1421-
     1422-                               $result['label'] = __( 'A scheduled event has failed' );
     1423-
     1424-                               $result['description'] = sprintf(
     1425-                                       '<p>%s</p>',
     1426-                                       sprintf(
     1427-                                               /* translators: %s: The name of the failed cron event. */
     1428-                                               __( '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.' ),
     1429-                                               $this->last_missed_cron
     1430-                                       )
     1431-                               );
     1432-                       }
     1433-               }
     1434-
     1435-               return $result;
     1436-       }
     1437-
     1438-       /**
     1439-        * Test if WordPress can run automated background updates.
     1440-        *
     1441-        * Background updates in WordPress are primarily used for minor releases and security updates. It's important
     1442-        * to either have these working, or be aware that they are intentionally disabled for whatever reason.
     1443-        *
     1444-        * @since 5.2.0
     1445-        *
     1446-        * @return array The test results.
     1447-        */
     1448-       public function get_test_background_updates() {
     1449-               $result = array(
     1450-                       'label'       => __( 'Background updates are working' ),
     1451-                       'status'      => 'good',
     1452-                       'badge'       => array(
     1453-                               'label' => __( 'Security' ),
     1454-                               'color' => 'blue',
     1455-                       ),
     1456-                       'description' => sprintf(
     1457-                               '<p>%s</p>',
     1458-                               __( 'Background updates ensure that WordPress can auto-update if a security update is released for the version you are currently using.' )
     1459-                       ),
     1460-                       'actions'     => '',
     1461-                       'test'        => 'background_updates',
     1462-               );
     1463-
     1464-               if ( ! class_exists( 'WP_Site_Health_Auto_Updates' ) ) {
     1465-                       require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health-auto-updates.php' );
     1466-               }
     1467-
     1468-               // Run the auto-update tests in a separate class,
     1469-               // as there are many considerations to be made.
     1470-               $automatic_updates = new WP_Site_Health_Auto_Updates();
     1471-               $tests             = $automatic_updates->run_tests();
     1472-
     1473-               $output = '<ul>';
     1474-
     1475-               foreach ( $tests as $test ) {
     1476-                       $severity_string = __( 'Passed' );
     1477-
     1478-                       if ( 'fail' === $test->severity ) {
     1479-                               $result['label'] = __( 'Background updates are not working as expected' );
     1480-
     1481-                               $result['status'] = 'critical';
     1482-
     1483-                               $severity_string = __( 'Error' );
     1484-                       }
     1485-
     1486-                       if ( 'warning' === $test->severity && 'good' === $result['status'] ) {
     1487-                               $result['label'] = __( 'Background updates may not be working properly' );
     1488-
     1489-                               $result['status'] = 'recommended';
     1490-
     1491-                               $severity_string = __( 'Warning' );
     1492-                       }
     1493-
     1494-                       $output .= sprintf(
     1495-                               '<li><span class="%s"><span class="screen-reader-text">%s</span></span> %s</li>',
     1496-                               esc_attr( $test->severity ),
     1497-                               $severity_string,
     1498-                               $test->description
     1499-                       );
     1500-               }
     1501-
     1502-               $output .= '</ul>';
     1503-
     1504-               if ( 'good' !== $result['status'] ) {
     1505-                       $result['description'] .= sprintf(
     1506-                               '<p>%s</p>',
     1507-                               $output
     1508-                       );
     1509-               }
     1510-
     1511-               return $result;
     1512-       }
     1513-
     1514-       /**
     1515-        * Test if loopbacks work as expected.
     1516-        *
     1517-        * A loopback is when WordPress queries itself, for example to start a new WP_Cron instance, or when editing a
     1518-        * plugin or theme. This has shown itself to be a recurring issue as code can very easily break this interaction.
     1519-        *
     1520-        * @since 5.2.0
     1521-        *
     1522-        * @return array The test results.
     1523-        */
     1524-       public function get_test_loopback_requests() {
     1525-               $result = array(
     1526-                       'label'       => __( 'Your site can perform loopback requests' ),
     1527-                       'status'      => 'good',
     1528-                       'badge'       => array(
     1529-                               'label' => __( 'Performance' ),
     1530-                               'color' => 'blue',
     1531-                       ),
     1532-                       'description' => sprintf(
     1533-                               '<p>%s</p>',
     1534-                               __( '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.' )
     1535-                       ),
     1536-                       'actions'     => '',
     1537-                       'test'        => 'loopback_requests',
     1538-               );
     1539-
     1540-               $check_loopback = $this->can_perform_loopback();
     1541-
     1542-               $result['status'] = $check_loopback->status;
     1543-
     1544-               if ( 'good' !== $check_loopback->status ) {
     1545-                       $result['label'] = __( 'Your site could not complete a loopback request' );
     1546-
     1547-                       $result['description'] .= sprintf(
     1548-                               '<p>%s</p>',
     1549-                               $check_loopback->message
     1550-                       );
     1551-               }
     1552-
     1553-               return $result;
     1554-       }
     1555-
     1556-       /**
     1557-        * Test if HTTP requests are blocked.
     1558-        *
     1559-        * It's possible to block all outgoing communication (with the possibility of whitelisting hosts) via the
     1560-        * HTTP API. This may create problems for users as many features are running as services these days.
     1561-        *
     1562-        * @since 5.2.0
     1563-        *
     1564-        * @return array The test results.
     1565-        */
     1566-       public function get_test_http_requests() {
     1567-               $result = array(
     1568-                       'label'       => __( 'HTTP requests seem to be working as expected' ),
     1569-                       'status'      => 'good',
     1570-                       'badge'       => array(
     1571-                               'label' => __( 'Performance' ),
     1572-                               'color' => 'blue',
     1573-                       ),
     1574-                       'description' => sprintf(
     1575-                               '<p>%s</p>',
     1576-                               __( '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.' )
     1577-                       ),
     1578-                       'actions'     => '',
     1579-                       'test'        => 'http_requests',
     1580-               );
     1581-
     1582-               $blocked = false;
     1583-               $hosts   = array();
     1584-
     1585-               if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) ) {
     1586-                       $blocked = true;
     1587-               }
     1588-
     1589-               if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
     1590-                       $hosts = explode( ',', WP_ACCESSIBLE_HOSTS );
     1591-               }
     1592-
     1593-               if ( $blocked && 0 === sizeof( $hosts ) ) {
     1594-                       $result['status'] = 'critical';
     1595-
     1596-                       $result['label'] = __( 'HTTP requests are blocked' );
     1597-
     1598-                       $result['description'] .= sprintf(
     1599-                               '<p>%s</p>',
     1600-                               sprintf(
     1601-                                       /* translators: %s: Name of the constant used. */
     1602-                                       __( 'HTTP requests have been blocked by the %s constant, with no allowed hosts.' ),
     1603-                                       '<code>WP_HTTP_BLOCK_EXTERNAL</code>'
     1604-                               )
     1605-                       );
     1606-               }
     1607-
     1608-               if ( $blocked && 0 < sizeof( $hosts ) ) {
     1609-                       $result['status'] = 'recommended';
     1610-
     1611-                       $result['label'] = __( 'HTTP requests are partially blocked' );
     1612-
     1613-                       $result['description'] .= sprintf(
     1614-                               '<p>%s</p>',
     1615-                               sprintf(
     1616-                                       /* translators: 1: Name of the constant used. 2: List of hostnames whitelisted. */
     1617-                                       __( 'HTTP requests have been blocked by the %1$s constant, with some hosts whitelisted: %2$s.' ),
     1618-                                       '<code>WP_HTTP_BLOCK_EXTERNAL</code>',
     1619-                                       implode( ',', $hosts )
     1620-                               )
     1621-                       );
     1622-               }
     1623-
     1624-               return $result;
     1625-       }
     1626-
     1627-       /**
     1628-        * Test if the REST API is accessible.
     1629-        *
     1630-        * Various security measures may block the REST API from working, or it may have been disabled in general.
     1631-        * This is required for the new block editor to work, so we explicitly test for this.
     1632-        *
     1633-        * @since 5.2.0
     1634-        *
     1635-        * @return array The test results.
     1636-        */
     1637-       public function get_test_rest_availability() {
     1638-               $result = array(
     1639-                       'label'       => __( 'The REST API is available' ),
     1640-                       'status'      => 'good',
     1641-                       'badge'       => array(
     1642-                               'label' => __( 'Performance' ),
     1643-                               'color' => 'blue',
     1644-                       ),
     1645-                       'description' => sprintf(
     1646-                               '<p>%s</p>',
     1647-                               __( '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.' )
     1648-                       ),
     1649-                       'actions'     => '',
     1650-                       'test'        => 'rest_availability',
     1651-               );
     1652-
     1653-               $cookies = wp_unslash( $_COOKIE );
     1654-               $timeout = 10;
     1655-               $headers = array(
     1656-                       'Cache-Control' => 'no-cache',
     1657-                       'X-WP-Nonce'    => wp_create_nonce( 'wp_rest' ),
     1658-               );
     1659-
     1660-               // Include Basic auth in loopback requests.
     1661-               if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
     1662-                       $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
     1663-               }
     1664-
     1665-               $url = rest_url( 'wp/v2/types/post' );
     1666-
     1667-               // The context for this is editing with the new block editor.
     1668-               $url = add_query_arg(
     1669-                       array(
     1670-                               'context' => 'edit',
     1671-                       ),
     1672-                       $url
     1673-               );
     1674-
     1675-               $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
     1676-
     1677-               if ( is_wp_error( $r ) ) {
     1678-                       $result['status'] = 'critical';
     1679-
     1680-                       $result['label'] = __( 'The REST API encountered an error' );
     1681-
     1682-                       $result['description'] .= sprintf(
     1683-                               '<p>%s</p>',
     1684-                               sprintf(
     1685-                                       '%s<br>%s',
     1686-                                       __( 'The REST API request failed due to an error.' ),
     1687-                                       sprintf(
     1688-                                               /* translators: 1: The HTTP response code. 2: The error message returned. */
     1689-                                               __( 'Error: [%1$s] %2$s' ),
     1690-                                               wp_remote_retrieve_response_code( $r ),
     1691-                                               $r->get_error_message()
     1692-                                       )
     1693-                               )
     1694-                       );
     1695-               } elseif ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
     1696-                       $result['status'] = 'recommended';
     1697-
     1698-                       $result['label'] = __( 'The REST API encountered an unexpected result' );
     1699-
     1700-                       $result['description'] .= sprintf(
     1701-                               '<p>%s</p>',
     1702-                               sprintf(
     1703-                                       /* translators: 1: The HTTP response code returned. 2: The error message returned. */
     1704-                                       __( 'The REST API call gave the following unexpected result: (%1$d) %2$s.' ),
     1705-                                       wp_remote_retrieve_response_code( $r ),
     1706-                                       wp_remote_retrieve_body( $r )
     1707-                               )
     1708-                       );
     1709-               } else {
     1710-                       $json = json_decode( wp_remote_retrieve_body( $r ), true );
     1711-
     1712-                       if ( false !== $json && ! isset( $json['capabilities'] ) ) {
     1713-                               $result['status'] = 'recommended';
     1714-
     1715-                               $result['label'] = __( 'The REST API did not behave correctly' );
     1716-
     1717-                               $result['description'] .= sprintf(
     1718-                                       '<p>%s</p>',
     1719-                                       sprintf(
     1720-                                               /* translators: %s: the name of the query parameter being tested. */
     1721-                                               __( 'The REST API did not process the %s query parameter correctly.' ),
     1722-                                               '<code>context</code>'
     1723-                                       )
     1724-                               );
     1725-                       }
     1726-               }
     1727-
     1728-               return $result;
     1729-       }
     1730-
     1731-       /**
     1732-        * Return a set of tests that belong to the site status page.
     1733-        *
     1734-        * Each site status test is defined here, they may be `direct` tests, that run on page load, or `async` tests
     1735-        * which will run later down the line via JavaScript calls to improve page performance and hopefully also user
     1736-        * experiences.
     1737-        *
     1738-        * @since 5.2.0
     1739-        *
     1740-        * @return array The list of tests to run.
     1741-        */
     1742-       public static function get_tests() {
     1743-               $tests = array(
     1744-                       'direct' => array(
     1745-                               'wordpress_version' => array(
     1746-                                       'label' => __( 'WordPress Version' ),
     1747-                                       'test'  => 'wordpress_version',
     1748-                               ),
     1749-                               'plugin_version'    => array(
     1750-                                       'label' => __( 'Plugin Versions' ),
     1751-                                       'test'  => 'plugin_version',
     1752-                               ),
     1753-                               'theme_version'     => array(
     1754-                                       'label' => __( 'Theme Versions' ),
     1755-                                       'test'  => 'theme_version',
     1756-                               ),
     1757-                               'php_version'       => array(
     1758-                                       'label' => __( 'PHP Version' ),
     1759-                                       'test'  => 'php_version',
     1760-                               ),
     1761-                               'sql_server'        => array(
     1762-                                       'label' => __( 'Database Server version' ),
     1763-                                       'test'  => 'sql_server',
     1764-                               ),
     1765-                               'php_extensions'    => array(
     1766-                                       'label' => __( 'PHP Extensions' ),
     1767-                                       'test'  => 'php_extensions',
     1768-                               ),
     1769-                               'utf8mb4_support'   => array(
     1770-                                       'label' => __( 'MySQL utf8mb4 support' ),
     1771-                                       'test'  => 'utf8mb4_support',
     1772-                               ),
     1773-                               'https_status'      => array(
     1774-                                       'label' => __( 'HTTPS status' ),
     1775-                                       'test'  => 'https_status',
     1776-                               ),
     1777-                               'ssl_support'       => array(
     1778-                                       'label' => __( 'Secure communication' ),
     1779-                                       'test'  => 'ssl_support',
     1780-                               ),
     1781-                               'scheduled_events'  => array(
     1782-                                       'label' => __( 'Scheduled events' ),
     1783-                                       'test'  => 'scheduled_events',
     1784-                               ),
     1785-                               'http_requests'     => array(
     1786-                                       'label' => __( 'HTTP Requests' ),
     1787-                                       'test'  => 'http_requests',
     1788-                               ),
     1789-                               'debug_enabled'     => array(
     1790-                                       'label' => __( 'Debugging enabled' ),
     1791-                                       'test'  => 'is_in_debug_mode',
     1792-                               ),
     1793-                       ),
     1794-                       'async'  => array(
     1795-                               'dotorg_communication' => array(
     1796-                                       'label' => __( 'Communication with WordPress.org' ),
     1797-                                       'test'  => 'dotorg_communication',
     1798-                               ),
     1799-                               'background_updates'   => array(
     1800-                                       'label' => __( 'Background updates' ),
     1801-                                       'test'  => 'background_updates',
     1802-                               ),
     1803-                               'loopback_requests'    => array(
     1804-                                       'label' => __( 'Loopback request' ),
     1805-                                       'test'  => 'loopback_requests',
     1806-                               ),
     1807-                       ),
     1808-               );
     1809-
     1810-               // Conditionally include REST rules if the function for it exists.
     1811-               if ( function_exists( 'rest_url' ) ) {
     1812-                       $tests['direct']['rest_availability'] = array(
     1813-                               'label' => __( 'REST API availability' ),
     1814-                               'test'  => 'rest_availability',
     1815-                       );
     1816-               }
     1817-
     1818-               /**
     1819-                * Add or modify which site status tests are run on a site.
     1820-                *
     1821-                * The site health is determined by a set of tests based on best practices from
     1822-                * both the WordPress Hosting Team, but also web standards in general.
     1823-                *
     1824-                * Some sites may not have the same requirements, for example the automatic update
     1825-                * checks may be handled by a host, and are therefore disabled in core.
     1826-                * Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example.
     1827-                *
     1828-                * Tests may be added either as direct, or asynchronous ones. Any test that may require some time
     1829-                * to complete should run asynchronously, to avoid extended loading periods within wp-admin.
     1830-                *
     1831-                * @since 5.2.0
     1832-                *
     1833-                * @param array $test_type {
     1834-                *     An associative array, where the `$test_type` is either `direct` or
     1835-                *     `async`, to declare if the test should run via AJAX calls after page load.
     1836-                *
     1837-                *     @type array $identifier {
     1838-                *         `$identifier` should be a unique identifier for the test that should run.
     1839-                *         Plugins and themes are encouraged to prefix test identifiers with their slug
     1840-                *         to avoid any collisions between tests.
     1841-                *
     1842-                *         @type string $label A friendly label for your test to identify it by.
     1843-                *         @type mixed  $test  A callable to perform a direct test, or a string AJAX action to be called
     1844-                *                             to perform an async test.
     1845-                *     }
     1846-                * }
     1847-                */
     1848-               $tests = apply_filters( 'site_status_tests', $tests );
     1849-
     1850-               return $tests;
     1851-       }
     1852-
     1853-       /**
     1854-        * Add a class to the body HTML tag.
     1855-        *
     1856-        * Filters the body class string for admin pages and adds our own class for easier styling.
     1857-        *
     1858-        * @since 5.2.0
     1859-        *
     1860-        * @param string $body_class The body class string.
     1861-        * @return string The modified body class string.
     1862-        */
     1863-       public function admin_body_class( $body_class ) {
     1864-               $body_class .= ' site-health';
     1865-
     1866-               return $body_class;
     1867-       }
     1868-
     1869-       /**
     1870-        * Initiate the WP_Cron schedule test cases.
     1871-        *
     1872-        * @since 5.2.0
     1873-        */
     1874-       private function wp_schedule_test_init() {
     1875-               $this->schedules = wp_get_schedules();
     1876-               $this->get_cron_tasks();
     1877-       }
     1878-
     1879-       /**
     1880-        * Populate our list of cron events and store them to a class-wide variable.
     1881-        *
     1882-        * @since 5.2.0
     1883-        */
     1884-       private function get_cron_tasks() {
     1885-               $cron_tasks = _get_cron_array();
     1886-
     1887-               if ( empty( $cron_tasks ) ) {
     1888-                       $this->crons = new WP_Error( 'no_tasks', __( 'No scheduled events exist on this site.' ) );
     1889-                       return;
     1890-               }
     1891-
     1892-               $this->crons = array();
     1893-
     1894-               foreach ( $cron_tasks as $time => $cron ) {
     1895-                       foreach ( $cron as $hook => $dings ) {
     1896-                               foreach ( $dings as $sig => $data ) {
     1897-
     1898-                                       $this->crons[ "$hook-$sig-$time" ] = (object) array(
     1899-                                               'hook'     => $hook,
     1900-                                               'time'     => $time,
     1901-                                               'sig'      => $sig,
     1902-                                               'args'     => $data['args'],
     1903-                                               'schedule' => $data['schedule'],
     1904-                                               'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
     1905-                                       );
     1906-
     1907-                               }
     1908-                       }
     1909-               }
     1910-       }
     1911-
     1912-       /**
     1913-        * Check if any scheduled tasks have been missed.
     1914-        *
     1915-        * Returns a boolean value of `true` if a scheduled task has been missed and ends processing. If the list of
     1916-        * crons is an instance of WP_Error, return the instance instead of a boolean value.
     1917-        *
     1918-        * @since 5.2.0
     1919-        *
     1920-        * @return bool|WP_Error true if a cron was missed, false if it wasn't. WP_Error if the cron is set to that.
     1921-        */
     1922-       public function has_missed_cron() {
     1923-               if ( is_wp_error( $this->crons ) ) {
     1924-                       return $this->crons;
     1925-               }
     1926-
     1927-               foreach ( $this->crons as $id => $cron ) {
     1928-                       if ( ( $cron->time - time() ) < 0 ) {
     1929-                               $this->last_missed_cron = $cron->hook;
     1930-                               return true;
     1931-                       }
     1932-               }
     1933-
     1934-               return false;
     1935-       }
     1936-
     1937-       /**
     1938-        * Run a loopback test on our site.
     1939-        *
     1940-        * Loopbacks are what WordPress uses to communicate with itself to start up WP_Cron, scheduled posts,
     1941-        * make sure plugin or theme edits don't cause site failures and similar.
     1942-        *
     1943-        * @since 5.2.0
     1944-        *
     1945-        * @return object The test results.
     1946-        */
     1947-       function can_perform_loopback() {
     1948-               $cookies = wp_unslash( $_COOKIE );
     1949-               $timeout = 10;
     1950-               $headers = array(
     1951-                       'Cache-Control' => 'no-cache',
     1952-               );
     1953-
     1954-               // Include Basic auth in loopback requests.
     1955-               if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
     1956-                       $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
     1957-               }
     1958-
     1959-               $url = admin_url();
     1960-
     1961-               $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
     1962-
     1963-               if ( is_wp_error( $r ) ) {
     1964-                       return (object) array(
     1965-                               'status'  => 'critical',
     1966-                               'message' => sprintf(
     1967-                                       '%s<br>%s',
     1968-                                       __( 'The loopback request to your site failed, this means features relying on them are not currently working as expected.' ),
     1969-                                       sprintf(
     1970-                                               // translators: 1: The HTTP response code. 2: The error message returned.
     1971-                                               __( 'Error: [%1$s] %2$s' ),
     1972-                                               wp_remote_retrieve_response_code( $r ),
     1973-                                               $r->get_error_message()
     1974-                                       )
     1975-                               ),
     1976-                       );
     1977-               }
     1978-
     1979-               if ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
     1980-                       return (object) array(
     1981-                               'status'  => 'recommended',
     1982-                               'message' => sprintf(
     1983-                                       // translators: %d: The HTTP response code returned.
     1984-                                       __( '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.' ),
     1985-                                       wp_remote_retrieve_response_code( $r )
     1986-                               ),
     1987-                       );
     1988-               }
     1989-
     1990-               return (object) array(
     1991-                       'status'  => 'good',
     1992-                       'message' => __( 'The loopback request to your site completed successfully.' ),
     1993-               );
     1994-       }
     1995-}