PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.91
WindPress – Tailwind CSS integration for WordPress v3.2.91
3.2.91 3.2.92 3.2.90 3.2.89 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 All 146 releases
windpress / src / Abilities / Abilities / DeleteVolumeEntry.php

DeleteVolumeEntry.php in WindPress – Tailwind CSS integration for WordPress 3.2.91, at src/Abilities/Abilities/DeleteVolumeEntry.php

73 lines 2.7 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 <[email protected]>
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\Abilities\Abilities;
13
14 use WindPress\WindPress\Core\Volume;
15 use WP_Error;
16 /**
17 * Delete Volume Entry Ability
18 *
19 * Deletes a file from the WindPress Simple File System.
20 *
21 * @since 3.2.0
22 */
23 class DeleteVolumeEntry
24 {
25 /**
26 * Execute the ability
27 *
28 * @param array $input Input with relative_path and signature
29 * @return array|WP_Error Success status or error
30 */
31 public static function execute($input)
32 {
33 if (!is_array($input)) {
34 return new WP_Error('invalid_input', __('Input must be an object.', 'windpress'), ['status' => 400]);
35 }
36 $relative_path = $input['relative_path'] ?? '';
37 $signature = $input['signature'] ?? '';
38 if (empty($relative_path)) {
39 return new WP_Error('invalid_input', __('Relative path is required.', 'windpress'), ['status' => 400]);
40 }
41 if (empty($signature)) {
42 return new WP_Error('invalid_input', __('Signature is required for security verification.', 'windpress'), ['status' => 400]);
43 }
44 try {
45 // To delete a file, we save an entry with empty content
46 // The Volume::save_entries method handles deletion when content is empty
47 $entry_to_delete = [
48 'name' => basename($relative_path),
49 'relative_path' => $relative_path,
50 'content' => '',
51 // Empty content triggers deletion
52 'handler' => 'internal',
53 'signature' => $signature,
54 ];
55 $result = Volume::save_entries([$entry_to_delete]);
56 if (!empty($result['errors']) || !empty($result['skipped']) || empty($result['deleted'])) {
57 return new WP_Error('delete_failed', __('The entry could not be deleted. Verify the signature and relative path.', 'windpress'), ['status' => empty($result['errors']) ? 400 : 500, 'details' => $result]);
58 }
59 return ['success' => \true, 'message' => sprintf(
60 /* translators: %s: file path */
61 __('File "%s" deleted successfully.', 'windpress'),
62 $relative_path
63 )];
64 } catch (\Throwable $throwable) {
65 return new WP_Error('delete_failed', sprintf(
66 /* translators: %s: error message */
67 __('Failed to delete entry: %s', 'windpress'),
68 $throwable->getMessage()
69 ), ['status' => 500]);
70 }
71 }
72 }
73