LLMS_Admin_Notices_Core

Manage core admin notices class


Source Source

File: includes/admin/class.llms.admin.notices.core.php

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
class LLMS_Admin_Notices_Core {
 
    /**
     * Init.
     *
     * @since 3.0.0
     * @since 3.14.8 Add handler for removing dismissed notices.
     * @since 7.1.0 Do not add a callback to remove sidebar notice on `switch_theme` anymore.
     *
     * @return void
     */
    public static function init() {
 
        add_action( 'admin_head', array( __CLASS__, 'maybe_hide_notices' ), 1 );
        add_action( 'current_screen', array( __CLASS__, 'maybe_hide_notices' ), 999 );
 
        add_action( 'current_screen', array( __CLASS__, 'add_init_actions' ) );
 
    }
 
    /**
     * Add actions on different hooks depending on the current screen.
     *
     * Adds later for LLMS Settings screens to accommodate for settings that are updated later in the load cycle.
     *
     * @since 3.0.0
     * @since 4.12.0 Remove hook for deprecated `check_staging()` notice.
     * @since 7.1.0 Do not add a callback to show the missing sidebar support anymore.
     *
     * @return void
     */
    public static function add_init_actions() {
 
        $screen = get_current_screen();
        if ( ! empty( $screen->base ) && 'lifterlms_page_llms-settings' === $screen->base ) {
            $action   = 'lifterlms_settings_notices';
            $priority = 5;
        } else {
            $action   = 'current_screen';
            $priority = 77;
        }
 
        add_action( $action, array( __CLASS__, 'gateways' ), $priority );
 
    }
 
    /**
     * Check for gateways and output gateway notice
     *
     * @since 3.0.0
     * @since 3.13.0 Unknown.
     * @since 4.5.0 Dismiss notice for 2 years instead of 7 days.
     *
     * @return void
     */
    public static function gateways() {
        $id = 'no-gateways';
 
        if ( ! apply_filters( 'llms_admin_notice_no_payment_gateways', llms()->payment_gateways()->has_gateways( true ) ) ) {
            $html  = __( 'No LifterLMS Payment Gateways are currently enabled. Students will only be able to enroll in courses or memberships with free access plans.', 'lifterlms' ) . '<br><br>';
            $html .= sprintf(
                __( 'For starters you can configure manual payments on the %1$sCheckout Settings tab%2$s. Be sure to check out all the available %3$sLifterLMS Payment Gateways%4$s and install one later so that you can start selling your courses and memberships.', 'lifterlms' ),
                '<a href="' . add_query_arg(
                    array(
                        'page' => 'llms-settings',
                        'tab'  => 'checkout',
                    ),
                    admin_url( 'admin.php' )
                ) . '">',
                '</a>',
                '<a href="https://lifterlms.com/product-category/plugins/payment-gateways/" target="_blank">',
                '</a>'
            );
            LLMS_Admin_Notices::add_notice(
                $id,
                $html,
                array(
                    'type'             => 'warning',
                    'dismiss_for_days' => 730, // @TODO: there should be a "forever" setting here.
                    'remindable'       => true,
                )
            );
        } elseif ( LLMS_Admin_Notices::has_notice( $id ) ) {
            LLMS_Admin_Notices::delete_notice( $id );
        }
    }
 
    /**
     * Don't display notices on specific pages
     *
     * @since 3.14.8
     * @since 3.16.14 Unknown.
     *
     * @return void
     */
    public static function maybe_hide_notices() {
 
        $screen = get_current_screen();
 
        if ( $screen && 'admin_page_llms-course-builder' === $screen->id ) {
 
            remove_all_actions( 'admin_notices' ); // 3rd party notices.
            remove_action( 'admin_print_styles', array( 'LLMS_Admin_Notices', 'output_notices' ) ); // Notices output by LifterLMS.
 
        }
 
    }
 
    /**
     * Check theme support for LifterLMS Sidebars.
     *
     * @since 3.0.0
     * @since 3.7.4 Unknown.
     * @since 4.5.0 Use strict comparison for `in_array()`.
     * @deprecated 7.1.0
     *
     * @return void
     */
    public static function sidebar_support() {
 
        _deprecated_function( __METHOD__, '7.1.0' );
 
        $theme = wp_get_theme();
 
        $id = 'sidebars';
 
        if ( ! current_theme_supports( 'lifterlms-sidebars' ) && ! in_array( $theme->get_template(), llms_get_core_supported_themes(), true ) ) {
 
            $msg = sprintf(
                __( '<strong>The current theme, %1$s, does not declare support for LifterLMS Sidebars.</strong> Course and Lesson sidebars may not work as expected. Please see our %2$sintegration guide%3$s or check out our %4$sLaunchPad%5$s theme which is designed specifically for use with LifterLMS.', 'lifterlms' ),
                $theme->get( 'Name' ),
                '</a>',
                '</a>'
            );
 
            LLMS_Admin_Notices::add_notice(
                $id,
                $msg,
                array(
                    'dismissible'      => true,
                    'dismiss_for_days' => 730, // @TODO: there should be a "forever" setting here.
                    'remindable'       => false,
                    'type'             => 'warning',
                )
            );
 
        } elseif ( LLMS_Admin_Notices::has_notice( $id ) ) {
 
            LLMS_Admin_Notices::delete_notice( $id );
 
        }
 
    }
 
    /**
     * Removes the current sidebar notice (if present) and clears notice delay transients.
     *
     * Called when theme is switched.
     *
     * @since 3.14.7
     * @deprecated 7.1.0
     *
     * @return void
     */
    public static function clear_sidebar_notice() {
 
        _deprecated_function( __METHOD__, '7.1.0' );
 
        if ( LLMS_Admin_Notices::has_notice( 'sidebars' ) ) {

Top ↑

Methods Methods

  • add_init_actions — Add actions on different hooks depending on the current screen
  • check_staging — Outputs a notice that allows users to enable or disable automated recurring payments — deprecated
  • clear_sidebar_notice — Removes the current sidebar notice (if present) and clears notice delay transients
  • gateways — Check for gateways and output gateway notice
  • init — Constructor
  • maybe_hide_notices — Don't display notices on specific pages
  • sidebar_support — Check theme support for LifterLMS Sidebars

Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Removed the deprecated LLMS_Admin_Notices_Core::check_staging() method.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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