PluginProbe
eRecht24 Legal Texts / trunk
eRecht24 Legal Texts vtrunk
4.1.0 4.0.5 4.0.4 4.0.3 trunk 4.0.0 4.0.1 4.0.2
erecht24 / src / Integrations / Elementor.php

Elementor.php in eRecht24 Legal Texts trunk, at src/Integrations/Elementor.php

73 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Optional Elementor integration.
4 *
5 * @package ERecht24LegalText
6 */
7
8 namespace ERecht24LegalText\Integrations;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Registers an Elementor widget when Elementor is active.
14 */
15 final class Elementor {
16
17 /**
18 * Prevent duplicate widget registration when old and new Elementor hooks run.
19 *
20 * @var bool
21 */
22 private $registered = false;
23
24 /**
25 * Register hooks.
26 */
27 public function register_hooks(): void {
28 add_action( 'plugins_loaded', array( $this, 'maybe_register' ), 100 );
29 }
30
31 /**
32 * Register Elementor widget hooks.
33 */
34 public function maybe_register(): void {
35 if ( ! did_action( 'elementor/loaded' ) ) {
36 return;
37 }
38
39 add_action( 'elementor/widgets/register', array( $this, 'register_widget' ) );
40 }
41
42 /**
43 * Register widget(s).
44 *
45 * @param object $widgets_manager Elementor widgets manager.
46 */
47 public function register_widget( $widgets_manager ): void {
48 if ( $this->registered ) {
49 return;
50 }
51
52 if ( ! class_exists( '\Elementor\Widget_Base' ) ) {
53 return;
54 }
55
56 $widgets = array(
57 new Elementor_Widget(),
58 // Legacy alias for widgets placed by the pre-4.0 plugin as 'erecht24'.
59 new Elementor_Widget_Legacy(),
60 );
61
62 foreach ( $widgets as $widget ) {
63 if ( method_exists( $widgets_manager, 'register' ) ) {
64 $widgets_manager->register( $widget );
65 } elseif ( method_exists( $widgets_manager, 'register_widget_type' ) ) {
66 $widgets_manager->register_widget_type( $widget );
67 }
68 }
69
70 $this->registered = true;
71 }
72 }
73