one-click-accessibility/modules/remediation/classes/route-base.php
2024-12-29 16:45:20 +02:00

56 lines
1.2 KiB
PHP

<?php
namespace EA11y\Modules\Remediation\Classes;
use EA11y\Classes\Database\Exceptions\Missing_Table_Exception;
use EA11y\Classes\Rest\Route;
use EA11y\Modules\Remediation\Database\Page_Entry;
use EA11y\Modules\Remediation\Database\Page_Table;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Route_Base
*/
class Route_Base extends Route {
protected bool $override = false;
protected $auth = true;
protected string $path = '';
public function get_methods(): array {
return [];
}
public function get_endpoint(): string {
return 'remediation/' . $this->get_path();
}
public function get_path(): string {
return $this->path;
}
public function get_name(): string {
return '';
}
public function get_permission_callback( \WP_REST_Request $request ) : bool {
$valid = $this->permission_callback( $request );
return $valid && user_can( $this->current_user_id, 'manage_options' );
}
/**
* @throws Missing_Table_Exception
*/
public function get_page_entry( $url ) {
$page_entry = new Page_Entry( [
'by' => Page_Table::URL,
'value' => $url,
] );
if ( ! $page_entry->exists() ) {
return false;
}
return $page_entry;
}
}