| @@ -24,9 +24,9 @@ | ||
| 24 | 24 | private array $apis = []; |
| 25 | 25 | public function __construct() |
| 26 | 26 | { |
| 27 | 27 | $this->scan_apis(); |
| 28 | - \add_action('rest_api_init', function () { | |
| 28 | + add_action('rest_api_init', function () { | |
| 29 | 29 | $this->register_apis(); |
| 30 | 30 | }); |
| 31 | 31 | } |
| 32 | 32 | public function scan_apis() |
| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | { |
| 34 | 34 | // Get cached APIs |
| 35 | 35 | $transient_name = 'windpress_scanned_apis_' . WIND_PRESS::VERSION; |
| 36 | 36 | /** @var ApiInterface[]|false $cached */ |
| 37 | - $cached = \get_transient($transient_name); | |
| 37 | + $cached = get_transient($transient_name); | |
| 38 | 38 | if (!\WP_DEBUG && $cached !== \false) { |
| 39 | 39 | $this->apis = $cached; |
| 40 | 40 | return; |
| 41 | 41 | } |
| @@ -45,20 +45,20 @@ | ||
| 45 | 45 | * Add additional places to scan for APIs. |
| 46 | 46 | * |
| 47 | 47 | * @param Finder $finder The Finder instance. |
| 48 | 48 | */ |
| 49 | - \do_action('a!windpress/api/router:before_scan', $finder); | |
| 49 | + do_action('a!windpress/api/router:before_scan', $finder); | |
| 50 | 50 | foreach ($finder as $file) { |
| 51 | 51 | $api_file = $file->getPathname(); |
| 52 | - if (!\is_readable($api_file)) { | |
| 52 | + if (!is_readable($api_file)) { | |
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | require_once $api_file; |
| 56 | 56 | } |
| 57 | 57 | // Find any APIs that extends ApiInterface class |
| 58 | - $declared_classes = \get_declared_classes(); | |
| 58 | + $declared_classes = get_declared_classes(); | |
| 59 | 59 | foreach ($declared_classes as $declared_class) { |
| 60 | - if (!\class_exists($declared_class)) { | |
| 60 | + if (!class_exists($declared_class)) { | |
| 61 | 61 | continue; |
| 62 | 62 | } |
| 63 | 63 | $reflector = new ReflectionClass($declared_class); |
| 64 | 64 | if (!$reflector->isSubclassOf(\WindPress\WindPress\Api\ApiInterface::class)) { |
| @@ -69,14 +69,14 @@ | ||
| 69 | 69 | $api = $reflector->newInstanceWithoutConstructor(); |
| 70 | 70 | $this->apis[$api->get_prefix()] = ['name' => $api->get_prefix(), 'file_path' => $reflector->getFileName(), 'class_name' => $reflector->getName()]; |
| 71 | 71 | } |
| 72 | 72 | // Cache the scanned APIs |
| 73 | - \set_transient($transient_name, $this->apis, \HOUR_IN_SECONDS); | |
| 73 | + set_transient($transient_name, $this->apis, \HOUR_IN_SECONDS); | |
| 74 | 74 | } |
| 75 | 75 | /** |
| 76 | 76 | * Register APIs. |
| 77 | 77 | */ |
| 78 | - public function register_apis() : void | |
| 78 | + public function register_apis(): void | |
| 79 | 79 | { |
| 80 | 80 | /** |
| 81 | 81 | * Filter the APIs before register to WP Rest. |
| 82 | 82 | * |
| @@ -83,9 +83,9 @@ | ||
| 83 | 83 | * @param ApiInterface[] $apis |
| 84 | 84 | * @return ApiInterface[] |
| 85 | 85 | */ |
| 86 | 86 | /** @var ApiInterface[] $apis */ |
| 87 | - $apis = \apply_filters('f!windpress/api/router:register_apis', $this->apis); | |
| 87 | + $apis = apply_filters('f!windpress/api/router:register_apis', $this->apis); | |
| 88 | 88 | foreach ($apis as $api) { |
| 89 | 89 | // Create new instance of API class and register custom endpoints |
| 90 | 90 | /** @var ApiInterface $apiInstance */ |
| 91 | 91 | $apiInstance = new $api['class_name'](); |