Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/admin.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/*
3
+
Admin code.
4
+
*/
5
+
// Wizard pre-header
6
+
include( PMPRO_DIR . '/adminpages/wizard/save-steps.php' );
7
+
require_once( PMPRO_DIR . '/includes/lib/SendWP/sendwp.php' );
8
+
9
+
/**
10
+
* Redirect to Setup Wizard if the user hasn't been there yet.
11
+
*
12
+
* @since 1.10
13
+
* @since 2.10 Redirects to the Setup Wizard instead.
14
+
*/
15
+
function pmpro_admin_init_redirect_to_dashboard() {
16
+
// Can the current user view the dashboard?
17
+
if ( ! current_user_can( 'manage_options' ) ) {
18
+
return;
19
+
}
20
+
21
+
// Check if we should redirect to the wizard. This should only happen on new installs and once.
22
+
if ( get_option( 'pmpro_wizard_redirect' ) ) {
23
+
delete_option( 'pmpro_wizard_redirect' ); // Deleting right away to avoid redirect loops.
24
+
wp_redirect( admin_url( 'admin.php?page=pmpro-wizard' ) );
25
+
exit;
26
+
}
27
+
}
28
+
add_action( 'admin_init', 'pmpro_admin_init_redirect_to_dashboard' );
29
+
30
+
/**
31
+
* Block Subscribers from accessing the WordPress Dashboard.
32
+
*
33
+
* @since 2.3.4
34
+
*/
35
+
function pmpro_block_dashboard_redirect() {
36
+
if ( pmpro_block_dashboard() ) {
37
+
wp_redirect( pmpro_url( 'account' ) );
38
+
exit;
39
+
}
40
+
}
41
+
add_action( 'admin_init', 'pmpro_block_dashboard_redirect', 9 );
42
+
43
+
/**
44
+
* Is the current user blocked from the dashboard
45
+
* per the advanced setting.
46
+
*
47
+
* @since 2.3
48
+
*/
49
+
function pmpro_block_dashboard() {
50
+
global $current_user, $pagenow;
51
+
52
+
$block_dashboard = get_option( 'pmpro_block_dashboard' );
53
+
54
+
if (
55
+
! wp_doing_ajax()
56
+
&& 'admin-post.php' !== $pagenow
57
+
&& ! empty( $block_dashboard )
58
+
&& ! current_user_can( 'manage_options' )
59
+
&& ! current_user_can( 'edit_users' )
60
+
&& ! current_user_can( 'edit_posts' )
61
+
&& in_array( 'subscriber', (array) $current_user->roles )
62
+
) {
63
+
$block = true;
64
+
} else {
65
+
$block = false;
66
+
}
67
+
$block = apply_filters( 'pmpro_block_dashboard', $block );
68
+
69
+
/**
70
+
* Allow filtering whether to block Dashboard access.
71
+
*
72
+
* @param bool $block Whether to block Dashboard access.
73
+
*/
74
+
return apply_filters( 'pmpro_block_dashboard', $block );
75
+
}
76
+
77
+
/**
78
+
* Handle saving custom metabox order via AJAX.
79
+
*
80
+
* Saves the order of dashboard metaboxes for the current user.
81
+
*
82
+
* @since 3.5
83
+
* @return void
84
+
*/
85
+
function pmpro_save_metabox_order() {
86
+
87
+
// Nonce check.
88
+
if ( ! wp_verify_nonce( $_POST['pmpro_metabox_nonce'], 'pmpro_metabox_order' ) ) {
89
+
wp_send_json_error( __( 'Security check failed.', 'paid-memberships-pro' ) );
90
+
}
91
+
92
+
// Sanitize and validate order.
93
+
$order = sanitize_text_field( wp_unslash( $_POST['order'] ) );
94
+
95
+
// Save to user meta.
96
+
$user_id = get_current_user_id();
97
+
$updated = update_user_meta( $user_id, 'pmpro_dashboard_metabox_order', $order );
98
+
99
+
if ( false === $updated ) {
100
+
wp_send_json_error( __( 'Could not save order.', 'paid-memberships-pro' ) );
101
+
}
102
+
103
+
wp_send_json_success( __( 'Order saved successfully.', 'paid-memberships-pro' ) );
104
+
}
105
+
add_action( 'wp_ajax_pmpro_save_metabox_order', 'pmpro_save_metabox_order' );
106
+
107
+
/**
108
+
* Initialize our Site Health integration and add hooks.
109
+
*
110
+
* @since 2.6.2
111
+
*/
112
+
function pmpro_init_site_health_integration() {
113
+
114
+
$site_health = PMPro_Site_Health::init();
115
+
$site_health->hook();
116
+
}
117
+
118
+
add_action( 'admin_init', 'pmpro_init_site_health_integration' );
119
+
120
+
/**
121
+
* Compare stored and current site URL and decide if we should go into pause mode
122
+
*
123
+
* @since 2.10
124
+
*/
125
+
function pmpro_site_url_check() {
126
+
if ( pmpro_is_paused() ) {
127
+
//We are paused, show a notice.
128
+
add_action( 'admin_notices', 'pmpro_pause_mode_notice' );
129
+
}
130
+
}
131
+
add_action( 'admin_init', 'pmpro_site_url_check' );
132
+
133
+
/**
134
+
* Allows a user to deactivate pause mode and update the last known URL
135
+
*
136
+
* @since 2.10
137
+
*/
138
+
function pmpro_handle_pause_mode_actions() {
139
+
140
+
// Can the current user view the dashboard?
141
+
if ( current_user_can( 'pmpro_manage_pause_mode' ) ) {
142
+
//We're attempting to reactivate all services.
143
+
if( ! empty( $_REQUEST['pmpro-reactivate-services'] ) ) {
144
+
delete_option( 'pmpro_last_known_url' );
145
+
}
146
+
}
147
+
148
+
}
149
+
add_action( 'admin_init', 'pmpro_handle_pause_mode_actions' );
150
+
151
+
/**
152
+
* Display a notice about pause mode being enabled
153
+
*
154
+
* @since 2.10
155
+
*/
156
+
function pmpro_pause_mode_notice() {
157
+
global $current_user;
158
+
if ( isset( $_REQUEST[ 'show_pause_notification' ] ) ) {
159
+
$pmpro_show_pause_notification = (bool)$_REQUEST['show_pause_notification'];
160
+
} else {
161
+
$pmpro_show_pause_notification = false;
162
+
}
163
+
164
+
// Remove notice from dismissed user meta if URL parameter is set.
165
+
$archived_notifications = get_user_meta( $current_user->ID, 'pmpro_archived_notifications', true );
166
+
if ( ! is_array( $archived_notifications ) ) {
167
+
$archived_notifications = array();
168
+
}
169
+
170
+
if ( array_key_exists( 'hide_pause_notification', $archived_notifications ) ) {
171
+
$show_notice = false;
172
+
if ( ! empty( $pmpro_show_pause_notification ) ) {
173
+
unset( $archived_notifications['hide_pause_notification'] );
174
+
update_user_meta( $current_user->ID, 'pmpro_archived_notifications', $archived_notifications );
175
+
$show_notice = true;
176
+
}
177
+
} else {
178
+
$show_notice = true;
179
+
}
180
+
181
+
if ( pmpro_is_paused() && ! empty( $show_notice ) ) {
182
+
// Site is paused. Show the notice. ?>
183
+
<div id="hide_pause_notification" class="notice notice-error pmpro_notification pmpro_notification-error">
184
+
<button type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'pmpro_notification_dismiss_hide_pause_notification' ) ); ?>" class="pmpro-notice-button notice-dismiss" value="hide_pause_notification"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'paid-memberships-pro' ); ?></span></button>
185
+
<div class="pmpro_notification-icon">
186
+
<span class="dashicons dashicons-warning"></span>
187
+
</div>
188
+
<div class="pmpro_notification-content">
189
+
<h3><?php esc_html_e( 'Site URL Change Detected', 'paid-memberships-pro' ); ?></h3>
190
+
<p><?php echo wp_kses_post( sprintf( __( '<strong>Warning:</strong> We have detected that your site URL has changed. All PMPro-related cron jobs and automated services have been disabled. Paid Memberships Pro considers %s to be the site URL.', 'paid-memberships-pro' ), '<code>' . esc_url( get_option( 'pmpro_last_known_url' ) ) . '</code>' ) ); ?></p>
191
+
<?php if ( current_user_can( 'pmpro_manage_pause_mode' ) ) { ?>
192
+
<p>
193
+
<a href='#' id="hide_pause_notification_button" class='button' value="hide_pause_notification"><?php esc_html_e( 'Dismiss notice and keep all services paused', 'paid-memberships-pro' ); ?></a>
194
+
<a href='<?php echo esc_url( admin_url( '?pmpro-reactivate-services=true' ) ); ?>' class='button button-secondary'><?php esc_html_e( 'Update my primary domain and reactivate all services', 'paid-memberships-pro' ); ?></a>
195
+
</p>
196
+
<?php } else { ?>
197
+
<p><?php echo wp_kses_post( __( 'Only users with the <code>pmpro_manage_pause_mode</code> capability are able to deactivate pause mode.', 'paid-memberships-pro' ) ); ?></p>
198
+
<?php } ?>
199
+
</div>
200
+
</div>
201
+
<?php
202
+
}
203
+
}
204
+
205
+
/**
206
+
* Maybe display a notice about spam protection being disabled.
207
+
*
208
+
* @since 2.11
209
+
*/
210
+
function pmpro_spamprotection_notice() {
211
+
global $current_user;
212
+
213
+
// If spam protection is enabled, we are not on a PMPro settings page, or we are on the PMPro advanced settings page, don't show the notice.
214
+
if (
215
+
get_option( 'pmpro_spamprotection' ) ||
216
+
! isset( $_REQUEST['page'] ) ||
217
+
( isset( $_REQUEST['page'] ) && 'pmpro-' !== substr( $_REQUEST['page'], 0, 6 ) ) ||
218
+
( isset( $_REQUEST['page'] ) && 'pmpro-securitysettings' === $_REQUEST['page'] )
219
+
) {
220
+
return;
221
+
}
222
+
223
+
// Get notifications that have been archived.
224
+
$archived_notifications = get_user_meta( $current_user->ID, 'pmpro_archived_notifications', true );
225
+
226
+
// If the user hasn't dismissed the notice, show it.
227
+
if ( ! is_array( $archived_notifications ) || ! array_key_exists( 'hide_spamprotection_notification', $archived_notifications ) ) {
228
+
?>
229
+
<div id="hide_spamprotection_notification" class="notice notice-error pmpro_notification pmpro_notification-error">
230
+
<button type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'pmpro_notification_dismiss_hide_spamprotection_notification' ) ); ?>" class="pmpro-notice-button notice-dismiss" value="hide_spamprotection_notification"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'paid-memberships-pro' ); ?></span></button>
231
+
<div class="pmpro_notification-icon">
232
+
<span class="dashicons dashicons-warning"></span>
233
+
</div>
234
+
<div class="pmpro_notification-content">
235
+
<h3><?php esc_html_e( 'Spam Protection Disabled', 'paid-memberships-pro' ); ?></h3>
236
+
<p><?php esc_html_e( 'Spam protection is currently disabled. This is not recommended. Please enable spam protection on the Security Settings page.', 'paid-memberships-pro' ); ?></p>
237
+
<p>
238
+
<a href='<?php echo esc_url( admin_url( 'admin.php?page=pmpro-securitysettings' ) ); ?>' class='button button-secondary'><?php esc_html_e( 'Go to Security Settings', 'paid-memberships-pro' ); ?></a>
239
+
</p>
240
+
</div>
241
+
</div>
242
+
<?php
243
+
}
244
+
}
245
+
add_action( 'admin_notices', 'pmpro_spamprotection_notice' );
246
+
247
+
/**
248
+
* Remove all WordPress admin notifications from our Wizard area as it's distracting.
249
+
*/
250
+
function pmpro_wizard_remove_admin_notices() {
251
+
if ( is_admin() && ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'pmpro-wizard' ) {
252
+
remove_all_actions( 'admin_notices' );
253
+
remove_all_actions( 'all_admin_notices' );
254
+
}
255
+
}
256
+
add_action( 'in_admin_header', 'pmpro_wizard_remove_admin_notices', 11 );
257
+
258
+
/**
259
+
* Adds the Paid Memberships Pro branded header to the PMPro settings and admin pages.
260
+
*
261
+
* @since 3.0
262
+
*/
263
+
function pmpro_admin_header() {
264
+
// Assume we should not show our header.
265
+
$show_header = false;
266
+
267
+
// Show header on our settings pages.
268
+
if ( ! empty( $_GET['page'] ) && strpos( $_GET['page'], 'pmpro-' ) === 0 ) {
269
+
$show_header = true;
270
+
}
271
+
272
+
// Exclude the wizard.
273
+
if ( ! empty( $_GET['page'] ) && 'pmpro-wizard' === $_GET['page'] ) {
274
+
$show_header = false;
275
+
}
276
+
277
+
if ( empty( $show_header ) ) {
278
+
return;
279
+
} ?>
280
+
<div class="pmpro_banner">
281
+
<div class="pmpro_banner_wrapper">
282
+
<div class="pmpro_logo">
283
+
<h1>
284
+
<span class="screen-reader-text"><?php esc_html_e( 'Paid Memberships Pro', 'paid-memberships-pro' ); ?></span>
285
+
<a target="_blank" rel="noopener noreferrer" href="https://www.paidmembershipspro.com/?utm_source=plugin&utm_medium=pmpro-admin-header&utm_campaign=homepage"><img src="<?php echo esc_url( PMPRO_URL . '/images/Paid-Memberships-Pro.png' ); ?>" width="300" border="0" alt="Paid Memberships Pro(c) - All Rights Reserved" /></a>
286
+
</h1>
287
+
<span class="pmpro_version">v<?php echo esc_html( PMPRO_VERSION ); ?></span>
288
+
</div>
289
+
<div class="pmpro_meta">
290
+
<a target="_blank" rel="noopener noreferrer" href="https://www.paidmembershipspro.com/documentation/?utm_source=plugin&utm_medium=pmpro-admin-header&utm_campaign=documentation"><?php esc_html_e('Documentation', 'paid-memberships-pro' ); ?></a>
291
+
<a target="_blank" href="https://www.paidmembershipspro.com/support/?utm_source=plugin&utm_medium=pmpro-admin-header&utm_campaign=pricing&utm_content=get-support"><?php esc_html_e('Get Support', 'paid-memberships-pro' );?></a>
292
+
293
+
<?php
294
+
// Show notice if paused.
295
+
if ( pmpro_is_paused() ) {
296
+
// Link to reactivate the notification about pause mode if has cap.
297
+
if ( current_user_can( 'pmpro_manage_pause_mode' ) ) { ?>
298
+
<a class="pmpro_paused_tag" href="<?php echo esc_url( add_query_arg( array( 'page' => 'pmpro-dashboard', 'show_pause_notification' => '1' ), admin_url( 'admin.php' ) ) ); ?>"><?php esc_html_e( 'Services Paused', 'paid-memberships-pro' ); ?></a>
299
+
<?php } else { ?>
300
+
<span class="pmpro_paused_tag"><?php esc_html_e( 'Crons Disabled', 'paid-memberships-pro' ); ?></span>
301
+
<?php }
302
+
}
303
+
?>
304
+
<?php if ( pmpro_license_isValid( null, pmpro_license_get_premium_types() ) ) { ?>
305
+
<?php echo wp_kses_post( sprintf(__( '<a class="pmpro_license_tag pmpro_license_tag-valid" href="%s">Valid License</a>', 'paid-memberships-pro' ), esc_url( add_query_arg( array( 'page' => 'pmpro-license' ), admin_url( 'admin.php' ) ) ) ) ); ?>
306
+
<?php } elseif ( ! defined( 'PMPRO_LICENSE_NAG' ) || PMPRO_LICENSE_NAG == true ) { ?>
307
+
<?php echo wp_kses_post( sprintf(__( '<a class="pmpro_license_tag pmpro_license_tag-invalid" href="%s">No License</a>', 'paid-memberships-pro' ), esc_url( add_query_arg( array( 'page' => 'pmpro-license' ), admin_url( 'admin.php' ) ) ) ) ); ?>
308
+
<?php } ?>
309
+
</div> <!-- end pmpro_meta -->
310
+
</div> <!-- end pmpro_banner_wrapper -->
311
+
</div> <!-- end pmpro_banner -->
312
+
<?php
313
+
}
314
+
add_action( 'admin_notices', 'pmpro_admin_header', 1 );
315
+
316
+
/**
317
+
* Replace the default WordPress footer text on PMPro pages.
318
+
*/
319
+
function pmpro_admin_footer_text( $text ) {
320
+
// Show footer on our pages in admin, but not on the block editor.
321
+
if (
322
+
! isset( $_REQUEST['page'] ) ||
323
+
( isset( $_REQUEST['page'] ) && 'pmpro-' !== substr( $_REQUEST['page'], 0, 6 ) )
324
+
) {
325
+
return $text;
326
+
}
327
+
328
+
return sprintf(
329
+
wp_kses(
330
+
/* translators: $1$s - Paid Memberships Pro plugin name; $2$s - testimonial link. */
331
+
__( 'Please <a href="%1$s" target="_blank" rel="noopener noreferrer">submit a testimonial</a> to help others find %2$s. Thank you from the %3$s team!', 'paid-memberships-pro' ),
332
+
[
333
+
'a' => [
334
+
'href' => [],
335
+
'target' => [],
336
+
'rel' => [],
337
+
],
338
+
'p' => [
339
+
'class' => [],
340
+
],
341
+
]
342
+
),
343
+
'https://www.paidmembershipspro.com/submit-testimonial/',
344
+
'Paid Memberships Pro',
345
+
'PMPro'
346
+
);
347
+
}
348
+
add_filter( 'admin_footer_text', 'pmpro_admin_footer_text' );
349
+
350
+
/**
351
+
* Hide non-PMPro notices from PMPro dashboard pages.
352
+
* @since 3.0
353
+
*/
354
+
function pmpro_hide_non_pmpro_notices() {
355
+
global $wp_filter;
356
+
357
+
// Make sure we're on a PMPro page.
358
+
if ( ! isset( $_REQUEST['page'] )
359
+
|| substr( sanitize_text_field( $_REQUEST['page'] ), 0, 6 ) !== 'pmpro-' ) {
360
+
return;
361
+
}
362
+
363
+
// Handle notices added through these hooks.
364
+
$hooks = ['admin_notices', 'all_admin_notices'];
365
+
366
+
foreach ($hooks as $hook) {
367
+
// If no callbacks are registered, skip.
368
+
if ( ! isset( $wp_filter[$hook] ) ) {
369
+
continue;
370
+
}
371
+
372
+
// Loop through the callbacks and remove any that aren't PMPro.
373
+
foreach ($wp_filter[$hook]->callbacks as $priority => $callbacks) {
374
+
foreach ($callbacks as $key => $callback) {
375
+
if ( is_string( $callback['function' ] ) ) {
376
+
// Check the function name.
377
+
// Ex. add_action( 'admin_notices', 'pmpro_admin_notice' );
378
+
$name_to_check = $callback['function'];
379
+
} elseif ( is_array( $callback['function' ] ) && is_string( $callback['function'][0] ) ) {
380
+
// Check the class name for the static method.
381
+
// Ex. add_action( 'admin_notices', array( 'PMPro_Admin', 'admin_notice' ) );
382
+
$name_to_check = $callback['function'][0];
383
+
} elseif ( is_array( $callback['function' ] ) && is_object( $callback['function'][0] ) ) {
384
+
// Check the class name for the non-static method.
385
+
// Ex. add_action( 'admin_notices', array( $some_object, 'admin_notice' ) );
386
+
$name_to_check = get_class( $callback['function'][0] );
387
+
} else {
388
+
// Ex. add_action( 'admin_notices', function() { echo 'Hello World'; } );
389
+
// We don't use closures in PMPro, so we don't need to check for them.
390
+
$name_to_check = '';
391
+
}
392
+
393
+
// Trim slashes for namespaces and lowercase the name.
394
+
$name_to_check = strtolower( trim( $name_to_check, '\\' ) );
395
+
396
+
// If the function name starts with 'pmpro', then we don't want to remove it.
397
+
// Not checking for 'pmpro_' because we have class names like PMProGateway_stripe and want to keep notices from add ons.
398
+
if ( strpos( $name_to_check, 'pmpro' ) !== 0 ) {
399
+
unset( $wp_filter[$hook]->callbacks[$priority][$key] );
400
+
}
401
+
}
402
+
}
403
+
}
404
+
}
405
+
add_action( 'in_admin_header', 'pmpro_hide_non_pmpro_notices' );
406
+