# cookiez/trunk/modules/script/rest/get-scripts.php

Cookie Consent – GDPR &amp; CCPA Cookie Banner &amp; Consent Manager, version trunk. 54 lines.

- Page: https://pluginprobe.com/plugins/cookiez/trunk/code/modules/script/rest/get-scripts.php
- Raw: https://pluginprobe.com/plugins/cookiez/trunk/raw/modules/script/rest/get-scripts.php
- Modified: 2026-05-18T12:03:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/cookiez/trunk/code/modules/script/rest/get-scripts.php#L10-L20`.

```php
<?php

namespace Cookiez\Modules\Script\Rest;

use Cookiez\Modules\Script\Classes\Route_Base;
use Cookiez\Modules\Script\Components\Script;

use Throwable;
use WP_REST_Response;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Get_Scripts
 * REST endpoint for retrieving all managed scripts
 */
class Get_Scripts extends Route_Base {
	public string $path = '';

	public function get_methods(): array {
		return [ 'GET' ];
	}

	public function get_name(): string {
		return 'get-scripts';
	}

	public function GET(): WP_REST_Response {
		try {
			$error = $this->verify_capability();

			if ( $error ) {
				return $error;
			}

			$scripts = ( new Script() )->list();

			$formatted = array_map( fn( $dto ) => $dto->to_array(), $scripts );

			return $this->respond_success_json( [
				'scripts' => $formatted,
			] );

		} catch ( Throwable $t ) {
			return $this->respond_error_json( [
				'message' => $t->getMessage(),
				'code' => 'internal_server_error',
			], 500 );
		}
	}
}

```
