PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.3
Elementor Website Builder – more than just a page builder v4.2.3
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 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / shortcode.php

shortcode.php in Elementor Website Builder – more than just a page builder 4.2.3, at includes/widgets/shortcode.php

180 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor shortcode widget.
10 *
11 * Elementor widget that insert any shortcodes into the page.
12 *
13 * @since 1.0.0
14 */
15 class Widget_Shortcode extends Widget_Base {
16
17 /**
18 * Get widget name.
19 *
20 * Retrieve shortcode widget name.
21 *
22 * @since 1.0.0
23 * @access public
24 *
25 * @return string Widget name.
26 */
27 public function get_name() {
28 return 'shortcode';
29 }
30
31 /**
32 * Get widget title.
33 *
34 * Retrieve shortcode widget title.
35 *
36 * @since 1.0.0
37 * @access public
38 *
39 * @return string Widget title.
40 */
41 public function get_title() {
42 return esc_html__( 'Shortcode', 'elementor' );
43 }
44
45 /**
46 * Get widget icon.
47 *
48 * Retrieve shortcode widget icon.
49 *
50 * @since 1.0.0
51 * @access public
52 *
53 * @return string Widget icon.
54 */
55 public function get_icon() {
56 return 'eicon-shortcode';
57 }
58
59 /**
60 * Get widget keywords.
61 *
62 * Retrieve the list of keywords the widget belongs to.
63 *
64 * @since 2.1.0
65 * @access public
66 *
67 * @return array Widget keywords.
68 */
69 public function get_keywords() {
70 return [ 'shortcode', 'code' ];
71 }
72
73 /**
74 * Whether the reload preview is required or not.
75 *
76 * Used to determine whether the reload preview is required.
77 *
78 * @since 1.0.0
79 * @access public
80 *
81 * @return bool Whether the reload preview is required.
82 */
83 public function is_reload_preview_required() {
84 return true;
85 }
86
87 public function has_widget_inner_wrapper(): bool {
88 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
89 }
90
91 /**
92 * Register shortcode widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 3.1.0
97 * @access protected
98 */
99 protected function register_controls() {
100 $this->start_controls_section(
101 'section_shortcode',
102 [
103 'label' => esc_html__( 'Shortcode', 'elementor' ),
104 ]
105 );
106
107 $this->add_control(
108 'shortcode',
109 [
110 'label' => esc_html__( 'Enter your shortcode', 'elementor' ),
111 'type' => Controls_Manager::TEXTAREA,
112 'dynamic' => [
113 'active' => true,
114 ],
115 'ai' => [
116 'active' => false,
117 ],
118 'placeholder' => '[gallery id="123" size="medium"]',
119 'default' => '',
120 ]
121 );
122
123 $this->end_controls_section();
124 }
125
126 /**
127 * Render shortcode widget output on the frontend.
128 *
129 * Written in PHP and used to generate the final HTML.
130 *
131 * @since 1.0.0
132 * @access protected
133 */
134 protected function render() {
135 $shortcode = $this->get_settings_for_display( 'shortcode' );
136
137 if ( empty( $shortcode ) ) {
138 return;
139 }
140
141 $shortcode = do_shortcode( shortcode_unautop( $shortcode ) );
142 ?>
143 <div class="elementor-shortcode"><?php echo $shortcode; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
144 <?php
145 }
146
147 /**
148 * Render shortcode widget as plain content.
149 *
150 * Override the default behavior by printing the shortcode instead of rendering it.
151 *
152 * @since 1.0.0
153 * @access public
154 */
155 public function render_plain_content() {
156 // In plain mode, render without shortcode
157 $this->print_unescaped_setting( 'shortcode' );
158 }
159
160 /**
161 * Render shortcode widget output in the editor.
162 *
163 * Written as a Backbone JavaScript template and used to generate the live preview.
164 *
165 * @since 2.9.0
166 * @access protected
167 */
168 protected function content_template() {}
169
170 public function render_markdown(): string {
171 $settings = $this->get_settings_for_display();
172 $shortcode = $settings['shortcode'] ?? '';
173 if ( empty( $shortcode ) ) {
174 return '';
175 }
176 $output = do_shortcode( $shortcode );
177 return Utils::html_to_plain_text( $output );
178 }
179 }
180