LifterLMS_Helper

LifterLMS_Helper class


Source Source

File: libraries/lifterlms-helper/class-lifterlms-helper.php

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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
final class LifterLMS_Helper {
 
    /**
     * Current Plugin Version
     *
     * @var string
     */
    public $version = '3.5.0';
 
    /**
     * Singleton instance reference
     *
     * @var null
     */
    protected static $instance = null;
 
    /**
     * Instance of the LLMS_Helper_Upgrader class
     *
     * Use/retrieve via llms_helper()->upgrader().
     *
     * @var null|LLMS_Helper_Upgrader
     */
    private $upgrader = null;
 
    /**
     * Retrieve the main Instance of LifterLMS_Helper
     *
     * @since 3.0.0
     * @since 3.2.0 Use `self::$instance` in favor of `self::$_instance`.
     *
     * @return LifterLMS_Helper
     */
    public static function instance() {
        if ( is_null( self::$instance ) ) {
            self::$instance = new self();
        }
        return self::$instance;
    }
 
    /**
     * Constructor, get things started!
     *
     * @since 1.0.0
     * @since 3.4.0 Only localize when loaded as an independent plugin.
     *
     * @return void
     */
    private function __construct() {
 
        // Define class constants.
        $this->define_constants();
 
        /**
         * When loaded as a library included by the LifterLMS core localization is handled by the LifterLMS core.
         *
         * When the plugin is loaded by itself as a plugin, we must localize it independently.
         */
        if ( ! defined( 'LLMS_HELPER_LIB' ) || ! LLMS_HELPER_LIB ) {
            add_action( 'init', array( $this, 'load_textdomain' ), 0 );
        }
 
        add_action( 'plugins_loaded', array( $this, 'init' ) );
 
    }
 
    /**
     * Inititalize the Plugin
     *
     * @since 1.0.0
     * @since 3.0.0 Unknown.
     * @since 3.2.0 Use `llms()` in favor of deprecated `LLMS()`.
     * @since 3.3.1 Load the upgrader instance in WP_CLI context.
     *
     * @return void
     */
    public function init() {
 
        // Only load if we have the minimum LifterLMS version installed & activated.
        if ( function_exists( 'llms' ) && version_compare( '3.22.0', llms()->version, '<=' ) ) {
 
            $this->includes();
            $this->crons();
 
            if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
                $this->upgrader = LLMS_Helper_Upgrader::instance();
            }
        }
 
    }
 
    /**
     * Schedule and handle cron functions
     *
     * @since 3.0.0
     *
     * @return void
     */
    private function crons() {
 
        add_action( 'llms_helper_check_license_keys', array( 'LLMS_Helper_Keys', 'check_keys' ) );
 
        if ( ! wp_next_scheduled( 'llms_helper_check_license_keys' ) ) {
            wp_schedule_event( time(), 'daily', 'llms_helper_check_license_keys' );
        }
 
    }
 
    /**
     * Define constants for plugin
     *
     * @since 1.0.0
     *
     * @return void
     */
    private function define_constants() {
 
        if ( ! defined( 'LLMS_HELPER_VERSION' ) ) {
            define( 'LLMS_HELPER_VERSION', $this->version );
        }
 
    }
 
    /**
     * Include all clasess required by the plugin
     *
     * @since 1.0.0
     * @since 3.0.0 Include new files.
     *
     * @return void
     */
    private function includes() {
 
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-admin-add-ons.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-assets.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-betas.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-cloned.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-install.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-keys.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-options.php';
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/class-llms-helper-upgrader.php';
 
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/models/class-llms-helper-add-on.php';
 
        require_once LLMS_HELPER_PLUGIN_DIR . 'includes/functions-llms-helper.php';
 
    }
 
    /**
     * Load l10n files.
     *
     * This method is only used when the plugin is loaded as a standalone plugin (for development purposes),
     * otherwise (when loaded as a library from within the LifterLMS core plugin) the localization
     * strings are included into the LifterLMS Core plugin's po/mo files and are localized by the LifterLMS
     * core plugin.
     *
     * Files can be found in the following order (The first loaded file takes priority):
     *   1. WP_LANG_DIR/lifterlms/lifterlms-rest-LOCALE.mo
     *   2. WP_LANG_DIR/plugins/lifterlms-rest-LOCALE.mo
     *   3. WP_CONTENT_DIR/plugins/lifterlms-rest/i18n/lifterlms-rest-LOCALE.mo
     *
     * Note: The function `load_plugin_textdomain()` is not used because the same textdomain as the LifterLMS core
     * is used for this plugin but the file is named `lifterlms-rest` in order to allow using a separate language
     * file for each codebase.
     *
     * @since 2.5.0
     * @since 3.4.0 Updated to the core textdomain.
     *
     * @return void
     */
    public function load_textdomain() {
 
        // Load locale.
        $locale = apply_filters( 'plugin_locale', get_locale(), 'lifterlms' );
 
        // Load from the LifterLMS "safe" directory if it exists.
        load_textdomain( 'lifterlms', WP_LANG_DIR . '/lifterlms/lifterlms-helper-' . $locale . '.mo' );
 
        // Load from the default plugins language file directory.
        load_textdomain( 'lifterlms', WP_LANG_DIR . '/plugins/lifterlms-helper-' . $locale . '.mo' );
 
        // Load from the plugin's language file directory.
        load_textdomain( 'lifterlms', LLMS_HELPER_PLUGIN_DIR . '/i18n/lifterlms-helper-' . $locale . '.mo' );
    }
 
    /**
     * Return the singleton instance of the LLMS_Helper_Upgader
     *
     * @since 3.0.0
     *
     * @return LLMS_Helper_Upgrader
     */
    public function upgrader() {
        return $this->upgrader;
    }
 
}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
3.2.0 Moved class to its own file from lifterlms-helper.php. Replaced class variable $_instance with $instance.
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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