| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Elementor integration loader. | |
| 3 | + * Elementor integration loader | |
| 4 | 4 | * |
| 5 | 5 | * @package TableKit |
| 6 | 6 | */ |
| 7 | + | |
| 7 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 9 | exit; |
| 9 | 10 | } |
| 10 | 11 | |
| @@ -10,13 +11,29 @@ | ||
| 10 | 11 | |
| 11 | 12 | require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitElementorEditor.php'; |
| 12 | 13 | require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitElementorRest.php'; |
| 13 | 14 | |
| 15 | +/** | |
| 16 | + * Bootstraps TableKit's Elementor widget, editor assets, and REST support | |
| 17 | + * once Elementor (and the Pro add-on) are confirmed active. | |
| 18 | + */ | |
| 14 | 19 | class TableKit_Elementor { |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Hooks widget loading into "plugins_loaded", after Elementor itself has loaded. | |
| 23 | + * | |
| 24 | + * @return void | |
| 25 | + */ | |
| 15 | 26 | public static function init(): void { |
| 16 | 27 | add_action( 'plugins_loaded', array( __CLASS__, 'load_widget' ), 20 ); |
| 17 | 28 | } |
| 18 | 29 | |
| 30 | + /** | |
| 31 | + * Loads the Elementor editor integration, widget registration, and REST | |
| 32 | + * support, when Elementor has loaded and the Pro add-on is active. | |
| 33 | + * | |
| 34 | + * @return void | |
| 35 | + */ | |
| 19 | 36 | public static function load_widget(): void { |
| 20 | 37 | if ( ! did_action( 'elementor/loaded' ) ) { |
| 21 | 38 | return; |
| 22 | 39 | } |
| @@ -29,8 +46,14 @@ | ||
| 29 | 46 | add_action( 'elementor/widgets/register', array( __CLASS__, 'register_widget' ) ); |
| 30 | 47 | TableKit_Elementor_Rest::register(); |
| 31 | 48 | } |
| 32 | 49 | |
| 50 | + /** | |
| 51 | + * Registers the TableKit Elementor widget, hooked to "elementor/widgets/register". | |
| 52 | + * | |
| 53 | + * @param \Elementor\Widgets_Manager $widgets_manager Elementor's widget manager. | |
| 54 | + * @return void | |
| 55 | + */ | |
| 33 | 56 | public static function register_widget( $widgets_manager ): void { |
| 34 | 57 | if ( ! self::is_pro_active() ) { |
| 35 | 58 | return; |
| 36 | 59 | } |
| @@ -39,12 +62,22 @@ | ||
| 39 | 62 | |
| 40 | 63 | $widgets_manager->register( new TableKit_Elementor_Widget() ); |
| 41 | 64 | } |
| 42 | 65 | |
| 66 | + /** | |
| 67 | + * Whether Elementor is installed and active. | |
| 68 | + * | |
| 69 | + * @return bool | |
| 70 | + */ | |
| 43 | 71 | public static function is_active(): bool { |
| 44 | 72 | return defined( 'ELEMENTOR_VERSION' ) && class_exists( '\\Elementor\\Plugin' ); |
| 45 | 73 | } |
| 46 | 74 | |
| 75 | + /** | |
| 76 | + * Whether the Pro add-on plugin is active. | |
| 77 | + * | |
| 78 | + * @return bool | |
| 79 | + */ | |
| 47 | 80 | private static function is_pro_active(): bool { |
| 48 | 81 | return defined( 'TABLE_BUILDER_BLOCK_PRO_PLUGIN_VERSION' ); |
| 49 | 82 | } |
| 50 | 83 | } |