Server : LiteSpeed
System : Linux quebec.us.hostns.io 5.14.0-687.42.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 27 11:55:12 EDT 2026 x86_64
User : gazetufm ( 1431)
PHP Version : 8.1.35
Disable Function : NONE
Directory :  /home2/gazetufm/pelasgus.al/wp-content/plugins/code-snippets/php/REST_API/

📁 Create New:
⬆️ Upload File:
Current Dir [ Writable ] Root [ Writable ]


OR Upload from URL:
URL: Save as:

📄 File: REST_Controller.php

Path: //home2/gazetufm/pelasgus.al/wp-content/plugins/code-snippets/php/REST_API/REST_Controller.php

Size: 1.5 KB

Permissions: 0644

<?php

namespace Code_Snippets\REST_API;

use WP_REST_Request;
use function Code_Snippets\code_snippets;
use const Code_Snippets\REST_API_NAMESPACE;

/**
 * Base class for REST API controllers.
 */
abstract class REST_Controller {

	/**
	 * The version of the REST API this controller belongs to.
	 *
	 * @var string
	 */
	public const VERSION = 0;

	/**
	 * The base route for this controller, relative to the REST API namespace and version.
	 *
	 * @var string
	 */
	public const BASE_ROUTE = '';

	/**
	 * The namespace of this controller's route.
	 *
	 * @var string
	 */
	protected string $namespace;

	/**
	 * Class constructor.
	 */
	public function __construct() {
		assert( ! empty( static::VERSION ), get_class( $this ) . '::VERSION must be set' );
		assert( ! empty( static::BASE_ROUTE ), get_class( $this ) . '::BASE_ROUTE must be set' );

		$this->namespace = REST_API_NAMESPACE . static::VERSION;
		add_action( 'rest_api_init', [ $this, 'register_routes' ] );
	}

	/**
	 * Retrieve this controller's REST API base path, including namespace.
	 *
	 * @return string
	 */
	public static function get_base_route(): string {
		return REST_API_NAMESPACE . static::VERSION . '/' . static::BASE_ROUTE;
	}

	/**
	 * Register REST routes.
	 */
	abstract public function register_routes();

	/**
	 * Default permission callback for this controller's routes.
	 *
	 * @param WP_REST_Request $request Full data about the request.
	 *
	 * @return bool
	 */
	abstract public function permission_callback( WP_REST_Request $request ): bool;
}

← Back to Directory Edit File 🔒 Chmod

WP File Manager