PluginProbe
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager / trunk
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager vtrunk
0.0.11 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5
cookiez / modules / script / rest / get-scripts.php

get-scripts.php in Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager trunk, at modules/script/rest/get-scripts.php

54 lines 991 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Cookiez\Modules\Script\Rest;
4
5 use Cookiez\Modules\Script\Classes\Route_Base;
6 use Cookiez\Modules\Script\Components\Script;
7
8 use Throwable;
9 use WP_REST_Response;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class Get_Scripts
17 * REST endpoint for retrieving all managed scripts
18 */
19 class Get_Scripts extends Route_Base {
20 public string $path = '';
21
22 public function get_methods(): array {
23 return [ 'GET' ];
24 }
25
26 public function get_name(): string {
27 return 'get-scripts';
28 }
29
30 public function GET(): WP_REST_Response {
31 try {
32 $error = $this->verify_capability();
33
34 if ( $error ) {
35 return $error;
36 }
37
38 $scripts = ( new Script() )->list();
39
40 $formatted = array_map( fn( $dto ) => $dto->to_array(), $scripts );
41
42 return $this->respond_success_json( [
43 'scripts' => $formatted,
44 ] );
45
46 } catch ( Throwable $t ) {
47 return $this->respond_error_json( [
48 'message' => $t->getMessage(),
49 'code' => 'internal_server_error',
50 ], 500 );
51 }
52 }
53 }
54