An AJAX endpoint will be created to determine what checks to run for the AJAX Runner. This request will be called first in order to determine what checks will be run. The endpoint will accept a list of check slugs and the plugin slug to be checked. If the plugin to check is not active only static checks can be run.
Acceptance Criteria
- Crate a new AJAX endpoint for the action
plugin_check_get_checks_to_run In the Admin_Ajax class.
- A new WordPress action is created for
wp_ajax_plugin_check_get_checks_to_run that calls a get_checks_to_run method on the Admin_Ajax class.
- The
get_checks_to_run method will first verify the request using the nonce passed. If the nonce is invalid an error response is returned.
- The check slugs passed in the
$_REQUEST['checks'] will be processed to determine what checks to run by filtering the checks slugs passed against the Checks class get_checks() method. Only check slugs that exist as keys in the get_checks() array will be valid. If the $_REQUEST['checks'] is empty, all check slugs from the get_checks() will be used.
- Before returning the check slugs the plugin slug passed will be checked to see if the plugin is active. This is important as if the plugin is not active no runtime checks can be run.
- If
$_REQUEST['checks'] is empty and the plugin is not active, return only the static checks.
- If
$_REQUEST['checks'] contains any runtime check and the plugin is not active, return an error as that check would be disallowed.
- The check slugs array or error message is returned in the response.
- Update the
plugin-check-admin.js so the first request sent after submitting the form is sent to the admin-ajax.php endpoint with the plugin_check_get_checks_to_run action.
- The AJAX request will send the following:
- An array of selected checks. Currently, there are no options to select checks so an empty array will always be sent.
- The plugin name. Required to create the context for the
Checks class.
- A valid nonce.
- If the request fails, a user-friendly error message is displayed on the admin page and no further AJAX requests will be made.
- If the request is successful, the array of Check slugs will be stored in a
checks_to_run variable to be used by future requests.
An AJAX endpoint will be created to determine what checks to run for the AJAX Runner. This request will be called first in order to determine what checks will be run. The endpoint will accept a list of check slugs and the plugin slug to be checked. If the plugin to check is not active only static checks can be run.
Acceptance Criteria
plugin_check_get_checks_to_runIn theAdmin_Ajaxclass.wp_ajax_plugin_check_get_checks_to_runthat calls aget_checks_to_runmethod on theAdmin_Ajaxclass.get_checks_to_runmethod will first verify the request using the nonce passed. If the nonce is invalid an error response is returned.$_REQUEST['checks']will be processed to determine what checks to run by filtering the checks slugs passed against theChecksclassget_checks()method. Only check slugs that exist as keys in theget_checks()array will be valid. If the$_REQUEST['checks']is empty, all check slugs from theget_checks()will be used.$_REQUEST['checks']is empty and the plugin is not active, return only the static checks.$_REQUEST['checks']contains any runtime check and the plugin is not active, return an error as that check would be disallowed.plugin-check-admin.jsso the first request sent after submitting the form is sent to theadmin-ajax.phpendpoint with theplugin_check_get_checks_to_runaction.Checksclass.checks_to_runvariable to be used by future requests.