WordPress.org

Make WordPress Core

Changeset 45234


Ignore:
Timestamp:
04/17/2019 02:34:12 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Site Health: Allow any callable added via site_status_tests filter to return test results for direct tests.

Async tests still need to be a string for the AJAX action.

Props kraftbj.
Fixes #46836.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r45196 r45234  
    7272        if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
    7373            $tests = WP_Site_Health::get_tests();
     74
    7475            // Don't run https test on localhost
    7576            if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
    7677                unset( $tests['direct']['https_status'] );
    7778            }
     79
    7880            foreach ( $tests['direct'] as $test ) {
    79                 $test_function = sprintf(
    80                     'get_test_%s',
    81                     $test['test']
    82                 );
    83 
    84                 if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
    85                     $health_check_js_variables['site_status']['direct'][] = call_user_func( array( $this, $test_function ) );
    86                 } else {
     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'] ) ) {
    8794                    $health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] );
    8895                }
     
    9097
    9198            foreach ( $tests['async'] as $test ) {
    92                 $health_check_js_variables['site_status']['async'][] = array(
    93                     'test'      => $test['test'],
    94                     'completed' => false,
    95                 );
     99                if ( is_string( $test['test'] ) ) {
     100                    $health_check_js_variables['site_status']['async'][] = array(
     101                        'test'      => $test['test'],
     102                        'completed' => false,
     103                    );
     104                }
    96105            }
    97106        }
     
    17991808
    18001809        /**
    1801          * Add or modify which site status tests are ran on a site.
     1810         * Add or modify which site status tests are run on a site.
    18021811         *
    18031812         * The site health is determined by a set of tests based on best practices from
     
    18081817         * Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example.
    18091818         *
    1810          * Test may be added either as direct, or asynchronous ones. Any test that may require some time
     1819         * Tests may be added either as direct, or asynchronous ones. Any test that may require some time
    18111820         * to complete should run asynchronously, to avoid extended loading periods within wp-admin.
    18121821         *
     
    18231832         *
    18241833         *         @type string $label A friendly label for your test to identify it by.
    1825          *         @type string $test  The ajax action to be called to perform the tests.
     1834         *         @type mixed  $test  A callable to perform a direct test, or a string AJAX action to be called
     1835         *                             to perform an async test.
    18261836         *     }
    18271837         * }
Note: See TracChangeset for help on using the changeset viewer.