PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
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 / Promotions / FreeAddonModal / Controllers / CompleteRestApiEndpoint.php

CompleteRestApiEndpoint.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Promotions/FreeAddonModal/Controllers/CompleteRestApiEndpoint.php

57 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Promotions\FreeAddonModal\Controllers;
4
5 use WP_REST_Request;
6 use WP_REST_Response;
7 use WP_REST_Server;
8
9 class CompleteRestApiEndpoint
10 {
11 public function __invoke()
12 {
13 register_rest_route('give/v1', '/promotions/free-addon-modal/complete', [
14 'methods' => WP_REST_Server::EDITABLE,
15 'callback' => [$this, 'handleModalCompletion'],
16 'permission_callback' => function () {
17 return current_user_can('manage_options');
18 },
19 'args' => [
20 'reason' => [
21 'required' => true,
22 'type' => 'string',
23 'enum' => ['subscribed', 'rejected'],
24 ],
25 ],
26
27 ]);
28 }
29
30 public function handleModalCompletion(WP_REST_Request $request)
31 {
32 $reason = $request['reason'];
33 $iteration = 1;
34
35 if ( 'rejected' === $reason ) {
36 // If the user has rejected the modal before, increase the iteration.
37 $status = get_option('give_free_addon_modal_displayed');
38
39 if ( !empty($status) ) {
40 // The value will be something like rejected:1:1.18.0. The first number is the number of versions the modal has appeared
41 // in, and the second number is the version number of the plugin at the time of last display.
42 list($status, $iteration, $version) = explode(':', $status);
43
44 $iteration++;
45 }
46 }
47
48 update_option('give_free_addon_modal_displayed', implode(':', [
49 $request['reason'],
50 $iteration,
51 GIVE_VERSION,
52 ]));
53
54 return new WP_REST_Response(['success' => true]);
55 }
56 }
57