HEX
Server: Apache/2
System: Linux saturn 4.18.0-477.15.1.lve.2.el8.x86_64 #1 SMP Wed Aug 2 10:43:45 UTC 2023 x86_64
User: centuryt (1072)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/centuryt/public_html/wp-content/themes/rufous/lib/colibriwp/src/Customizer/CustomizerApi.php
<?php


namespace ColibriWP\Theme\Customizer;

use ColibriWP\Theme\Core\Hooks;
use WP_REST_Request;
use WP_REST_Response;

class CustomizerApi {

	const REST_NAMESPACE = 'colibri_theme/v1';

	public function __construct() {
		$that = $this;
		add_action(
			'rest_api_init',
			function () use ( $that ) {
				foreach ( $that->getRoutes() as $route => $data ) {
					$data['callback']            = array( $that, $data['callback'] );
					$data['permission_callback'] = function () {
						return current_user_can( 'edit_theme_options' );
					};
					register_rest_route( static::REST_NAMESPACE, $route, $data );
				}
			}
		);

		Hooks::prefixed_add_filter(
			'customizer_additional_js_data',
			function ( $data ) {
				$data['api_url'] = site_url( '?rest_route=/' . static::REST_NAMESPACE );

				return $data;
			}
		);
	}

	protected function getRoutes() {

		return array(
			'/attachment-data/(?P<id>\d+)' => array(
				'method'   => 'GET',
				'callback' => 'getAttachmentData',
			),
		);

	}

	public function send( $data, $status = '200' ) {
		$reponse = new WP_REST_Response( $data );
		$reponse->set_status( $status );

		return $reponse;
	}

	public function getAttachmentData( WP_REST_Request $request ) {

		$id = $request->get_param( 'id' );

		$url       = wp_get_attachment_url( $id );
		$type      = wp_check_filetype( $url, wp_get_mime_types() );
		$mime_type = $type['type'];

		return $this->send(
			array(
				'url'       => $url,
				'mime_type' => $mime_type,
			)
		);
	}
}