diff --git a/includes/Admin/Admin_AJAX.php b/includes/Admin/Admin_AJAX.php index 724edb1d1..288d8dea1 100644 --- a/includes/Admin/Admin_AJAX.php +++ b/includes/Admin/Admin_AJAX.php @@ -94,22 +94,10 @@ public function set_up_environment() { if ( is_wp_error( $valid_request ) ) { wp_send_json_error( $valid_request, 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 ); - $plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + $runner = $this->get_runner(); + $checks = $this->get_checks(); + $plugin = $this->get_plugin(); try { $runner->set_check_slugs( $checks ); @@ -189,22 +177,9 @@ public function get_checks_to_run() { wp_send_json_error( $valid_request, 403 ); } - $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_FULL_SPECIAL_CHARS ); - $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' ) ), - 403 - ); - } + $runner = $this->get_runner(); + $checks = $this->get_checks(); + $plugin = $this->get_plugin(); try { $runner->set_check_slugs( $checks ); @@ -240,23 +215,9 @@ public function run_checks() { wp_send_json_error( $valid_request, 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_FULL_SPECIAL_CHARS ); + $runner = $this->get_runner(); + $checks = $this->get_checks(); + $plugin = $this->get_plugin(); try { $runner->set_check_slugs( $checks ); @@ -278,6 +239,48 @@ public function run_checks() { ); } + + /** + * Get the AJAX_Runner runner. + * + * @since n.e.x.t + * + * @return AJAX_Runner + */ + protected function get_runner() { + $runner = Plugin_Request_Utility::get_runner(); + + if ( ! ( $runner instanceof AJAX_Runner ) ) { + $runner = new AJAX_Runner(); + } + + return $runner; + } + + /** + * Get array of checks to run. + * + * @since n.e.x.t + * + * @return array + */ + protected function get_checks() { + $checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); + + return is_null( $checks ) ? array() : (array) $checks; + } + + /** + * Get requested plugin. + * + * @since n.e.x.t + * + * @return string + */ + protected function get_plugin() { + return filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + } + /** * Verify the request. *