PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
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 2.31.0 2.31.1 All 253 releases
give / src / FormMigration / functions.php
functions.php
87 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Give\Framework\Database\DB;
4
5 /**
6 * This function is used to "redirect" shortcodes and blocks
7 * to a migrated form ID, if one exists.
8 *
9 * ex: givewp_migrated_form_id($formId);
10 * ex: givewp_migrated_form_id($formId, $atts['id']);
11 *
12 * @since 3.1.0 Make sure $formId always will receive an integer value
13 * @since 3.0.0
14 *
15 * @param $formId int $formId is used as an "output argument", meaning it is updated without needing to be returned.
16 * @param $extraReference int[] Any additional references to update with the migrated form ID.
17 *
18 * @return void Note: $formId is an "output argument" - not a return value.
19 */
20 function _give_redirect_form_id(&$formId, &...$extraReference) {
21 global $wpdb;
22
23 $formId = absint(DB::get_var(
24 DB::prepare(
25 "
26 SELECT `form_id`
27 FROM `{$wpdb->prefix}give_formmeta`
28 JOIN `{$wpdb->posts}`
29 ON `{$wpdb->posts}`.`ID` = `{$wpdb->prefix}give_formmeta`.`form_id`
30 WHERE `post_status` != 'trash'
31 AND `meta_key` = 'transferredFormId'
32 AND `meta_value` = %d",
33 $formId
34 )
35 )) ?: absint($formId);
36
37 foreach($extraReference as &$reference) {
38 $reference = $formId;
39 }
40 }
41
42 /**
43 * @param $formId
44 *
45 * @return bool
46 */
47 function _give_is_form_migrated($formId) {
48 global $wpdb;
49
50 return (bool) DB::get_var(
51 DB::prepare(
52 "
53 SELECT `form_id`
54 FROM `{$wpdb->prefix}give_formmeta`
55 JOIN `{$wpdb->posts}`
56 ON `{$wpdb->posts}`.`ID` = `{$wpdb->prefix}give_formmeta`.`form_id`
57 WHERE `post_status` != 'trash'
58 AND `meta_key` = 'migratedFormId'
59 AND `meta_value` = %d",
60 $formId
61 )
62 );
63 }
64
65 /**
66 * @param $formId
67 *
68 * @return bool
69 */
70 function _give_is_form_transferred($formId) {
71 global $wpdb;
72
73 return (bool) DB::get_var(
74 DB::prepare(
75 "
76 SELECT `form_id`
77 FROM `{$wpdb->prefix}give_formmeta`
78 JOIN `{$wpdb->posts}`
79 ON `{$wpdb->posts}`.`ID` = `{$wpdb->prefix}give_formmeta`.`form_id`
80 WHERE `post_status` != 'trash'
81 AND `meta_key` = 'transferredFormId'
82 AND `meta_value` = %d",
83 $formId
84 )
85 );
86 }
87