| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor integration loader |
| 4 |
* |
| 5 |
* @package TableKit |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitElementorEditor.php'; |
| 13 |
require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitElementorRest.php'; |
| 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 |
*/ |
| 19 |
class TableKit_Elementor { |
| 20 |
|
| 21 |
/** |
| 22 |
* Hooks widget loading into "plugins_loaded", after Elementor itself has loaded. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public static function init(): void { |
| 27 |
add_action( 'plugins_loaded', array( __CLASS__, 'load_widget' ), 20 ); |
| 28 |
} |
| 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 |
*/ |
| 36 |
public static function load_widget(): void { |
| 37 |
if ( ! did_action( 'elementor/loaded' ) ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ( ! self::is_pro_active() ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
TableKit_Elementor_Editor::register(); |
| 46 |
add_action( 'elementor/widgets/register', array( __CLASS__, 'register_widget' ) ); |
| 47 |
TableKit_Elementor_Rest::register(); |
| 48 |
} |
| 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 |
*/ |
| 56 |
public static function register_widget( $widgets_manager ): void { |
| 57 |
if ( ! self::is_pro_active() ) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitWidget.php'; |
| 62 |
|
| 63 |
$widgets_manager->register( new TableKit_Elementor_Widget() ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Whether Elementor is installed and active. |
| 68 |
* |
| 69 |
* @return bool |
| 70 |
*/ |
| 71 |
public static function is_active(): bool { |
| 72 |
return defined( 'ELEMENTOR_VERSION' ) && class_exists( '\\Elementor\\Plugin' ); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Whether the Pro add-on plugin is active. |
| 77 |
* |
| 78 |
* @return bool |
| 79 |
*/ |
| 80 |
private static function is_pro_active(): bool { |
| 81 |
return defined( 'TABLE_BUILDER_BLOCK_PRO_PLUGIN_VERSION' ); |
| 82 |
} |
| 83 |
} |
| 84 |
|