PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Donations / Endpoints / SwitchDonationView.php

SwitchDonationView.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Donations/Endpoints/SwitchDonationView.php

69 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Donations\Endpoints;
4
5 use WP_REST_Request;
6 use WP_REST_Response;
7
8 class SwitchDonationView extends Endpoint
9 {
10 /**
11 * @var string
12 */
13 protected $endpoint = 'admin/donations/view';
14
15 /**
16 * @var string
17 */
18 protected $slug = 'donations';
19
20 /**
21 * @inheritDoc
22 */
23 public function registerRoute()
24 {
25 register_rest_route(
26 'give-api/v2',
27 $this->endpoint,
28 [
29 [
30 'methods' => 'GET',
31 'callback' => [$this, 'handleRequest'],
32 'permission_callback' => [$this, 'permissionsCheck'],
33 ],
34 'args' => [
35 'isLegacy' => [
36 'type' => 'boolean',
37 'required' => true,
38 ]
39 ],
40 ]
41 );
42 }
43
44 /**
45 * @param WP_REST_Request $request
46 * @since 2.20.0
47 *
48 * @return WP_REST_Response
49 */
50 public function handleRequest(WP_REST_Request $request)
51 {
52 $success = true;
53 $isLegacyEnabled = $request->get_param('isLegacy');
54 $userId = get_current_user_id();
55 if($userId)
56 {
57 update_user_meta($userId, sprintf('_give_%s_archive_show_legacy', $this->slug), $isLegacyEnabled);
58 }
59 else
60 {
61 $success = false;
62 }
63
64 return new WP_REST_Response(
65 $success
66 );
67 }
68 }
69