| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 47 | public function publisher() { |
||
| 48 | |||
| 49 | // Ensure we don't have garbage before us. |
||
| 50 | ob_clean(); |
||
| 51 | |||
| 52 | // Check if the current user can `manage_options`. |
||
| 53 | if ( ! current_user_can( 'manage_options' ) ) { |
||
| 54 | wp_send_json_error( 'Access denied.' ); |
||
| 55 | } |
||
| 56 | |||
| 57 | // No actual search parameter was passed, bail out. |
||
| 58 | if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) { |
||
| 59 | wp_send_json_error( 'The q parameter is required.' ); |
||
| 60 | } |
||
| 61 | |||
| 62 | // Get the response. |
||
| 63 | $response = $this->publisher_service->query( $_POST['q'] ); |
||
| 64 | |||
| 65 | // Finally output the response. |
||
| 66 | wp_send_json_success( $response ); |
||
| 67 | |||
| 68 | } |
||
| 69 | |||
| 71 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.