PluginProbe
The Innovative Form Builder – IvyForms / 0.5
The Innovative Form Builder – IvyForms v0.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Controllers / Changelog / GetChangelogController.php

GetChangelogController.php in The Innovative Form Builder – IvyForms 0.5, at backend/src/Controllers/Changelog/GetChangelogController.php

76 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Changelog;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ForbiddenException;
16 use IvyForms\Common\Sanitizer\Sanitizer;
17 use IvyForms\Controllers\Controller;
18 use IvyForms\Services\Changelog\ChangelogService;
19 use IvyForms\Services\Settings\SettingsService;
20 use WP_REST_Request;
21 use WP_REST_Response;
22
23 /**
24 * Class GetChangelogController
25 *
26 * @package IvyForms\Controllers\Changelog
27 */
28 class GetChangelogController extends Controller
29 {
30 private ChangelogService $changelogService;
31 private SettingsService $settingsService;
32
33 public function __construct(
34 ChangelogService $changelogService,
35 SettingsService $settingsService
36 ) {
37 $this->changelogService = $changelogService;
38 $this->settingsService = $settingsService;
39 }
40 /**
41 * Get changelog data with translated strings
42 *
43 * @param WP_REST_Request $data
44 *
45 * @return WP_REST_Response
46 *
47 * @throws ForbiddenException
48 */
49 public function handle(WP_REST_Request $data): WP_REST_Response
50 {
51 // Verify the nonce
52 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
53
54 $oldVersion = $this->settingsService->getSetting('general', 'changelog_version');
55 $shouldShow = $oldVersion !== IVYFORMS_VERSION;
56
57 if ($shouldShow) {
58 $this->settingsService->setSetting('general', 'changelog_version', IVYFORMS_VERSION);
59 }
60 $changelogData = $this->changelogService->getChangelogData();
61
62 return new WP_REST_Response([
63 'message' => __('Changelog retrieved successfully', 'ivyforms'),
64 'data' => [
65 'oldVersion' => $oldVersion,
66 'version' => IVYFORMS_VERSION,
67 'release_date' => $changelogData['release_date'],
68 'features' => $changelogData['features'],
69 'improvements' => $changelogData['improvements'],
70 'bugfixes' => $changelogData['bugfixes'],
71 'shouldShow' => $shouldShow,
72 ]
73 ], 200);
74 }
75 }
76