LLMS_Staging

LLMS_Staging class.


Source Source

File: includes/class-llms-staging.php

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
class LLMS_Staging {
 
    /**
     * Static Constructor.
     *
     * @since 3.32.0
     * @since 4.12.0 Add hook on `llms_site_clone_detected` action.
     * @since 4.13.0 Only add actions when recurring payments constant is not defined.
     *               If `LLMS_SITE_IS_CLONE` is defined & true, automatically disable recurring payments.
     *
     * @return void
     */
    public static function init() {
 
        if ( defined( 'LLMS_SITE_IS_CLONE' ) && LLMS_SITE_IS_CLONE ) {
            llms_maybe_define_constant( 'LLMS_SITE_FEATURE_RECURRING_PAYMENTS', false );
        }
 
        if ( ! defined( 'LLMS_SITE_FEATURE_RECURRING_PAYMENTS' ) ) {
            add_action( 'llms_site_clone_detected', array( __CLASS__, 'clone_detected' ) );
            add_action( 'admin_init', array( __CLASS__, 'handle_staging_notice_actions' ) );
        }
 
        add_action( 'admin_menu', array( __CLASS__, 'menu_warning' ) );
 
    }
 
    /**
     * Callback function to automatically disable site features when a clone is detected
     *
     * @since 4.12.0
     * @since 4.13.0 Only disable payments for logged in users on the admin panel when not processing ajax requests.
     *
     * @return void
     */
    public static function clone_detected() {
 
        if ( is_admin() && current_user_can( 'manage_lifterlms' ) && ! wp_doing_ajax() ) {
            self::notice();
            LLMS_Site::update_feature( 'recurring_payments', false );
        }
 
    }
 
    /**
     * Retrieves the HTML for the "warning bubble" displayed in the admin menu when staging mode is active
     *
     * @since 4.12.0
     *
     * @return string
     */
    protected static function get_menu_warning_bubble() {
        return ' <span class="update-plugins">' . esc_html__( 'Staging', 'lifterlms' ) . '</span>';
    }
 
    /**
     * Handle the action buttons present in the recurring payments staging notice.
     *
     * @since 3.32.0
     * @since 3.35.0 Sanitize input data.
     * @since 4.12.0 Use `llms_filter_input()` for retrieval of `$_GET` data.
     * @since 5.9.0 Drop usage of deprecated `FILTER_SANITIZE_STRING`.
     *
     * @return void
     */
    public static function handle_staging_notice_actions() {
 
        if ( ! isset( $_GET['llms-staging-status'] ) || ! isset( $_GET['_llms_staging_nonce'] ) ) {
            return;
        }
 
        if ( ! llms_verify_nonce( '_llms_staging_nonce', 'llms_staging_status', 'GET' ) || ! current_user_can( 'manage_options' ) ) {
            wp_die( __( 'Action failed. Please refresh the page and retry.', 'lifterlms' ) );
        }
 
        $action = llms_filter_input( INPUT_GET, 'llms-staging-status' );
        if ( 'enable' === $action ) {
            LLMS_Site::set_lock_url();
            LLMS_Site::update_feature( 'recurring_payments', true );
        } elseif ( 'disable' === $action ) {
            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' );
 
        if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
            llms_redirect_and_exit( sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) );
        }
 
    }
 
 
 
    /**
     * Adds a "bubble" to the "Orders" menu item when recurring payments are disabled.
     *
     * @since 3.32.0
     * @since 4.12.0 Moved HTML for the warning bubble into it's own method.
     *
     * @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] .= self::get_menu_warning_bubble();
            }
        }
 
    }
 
    /**
     * Output a notice informing the user the site was put into staging mode.
     *
     * @since 4.12.0
     *
     * @return void
     */
    public static function notice() {
 
        $id = 'maybe-staging';
 
        if ( ! LLMS_Admin_Notices::has_notice( $id ) ) {
 
            LLMS_Admin_Notices::add_notice(
                $id,
                array(
                    'type'        => 'info',
                    'dismissible' => false,
                    'remindable'  => false,
                    'template'    => 'admin/notices/staging.php',
                )
            );
 
        }
 
    }
 
}

Top ↑

Methods Methods

  • clone_detected — Callback function to automatically disable site features when a clone is detected
  • get_menu_warning_bubble — Retrieves the HTML for the "warning bubble" displayed in the admin menu when staging mode is active
  • handle_staging_notice_actions — Handle the action buttons present in the recurring payments staging notice.
  • init — Static Constructor.
  • menu_warning — Adds a "bubble" to the "Orders" menu item when recurring payments are disabled.
  • notice — Output a notice informing the user the site was put into staging mode.

Top ↑

Changelog Changelog

Changelog
Version Description
3.32.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.