| Conditions | 2 |
| Paths | 2 |
| Total Lines | 14 |
| Code Lines | 5 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 43 | public function validate_key() { |
||
|
|
|||
| 44 | |||
| 45 | // Ensure we don't have garbage before us. |
||
| 46 | ob_clean(); |
||
| 47 | |||
| 48 | // Check if we have a key. |
||
| 49 | if ( ! isset( $_POST['key'] ) ) { |
||
| 50 | wp_send_json_error( 'The key parameter is required.' ); |
||
| 51 | } |
||
| 52 | |||
| 53 | // Set a response with valid set to true or false according to the key validity. |
||
| 54 | wp_send_json( array( 'valid' => $this->is_valid( $_POST['key'] ) ) ); |
||
| 55 | |||
| 56 | } |
||
| 57 | |||
| 59 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: