PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.87
WindPress – Tailwind CSS integration for WordPress v3.2.87
3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 All 142 releases
windpress / src / Api / Admin / LocalFileProvider.php

LocalFileProvider.php in WindPress – Tailwind CSS integration for WordPress 3.2.87, at src/Api/Admin/LocalFileProvider.php

50 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the WindPress package.
5 *
6 * (c) Joshua Gugun Siagian <suabahasa@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 declare (strict_types=1);
12 namespace WindPress\WindPress\Api\Admin;
13
14 use WindPressDeps\Symfony\Component\Finder\Finder;
15 use WindPressDeps\Symfony\Component\Finder\Glob;
16 use WindPress\WindPress\Api\AbstractApi;
17 use WindPress\WindPress\Api\ApiInterface;
18 use WP_REST_Request;
19 use WP_REST_Response;
20 use WP_REST_Server;
21 class LocalFileProvider extends AbstractApi implements ApiInterface
22 {
23 public function __construct()
24 {
25 }
26 public function get_prefix(): string
27 {
28 return 'admin/local-file-provider';
29 }
30 public function register_custom_endpoints(): void
31 {
32 register_rest_route(self::API_NAMESPACE, $this->get_prefix() . '/scan', ['methods' => WP_REST_Server::CREATABLE, 'callback' => fn(WP_REST_Request $wprestRequest): WP_REST_Response => $this->scan($wprestRequest), 'permission_callback' => fn(WP_REST_Request $wprestRequest): bool => $this->permission_callback($wprestRequest)]);
33 }
34 public function scan(WP_REST_Request $wprestRequest): WP_REST_Response
35 {
36 $payload = $wprestRequest->get_json_params();
37 $path = $payload['path'];
38 $contents = [];
39 $finder = new Finder();
40 $finder->ignoreUnreadableDirs()->in(\WP_CONTENT_DIR)->files()->followLinks()->path(Glob::toRegex($path));
41 foreach ($finder as $file) {
42 if (!is_readable($file->getPathname())) {
43 continue;
44 }
45 $contents[] = ['name' => $file->getFilename(), 'relative_path' => $file->getRelativePathname(), 'content' => $file->getContents()];
46 }
47 return new WP_REST_Response(['contents' => $contents]);
48 }
49 }
50