Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
/**
* Setup the runtime environment if needed.
*
* @param {Object} data Data object with props passed to form data.
* @since n.e.x.t
*
* @param {Object} data Data object with props passed to form data.
*/
function setUpEnvironment( data ) {
const pluginCheckData = new FormData();
Expand Down Expand Up @@ -65,6 +66,8 @@
* Cleanup the runtime environment.
*
* @since n.e.x.t
*
* @return {Object} The response data.
*/
function cleanUpEnvironment() {
const pluginCheckData = new FormData();
Expand Down Expand Up @@ -129,19 +132,37 @@
/**
* Run Checks.
*
* @since n.e.x.t
*
* @param {Object} data The response data.
*/
async function runChecks( data ) {
for ( let i = 0; i < data.checks.length; i++ ) {
try {
const result = await runCheck( data.plugin, data.checks[ i ] );
console.log( result );
} catch ( e ) {
// Ignore for now.
}
}
}

/**
* Run a single check.
*
* @since n.e.x.t
*
* @param {string} plugin The plugin to check.
* @param {string} check The check to run.
* @return {Object} The check results.
*/
function runChecks( data ) {
function runCheck( plugin, check ) {
const pluginCheckData = new FormData();
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append( 'plugin', data.plugin );
pluginCheckData.append( 'plugin', plugin );
pluginCheckData.append( 'checks[]', check );
pluginCheckData.append( 'action', 'plugin_check_run_checks' );

for ( let i = 0; i < data.checks.length; i++ ) {
pluginCheckData.append( 'checks[]', data.checks[ i ] );
}

return fetch( ajaxurl, {
method: 'POST',
credentials: 'same-origin',
Expand Down
34 changes: 33 additions & 1 deletion includes/Admin/Admin_AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use WP_Error;
use Exception;
use WordPress\Plugin_Check\Checker\AJAX_Runner;
use WordPress\Plugin_Check\Checker\Check_Result;
use WordPress\Plugin_Check\Checker\Runtime_Check;
use WordPress\Plugin_Check\Checker\Runtime_Environment_Setup;
use WordPress\Plugin_Check\Utilities\Plugin_Request_Utility;
Expand Down Expand Up @@ -208,9 +209,40 @@ public function run_checks() {
wp_send_json_error( $valid_nonce, 403 );
}

$runner = Plugin_Request_Utility::get_runner();

if ( is_null( $runner ) ) {
$runner = new AJAX_Runner();
}

// Make sure we are using the correct runner instance.
if ( ! ( $runner instanceof AJAX_Runner ) ) {
wp_send_json_error(
new WP_Error( 'invalid-runner', __( 'AJAX Runner was not initialized correctly.', 'plugin-check' ) ),
500
);
}

$checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
$checks = is_null( $checks ) ? array() : $checks;
$plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_STRING );

try {
$runner->set_check_slugs( $checks );
$runner->set_plugin( $plugin );
$results = $runner->run();
} catch ( Exception $error ) {
wp_send_json_error(
new WP_Error( 'invalid-request', $error->getMessage() ),
400
);
}

wp_send_json_success(
array(
'message' => __( 'Verified!', 'plugin-check' ),
'message' => __( 'Checks run successfully', 'plugin-check' ),
'errors' => $results->get_errors(),
'warnings' => $results->get_warnings(),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.