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 / DonationForms / V2 / Endpoints / Endpoint.php

Endpoint.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/DonationForms/V2/Endpoints/Endpoint.php

68 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonationForms\V2\Endpoints;
4
5 use Give\API\RestRoute;
6 use Give\Framework\Permissions\Facades\UserPermissions;
7 use WP_Error;
8
9 /**
10 * @since 2.19.0
11 */
12 abstract class Endpoint implements RestRoute
13 {
14
15 /**
16 * @var string
17 */
18 protected $endpoint;
19
20 /**
21 * @param string $value
22 *
23 * @return bool
24 */
25 public function validateInt($value)
26 {
27 return filter_var($value, FILTER_VALIDATE_INT);
28 }
29
30 /**
31 * @since 3.14.0
32 * @param string $id
33 * @return bool
34 */
35 public function validatePostType(string $id)
36 {
37 return get_post_type($id) === 'give_forms';
38 }
39
40 /**
41 * Check user permissions
42 * @since 4.14.0 update permission capability to use facade
43 * @return bool|WP_Error
44 */
45 public function permissionsCheck()
46 {
47 if (UserPermissions::donationForms()->canView()) {
48 return true;
49 }
50
51 return new WP_Error(
52 'rest_forbidden',
53 __("You don't have permission to view forms", 'give'),
54 ['status' => is_user_logged_in() ? 403 : 401]
55 );
56 }
57
58 // Sets up the proper HTTP status code for authorization.
59 public function authorizationStatusCode()
60 {
61 if (is_user_logged_in()) {
62 return 403;
63 }
64
65 return 401;
66 }
67 }
68