PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.0-beta1
Elementor Website Builder – more than just a page builder v3.6.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 All 457 releases
elementor / modules / container-converter / module.php

module.php in Elementor Website Builder – more than just a page builder 3.6.0-beta1, at modules/container-converter/module.php

133 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\ContainerConverter;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Controls_Stack;
7 use Elementor\Plugin;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 class Module extends \Elementor\Core\Base\Module {
14
15 // Event name dispatched by the buttons.
16 const EVENT_NAME = 'elementorContainerConverter:convert';
17
18 /**
19 * Retrieve the module name.
20 *
21 * @return string
22 */
23 public function get_name() {
24 return 'container-converter';
25 }
26
27 /**
28 * Determine whether the module is active.
29 *
30 * @return bool
31 */
32 public static function is_active() {
33 return Plugin::$instance->experiments->is_feature_active( 'container' );
34 }
35
36 /**
37 * Enqueue the module scripts.
38 *
39 * @return void
40 */
41 public function enqueue_scripts() {
42 wp_enqueue_script(
43 'container-converter',
44 $this->get_js_assets_url( 'container-converter' ),
45 [ 'elementor-editor' ],
46 ELEMENTOR_VERSION,
47 true
48 );
49 }
50
51 /**
52 * Add a convert button to sections.
53 *
54 * @param \Elementor\Controls_Stack $controls_stack
55 *
56 * @return void
57 */
58 protected function add_section_convert_button( Controls_Stack $controls_stack ) {
59 if ( ! Plugin::$instance->editor->is_edit_mode() ) {
60 return;
61 }
62
63 $controls_stack->start_injection( [
64 'of' => '_title',
65 ] );
66
67 $controls_stack->add_control(
68 'convert_to_container',
69 [
70 'type' => Controls_Manager::BUTTON,
71 'label' => esc_html__( 'Convert to container', 'elementor' ),
72 'text' => esc_html__( 'Convert', 'elementor' ),
73 'button_type' => 'default',
74 'description' => esc_html__( 'Copies all of the selected sections and columns and pastes them in a container beneath the original.', 'elementor' ),
75 'separator' => 'after',
76 'event' => static::EVENT_NAME,
77 ]
78 );
79
80 $controls_stack->end_injection();
81 }
82
83 /**
84 * Add a convert button to page settings.
85 *
86 * @param \Elementor\Controls_Stack $controls_stack
87 *
88 * @return void
89 */
90 protected function add_page_convert_button( Controls_Stack $controls_stack ) {
91 if ( ! Plugin::$instance->editor->is_edit_mode() ) {
92 return;
93 }
94
95 $controls_stack->start_injection( [
96 'of' => 'post_title',
97 'at' => 'before',
98 ] );
99
100 $controls_stack->add_control(
101 'convert_to_container',
102 [
103 'type' => Controls_Manager::BUTTON,
104 'label' => esc_html__( 'Convert to container', 'elementor' ),
105 'text' => esc_html__( 'Convert', 'elementor' ),
106 'button_type' => 'default',
107 'description' => esc_html__( 'Copies all of the selected sections and columns and pastes them in a container beneath the original.', 'elementor' ),
108 'separator' => 'after',
109 'event' => static::EVENT_NAME,
110 ]
111 );
112
113 $controls_stack->end_injection();
114 }
115
116 /**
117 * Initialize the Container-Converter module.
118 *
119 * @return void
120 */
121 public function __construct() {
122 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
123
124 add_action( 'elementor/element/section/section_layout/after_section_end', function ( Controls_Stack $controls_stack ) {
125 $this->add_section_convert_button( $controls_stack );
126 } );
127
128 add_action( 'elementor/documents/register_controls', function ( Controls_Stack $controls_stack ) {
129 $this->add_page_convert_button( $controls_stack );
130 } );
131 }
132 }
133