1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Front-end Actions |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Functions |
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
9
|
|
|
* @since 1.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Hooks Give actions, when present in the $_GET superglobal. Every give_action |
19
|
|
|
* present in $_GET is called using WordPress's do_action function. These |
20
|
|
|
* functions are called on init. |
21
|
|
|
* |
22
|
|
|
* @since 1.0 |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
function give_get_actions() { |
27
|
|
|
|
28
|
|
|
$_get_action = ! empty( $_GET['give_action'] ) ? $_GET['give_action'] : null; |
29
|
|
|
|
30
|
|
|
// Add backward compatibility to give-action param ( $_GET ) |
31
|
|
|
if( empty( $_get_action ) ) { |
32
|
|
|
$_get_action = ! empty( $_GET['give-action'] ) ? $_GET['give-action'] : null; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if ( isset( $_get_action ) ) { |
36
|
|
|
/** |
37
|
|
|
* Fires in WordPress init or admin init, when give_action is present in $_GET. |
38
|
|
|
* |
39
|
|
|
* @since 1.0 |
40
|
|
|
* |
41
|
|
|
* @param array $_GET Array of HTTP GET variables. |
42
|
|
|
*/ |
43
|
|
|
do_action( "give_{$_get_action}", $_GET ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
add_action( 'init', 'give_get_actions' ); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Hooks Give actions, when present in the $_POST super global. Every give_action |
52
|
|
|
* present in $_POST is called using WordPress's do_action function. These |
53
|
|
|
* functions are called on init. |
54
|
|
|
* |
55
|
|
|
* @since 1.0 |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
function give_post_actions() { |
60
|
|
|
|
61
|
|
|
$_post_action = ! empty( $_POST['give_action'] ) ? $_POST['give_action'] : null; |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
// Add backward compatibility to give-action param ( $_POST ) |
65
|
|
|
if( empty( $_post_action ) ) { |
66
|
|
|
$_post_action = ! empty( $_POST['give-action'] ) ? $_POST['give-action'] : null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ( isset( $_post_action ) ) { |
70
|
|
|
/** |
71
|
|
|
* Fires in WordPress init or admin init, when give_action is present in $_POST. |
72
|
|
|
* |
73
|
|
|
* @since 1.0 |
74
|
|
|
* |
75
|
|
|
* @param array $_POST Array of HTTP POST variables. |
76
|
|
|
*/ |
77
|
|
|
do_action( "give_{$_post_action}", $_POST ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
add_action( 'init', 'give_post_actions' ); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Connect WordPress user with Donor. |
86
|
|
|
* |
87
|
|
|
* @since 1.7 |
88
|
|
|
* @param int $user_id User ID |
89
|
|
|
* @param array $user_data User Data |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
function give_connect_donor_to_wpuser( $user_id, $user_data ){ |
93
|
|
|
/* @var Give_Customer $donor */ |
94
|
|
|
$donor = new Give_Customer( $user_data['user_email'] ); |
95
|
|
|
|
96
|
|
|
// Validate donor id and check if do nor is already connect to wp user or not. |
97
|
|
|
if( $donor->id && ! $donor->user_id ) { |
98
|
|
|
|
99
|
|
|
// Update donor user_id. |
100
|
|
|
if( $donor->update( array( 'user_id' => $user_id ) ) ) { |
101
|
|
|
$donor_note = sprintf( esc_html__( 'WordPress user #%d is connected to #%d', 'give' ), $user_id, $donor->id ); |
102
|
|
|
$donor->add_note( $donor_note ); |
103
|
|
|
|
104
|
|
|
// Update user_id meta in payments. |
105
|
|
|
if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) { |
106
|
|
|
foreach ( $donations as $donation ) { |
107
|
|
|
update_post_meta( $donation, '_give_payment_user_id', $user_id ); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
add_action( 'give_insert_user', 'give_connect_donor_to_wpuser', 10, 2 ); |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Setup site home url check |
118
|
|
|
* |
119
|
|
|
* Note: if location of site changes then run cron to validate licenses |
120
|
|
|
* |
121
|
|
|
* @since 1.7 |
122
|
|
|
* @return void |
123
|
|
|
*/ |
124
|
|
|
function give_validate_license_when_site_migrated() { |
125
|
|
|
// Store current site address if not already stored. |
126
|
|
|
$homeurl = home_url(); |
127
|
|
|
if( ! get_option( 'give_site_address_before_migrate' ) ) { |
128
|
|
|
// Update site address. |
129
|
|
|
update_option( 'give_site_address_before_migrate', $homeurl ); |
130
|
|
|
|
131
|
|
|
return; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if( $homeurl !== get_option( 'give_site_address_before_migrate' ) ) { |
135
|
|
|
// Immediately run cron. |
136
|
|
|
wp_schedule_single_event( time() , 'give_validate_license_when_site_migrated' ); |
137
|
|
|
|
138
|
|
|
// Update site address. |
139
|
|
|
update_option( 'give_site_address_before_migrate', home_url() ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
add_action( 'init', 'give_validate_license_when_site_migrated' ); |
144
|
|
|
add_action( 'admin_init', 'give_validate_license_when_site_migrated' ); |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Processing after donor batch export complete |
149
|
|
|
* |
150
|
|
|
* @since 1.8 |
151
|
|
|
* @param $data |
152
|
|
|
*/ |
153
|
|
|
function give_donor_batch_export_complete( $data ) { |
154
|
|
|
// Remove donor ids cache. |
155
|
|
|
if( |
156
|
|
|
isset( $data['class'] ) |
157
|
|
|
&& 'Give_Batch_Customers_Export' === $data['class'] |
158
|
|
|
&& ! empty( $data['forms'] ) |
159
|
|
|
&& isset( $data['give_export_option']['query_id'] ) |
160
|
|
|
) { |
161
|
|
|
Give_Cache::delete( Give_Cache::get_key( $data['give_export_option']['query_id'] ) ); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
add_action('give_file_export_complete', 'give_donor_batch_export_complete' ); |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Print css for wordpress setting pages. |
168
|
|
|
* |
169
|
|
|
* @since 1.8.7 |
170
|
|
|
*/ |
171
|
|
|
function give_admin_quick_css() { |
172
|
|
|
/* @var WP_Screen $screen */ |
173
|
|
|
$screen = get_current_screen(); |
174
|
|
|
|
175
|
|
|
if( ! ( $screen instanceof WP_Screen ) ) { |
|
|
|
|
176
|
|
|
return false; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
switch ( true ) { |
180
|
|
|
case ( 'plugins' === $screen->base ): |
181
|
|
|
?> |
182
|
|
|
<style> |
183
|
|
|
tr.active.update + tr.give-addon-notice-tr td{ |
184
|
|
|
box-shadow:none; |
185
|
|
|
-webkit-box-shadow:none; |
186
|
|
|
} |
187
|
|
|
tr.active + tr.give-addon-notice-tr td{ |
188
|
|
|
position: relative; |
189
|
|
|
top:-1px; |
190
|
|
|
} |
191
|
|
|
tr.active + tr.give-addon-notice-tr .notice{ |
192
|
|
|
margin: 5px 20px 15px 40px; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
tr.give-addon-notice-tr .dashicons { |
196
|
|
|
color: #f56e28; |
197
|
|
|
} |
198
|
|
|
tr.give-addon-notice-tr td{ |
199
|
|
|
border-left: 4px solid #00a0d2; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
tr.give-addon-notice-tr td{ |
203
|
|
|
padding: 0!important; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
tr.active.update + tr.give-addon-notice-tr .notice{ |
207
|
|
|
margin: 5px 20px 5px 40px; |
208
|
|
|
} |
209
|
|
|
</style> |
210
|
|
|
<?php |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
add_action( 'admin_head', 'give_admin_quick_css' ); |
214
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.