| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class WordPress\Plugin_Check\Checker\AJAX_Runner |
| 4 |
* |
| 5 |
* @package plugin-check |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WordPress\Plugin_Check\Checker; |
| 9 |
|
| 10 |
use Exception; |
| 11 |
|
| 12 |
/** |
| 13 |
* AJAX Runner class. |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
class AJAX_Runner extends Abstract_Check_Runner { |
| 18 |
|
| 19 |
/** |
| 20 |
* An instance of the Checks class. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* @var Checks |
| 24 |
*/ |
| 25 |
protected $checks; |
| 26 |
|
| 27 |
/** |
| 28 |
* Checks if the current request is an AJAX request for the Plugin Checker. |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* |
| 32 |
* @return bool Returns true if is an AJAX request for the plugin check else false. |
| 33 |
*/ |
| 34 |
public static function is_plugin_check() { |
| 35 |
if ( ! wp_doing_ajax() ) { |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
// PHPCS ignore reason: Nonce check is already happening before this logic in `Admin_AJAX` class. |
| 40 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 41 |
if ( ! isset( $_REQUEST['action'] ) || 'plugin_check_run_checks' !== $_REQUEST['action'] ) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Returns the plugin parameter based on the request. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @return string The plugin parameter. |
| 54 |
* |
| 55 |
* @throws Exception Thrown if the plugin parameter is empty. |
| 56 |
*/ |
| 57 |
protected function get_plugin_param() { |
| 58 |
// PHPCS ignore reason: Nonce check is already happening before this logic in `Admin_AJAX` class. |
| 59 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 60 |
if ( ! isset( $_REQUEST['plugin'] ) ) { |
| 61 |
throw new Exception( |
| 62 |
__( 'Invalid plugin: Plugin parameter must not be empty.', 'plugin-check' ) |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
// PHPCS ignore reason: Nonce check is already happening before this logic in `Admin_AJAX` class. |
| 67 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 68 |
return sanitize_text_field( $_REQUEST['plugin'] ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Returns an array of Check slugs to run based on the request. |
| 73 |
* |
| 74 |
* @since 1.0.0 |
| 75 |
* |
| 76 |
* @return array An array of Check slugs to run. |
| 77 |
*/ |
| 78 |
protected function get_check_slugs_param() { |
| 79 |
$checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); |
| 80 |
$checks = is_null( $checks ) ? array() : $checks; |
| 81 |
|
| 82 |
return $checks; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns an array of Check slugs to exclude based on the request. |
| 87 |
* |
| 88 |
* @since 1.0.0 |
| 89 |
* |
| 90 |
* @return array An array of Check slugs to exclude. |
| 91 |
*/ |
| 92 |
protected function get_check_exclude_slugs_param() { |
| 93 |
$checks = filter_input( INPUT_POST, 'exclude-checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); |
| 94 |
$checks = is_null( $checks ) ? array() : $checks; |
| 95 |
|
| 96 |
return $checks; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Returns the include experimental parameter based on the request. |
| 101 |
* |
| 102 |
* @since 1.0.0 |
| 103 |
* |
| 104 |
* @return bool Returns true to include experimental checks else false. |
| 105 |
*/ |
| 106 |
protected function get_include_experimental_param() { |
| 107 |
$include_experimental = filter_input( INPUT_POST, 'include-experimental', FILTER_VALIDATE_INT ); |
| 108 |
return ( 1 === absint( $include_experimental ) ); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Returns an array of categories for filtering the checks. |
| 113 |
* |
| 114 |
* @since 1.0.0 |
| 115 |
* |
| 116 |
* @return array An array of categories for filtering the checks. |
| 117 |
*/ |
| 118 |
protected function get_categories_param() { |
| 119 |
$categories = filter_input( INPUT_POST, 'categories', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); |
| 120 |
$categories = is_null( $categories ) ? array() : $categories; |
| 121 |
|
| 122 |
return $categories; |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Returns plugin slug parameter. |
| 127 |
* |
| 128 |
* @since 1.2.0 |
| 129 |
* |
| 130 |
* @return string Plugin slug parameter. |
| 131 |
*/ |
| 132 |
protected function get_slug_param() { |
| 133 |
return ''; |
| 134 |
} |
| 135 |
} |
| 136 |
|