#46836 closed defect (bug) (fixed)
Site Health: Allow any callable for a direct site health test.
Reported by: | kraftbj | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Site Health | Keywords: | has-patch site-health |
Focuses: | Cc: |
Description
When trying to extend the site health suite of tests, we should allow any callable to return test results for direct tests (async tests still need to be a string for the ajax action).
Being able to do this would be helpful:
add_filter( 'site_status_tests', 'debugger_site_status_tests' ); function debugger_site_status_tests( $tests ) { $tests['direct']['callable'] = array( 'label' => 'Example Test', 'test' => function(){ return array( 'label' => __( 'Example worked.), 'status' => 'good', 'badge' => array( 'label' => __( 'Testing'), 'color' => 'green', ), 'description' => sprintf( '<p>%s</p>', __( "For direct tests, any callable works." ) ), 'actions' => '', 'test' => 'callable_test', ); } ); return $tests; }
See #46573
Attachments (1)
Change History (9)
This ticket was mentioned in Slack in #core-php by kraft. View the logs.
6 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
6 years ago
#5
@
6 years ago
Seeing the Slack mention of punting this to 5.3. I would be really nice to get this in with the initial release of the feature so plugin developers can utilize callables with their first integration into Site Health instead of needing to special version control.
With this patch, if a developer wants to use a callable, they can do so only with the filter. If this is punted to 5.3, they would have to do extra checks since the presence of the filter is not enough to determine what they can use in the tests array item.
I'm fine owning the ticket, but still would need a committer willing to commit. :)
#6
@
6 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 45234:
Real-life example: https://github.com/Automattic/jetpack/pull/11976
In this case, we already have an existing testing suite that we want to add results of to the Site Health check. Each individual test is a separate protected method of a class and our process for adding new tests is simply add a new
test__
prefixed-function in a file.The current implementation makes it difficult since we would need a globally-scoped function for each test (unless I'm missing something a bit creative).
If we allow any callable, we could either pass an class/method array in the individual test was public or, within the filtering function, dynamically run each test.
e.g.