forked from gocodebox/lifterlms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-llms-staging.php
94 lines (75 loc) · 2.04 KB
/
class-llms-staging.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Handle warnings and notices when staging is enabled.
*
* @package LifterLMS/Classes
*
* @since 3.32.0
* @version 3.32.0
*/
defined( 'ABSPATH' ) || exit;
/**
* LLMS_Staging class..
*
* @since 3.32.0
*/
class LLMS_Staging {
/**
* Static Constructor.
*
* @since 3.32.0
*
* @return void
*/
public static function init() {
add_action( 'admin_menu', array( __CLASS__, 'menu_warning' ) );
add_action( 'admin_init', array( __CLASS__, 'handle_staging_notice_actions' ) );
}
/**
* Handle the action buttons present in the recurring payments staging notice.
*
* @since 3.32.0
*
* @return void
*/
public static function handle_staging_notice_actions() {
if ( ! isset( $_GET['llms-staging-status'] ) || ! isset( $_GET['_llms_staging_nonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_GET['_llms_staging_nonce'], 'llms_staging_status' ) ) {
wp_die( __( 'Action failed. Please refresh the page and retry.', 'lifterlms' ) );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'Cheatin’ huh?', 'lifterlms' ) );
}
if ( 'enable' === $_GET['llms-staging-status'] ) {
LLMS_Site::set_lock_url();
LLMS_Site::update_feature( 'recurring_payments', true );
} elseif ( 'disable' === $_GET['llms-staging-status'] ) {
LLMS_Site::clear_lock_url();
LLMS_Site::update_feature( 'recurring_payments', false );
update_option( 'llms_site_url_ignore', 'yes' );
}
LLMS_Admin_Notices::delete_notice( 'maybe-staging' );
llms_redirect_and_exit( $_SERVER['HTTP_REFERER'] );
}
/**
* Adds a "bubble" to the "Orders" menu item when recurring payments are disabled.
*
* @since 3.32.0
*
* @return void
*/
public static function menu_warning() {
if ( LLMS_Site::get_feature( 'recurring_payments' ) ) {
return;
}
global $menu;
foreach ( $menu as $index => $item ) {
if ( 'edit.php?post_type=llms_order' === $item[2] ) {
$menu[ $index ][0] .= ' <span class="update-plugins">' . esc_html__( 'Staging', 'lifterlms' ) . '</span>';
}
}
}
}
return LLMS_Staging::init();