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 / Helpers / Form / Template / Utils / Frontend.php

Frontend.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Helpers/Form/Template/Utils/Frontend.php

97 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Helpers\Form\Template\Utils;
4
5 use Give\Framework\Permissions\Facades\UserPermissions;
6 use Give\Session\SessionDonation\DonationAccessor;
7 use WP_Post;
8
9 class Frontend
10 {
11 /**
12 * This function will return form id.
13 *
14 * There are two ways to auto detect form id:
15 * 1. If global $post is give_forms post type then we assume that we are on donation form page and return id.
16 * 2. if we are not on donation form page and process donation then we will return form id from submitted donation form data.
17 * 3. if we are not on donation form page then we will get donation form id from session.
18 *
19 * This function can be use in donation processing flow i.e from donation form to receipt/failed transaction
20 *
21 * @since 2.7.0
22 * @return int|null
23 * @global WP_Post $post
24 */
25 public static function getFormId()
26 {
27 global $post;
28
29 if ('give_forms' === get_post_type($post)) {
30 return $post->ID;
31 }
32
33 if ($formId = Give()->routeForm->getQueriedFormID()) {
34 return $formId;
35 }
36
37 // Check if admin previewing donation form.
38 if ($formId = self::getPreviewDonationFormId()) {
39 return $formId;
40 }
41
42 // Get form Id on ajax request.
43 if (isset($_REQUEST['give_form_id']) && ($formId = absint($_REQUEST['give_form_id']))) {
44 return $formId;
45 }
46
47 // Get form Id on ajax request.
48 if (isset($_REQUEST['form_id']) && ($formId = absint($_REQUEST['form_id']))) {
49 return $formId;
50 }
51
52 // Get form id on ajax request by donation id.
53 if (
54 ! empty($_REQUEST['donation_id']) &&
55 ($donationId = absint($_REQUEST['donation_id']))
56 ) {
57 return give_get_payment_form_id($donationId);
58 }
59
60 // Get form id from donor purchase session.
61 $session = new DonationAccessor();
62 $formId = $session->getFormId();
63
64 if ($formId) {
65 return $formId;
66 }
67
68 return null;
69 }
70
71 /**
72 * Return form id if admin previewing donation form.
73 * Note: only for internal use. This function can be update or remove in future.
74 *
75 * @since 4.14.0 update permission capability to use facade
76 * @since 2.7.0
77 * @return int|null
78 */
79 public static function getPreviewDonationFormId()
80 {
81 if ( ! UserPermissions::donationForms()->canEdit()) {
82 return null;
83 }
84
85 if (
86 isset($_GET['preview'], $_GET['p'], $_GET['post_type']) &&
87 filter_var($_GET['preview'], FILTER_VALIDATE_BOOLEAN) &&
88 ('give_forms' === give_clean($_GET['post_type'])) &&
89 ($formId = absint($_GET['p']))
90 ) {
91 return $formId;
92 }
93
94 return null;
95 }
96 }
97