Main
LifterLMS Assignments Main Class
Contents
Source Source
File: libraries/lifterlms-cli/src/Main.php
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 | final class Main { /** * Current version of the plugin * * @var string */ public $version = '0.0.1' ; /** * Singleton instance of the class * * @var LifterLMS_CLI */ private static $instance = null; /** * Singleton Instance of the LifterLMS_CLI class * * @since 0.0.1 * * @return LifterLMS_CLI */ public static function instance() { if ( is_null ( self:: $instance ) ) { self:: $instance = new self(); } return self:: $instance ; } /** * Constructor * * @since 0.0.1 * * @return void */ private function __construct() { if ( ! defined( 'LLMS_CLI_VERSION' ) ) { define( 'LLMS_CLI_VERSION' , $this ->version ); } // Get started (after REST). add_action( 'plugins_loaded' , array ( $this , 'init' ) ); } /** * Add all LifterLMS CLI commands * * This includes a separate file so that commands can be included on their own * when generating documentation. * * @since 0.0.1 * * @return void */ public function commands() { require_once LLMS_CLI_PLUGIN_DIR . 'src/commands.php' ; } /** * Register WP_CLI hooks * * Loads all commands and sets up license and addon commands to be aborted * if the LifterLMS Helper is not present. * * @since 0.0.1 * * @return void */ private function hooks() { \WP_CLI::add_hook( 'after_wp_load' , array ( $this , 'commands' ) ); // If the Helper doesn't exist abort command addition. if ( ! class_exists ( 'LifterLMS_Helper' ) ) { $helper_commands = array ( 'license' , 'addon install' , 'addon uninstall' , 'addon activate' , 'addon deactivate' , 'addon update' , ); foreach ( $helper_commands as $command ) { \WP_CLI::add_hook( "before_add_command:llms {$command}" , function ( CommandAddition $command_addition ) { $command_addition ->abort( 'The LifterLMS Helper is required to use this command.' ); } ); } } } /** * Include all required files and classes * * @since [version * * @return void */ public function init() { // Only load if we have the minimum LifterLMS version installed & activated. if ( function_exists( 'llms' ) && version_compare( '5.0.0' , llms()->version, '<=' ) ) { $this ->hooks(); } } } |
Expand full source code Collapse full source code View on GitHub
Methods Methods
- __construct — Constructor
- commands — Add all LifterLMS CLI commands
- hooks — Register WP_CLI hooks
- init — Include all required files and classes
- instance — Singleton Instance of the LifterLMS_CLI class
Changelog Changelog
Version | Description |
---|---|
0.0.1 | Introduced. |