|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Actions |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Admin/Actions |
|
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
|
|
|
/** |
|
19
|
|
|
* Hide subscription notice if admin click on "Click here if already renewed" in subscription notice. |
|
20
|
|
|
* |
|
21
|
|
|
* @since 1.7 |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
|
|
function give_hide_subscription_notices() { |
|
25
|
|
|
|
|
26
|
|
|
// Hide subscription notices permanently. |
|
27
|
|
|
if ( ! empty( $_GET['_give_hide_license_notices_permanently'] ) ) { |
|
28
|
|
|
$current_user = wp_get_current_user(); |
|
29
|
|
|
|
|
30
|
|
|
// check previously disabled notice ids. |
|
31
|
|
|
$already_dismiss_notices = ( $already_dismiss_notices = get_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', true ) ) |
|
32
|
|
|
? $already_dismiss_notices |
|
33
|
|
|
: array(); |
|
34
|
|
|
|
|
35
|
|
|
// Get notice id. |
|
36
|
|
|
$notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_permanently'] ); |
|
37
|
|
|
|
|
38
|
|
|
if ( ! in_array( $notice_id, $already_dismiss_notices ) ) { |
|
39
|
|
|
$already_dismiss_notices[] = $notice_id; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// Store subscription ids. |
|
43
|
|
|
update_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', $already_dismiss_notices ); |
|
44
|
|
|
|
|
45
|
|
|
// Redirect user. |
|
46
|
|
|
wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_permanently', $_SERVER['REQUEST_URI'] ) ); |
|
47
|
|
|
exit(); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// Hide subscription notices shortly. |
|
51
|
|
|
if ( ! empty( $_GET['_give_hide_license_notices_shortly'] ) ) { |
|
52
|
|
|
$current_user = wp_get_current_user(); |
|
53
|
|
|
|
|
54
|
|
|
// Get notice id. |
|
55
|
|
|
$notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_shortly'] ); |
|
56
|
|
|
|
|
57
|
|
|
// Transient key name. |
|
58
|
|
|
$transient_key = "_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}"; |
|
59
|
|
|
|
|
60
|
|
|
if ( Give_Cache::get( $transient_key, true ) ) { |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Hide notice for 24 hours. |
|
65
|
|
|
Give_Cache::set( $transient_key, true, DAY_IN_SECONDS, true ); |
|
66
|
|
|
|
|
67
|
|
|
// Redirect user. |
|
68
|
|
|
wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_shortly', $_SERVER['REQUEST_URI'] ) ); |
|
69
|
|
|
exit(); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
add_action( 'admin_init', 'give_hide_subscription_notices' ); |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Load wp editor by ajax. |
|
77
|
|
|
* |
|
78
|
|
|
* @since 1.8 |
|
79
|
|
|
*/ |
|
80
|
|
|
function give_load_wp_editor() { |
|
81
|
|
|
if ( ! isset( $_POST['wp_editor'] ) ) { |
|
82
|
|
|
die(); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$wp_editor = json_decode( base64_decode( $_POST['wp_editor'] ), true ); |
|
86
|
|
|
$wp_editor[2]['textarea_name'] = $_POST['textarea_name']; |
|
87
|
|
|
|
|
88
|
|
|
wp_editor( $wp_editor[0], $_POST['wp_editor_id'], $wp_editor[2] ); |
|
89
|
|
|
|
|
90
|
|
|
die(); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
add_action( 'wp_ajax_give_load_wp_editor', 'give_load_wp_editor' ); |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Redirect admin to clean url give admin pages. |
|
98
|
|
|
* |
|
99
|
|
|
* @since 1.8 |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool |
|
|
|
|
|
|
102
|
|
|
*/ |
|
103
|
|
|
function give_redirect_to_clean_url_admin_pages() { |
|
104
|
|
|
// Give admin pages. |
|
105
|
|
|
$give_pages = array( |
|
106
|
|
|
'give-payment-history', |
|
107
|
|
|
'give-donors', |
|
108
|
|
|
'give-reports' |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
// Get current page. |
|
112
|
|
|
$current_page = isset( $_GET['page'] ) ? esc_attr( $_GET['page'] ) : ''; |
|
113
|
|
|
|
|
114
|
|
|
// Bailout. |
|
115
|
|
|
if ( |
|
116
|
|
|
empty( $current_page ) |
|
117
|
|
|
|| empty( $_GET['_wp_http_referer'] ) |
|
118
|
|
|
|| ! in_array( $current_page, $give_pages ) |
|
119
|
|
|
) { |
|
120
|
|
|
return false; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Verify current page request. |
|
125
|
|
|
* |
|
126
|
|
|
* @since 1.8 |
|
127
|
|
|
*/ |
|
128
|
|
|
$redirect = apply_filters( "give_validate_{$current_page}", true ); |
|
129
|
|
|
|
|
130
|
|
|
if ( $redirect ) { |
|
131
|
|
|
// Redirect. |
|
132
|
|
|
wp_redirect( |
|
133
|
|
|
remove_query_arg( |
|
134
|
|
|
array( '_wp_http_referer', '_wpnonce' ), |
|
135
|
|
|
wp_unslash( $_SERVER['REQUEST_URI'] ) |
|
136
|
|
|
) |
|
137
|
|
|
); |
|
138
|
|
|
exit; |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
add_action( 'admin_init', 'give_redirect_to_clean_url_admin_pages' ); |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Hide License Notice Shortly. |
|
146
|
|
|
* |
|
147
|
|
|
* This code is used with AJAX call to hide license notice for a short period of time |
|
148
|
|
|
* |
|
149
|
|
|
* @since 1.8.9 |
|
150
|
|
|
* |
|
151
|
|
|
* @return void |
|
152
|
|
|
*/ |
|
153
|
|
|
function give_hide_license_notice() { |
|
154
|
|
|
|
|
155
|
|
|
if ( ! isset( $_POST['_give_hide_license_notices_shortly'] ) ) { |
|
156
|
|
|
die(); |
|
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$current_user = wp_get_current_user(); |
|
160
|
|
|
|
|
161
|
|
|
// Get notice id. |
|
162
|
|
|
$notice_id = sanitize_text_field( $_POST['_give_hide_license_notices_shortly'] ); |
|
163
|
|
|
|
|
164
|
|
|
// Transient key name. |
|
165
|
|
|
$transient_key = "_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}"; |
|
166
|
|
|
|
|
167
|
|
|
if ( Give_Cache::get( $transient_key, true ) ) { |
|
168
|
|
|
return; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
// Hide notice for 24 hours. |
|
172
|
|
|
Give_Cache::set( $transient_key, true, DAY_IN_SECONDS, true ); |
|
173
|
|
|
|
|
174
|
|
|
die(); |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
add_action( 'wp_ajax_give_hide_license_notice', 'give_hide_license_notice' ); |
|
179
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.