| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor HTML widget. |
| 10 |
* |
| 11 |
* Elementor widget that insert a custom HTML code into the page. |
| 12 |
* |
| 13 |
* @since 1.0.0 |
| 14 |
*/ |
| 15 |
class Widget_Html extends Widget_Base { |
| 16 |
|
| 17 |
/** |
| 18 |
* Get widget name. |
| 19 |
* |
| 20 |
* Retrieve HTML 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 'html'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Get widget title. |
| 33 |
* |
| 34 |
* Retrieve HTML 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__( 'HTML', 'elementor' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get widget icon. |
| 47 |
* |
| 48 |
* Retrieve HTML 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-code'; |
| 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 [ 'html', 'code', 'embed', 'script' ]; |
| 71 |
} |
| 72 |
|
| 73 |
protected function is_dynamic_content(): bool { |
| 74 |
return false; |
| 75 |
} |
| 76 |
|
| 77 |
public function show_in_panel() { |
| 78 |
return User::is_current_user_can_use_custom_html(); |
| 79 |
} |
| 80 |
|
| 81 |
public function has_widget_inner_wrapper(): bool { |
| 82 |
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Register HTML widget controls. |
| 87 |
* |
| 88 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 89 |
* |
| 90 |
* @since 3.1.0 |
| 91 |
* @access protected |
| 92 |
*/ |
| 93 |
protected function register_controls() { |
| 94 |
$this->start_controls_section( |
| 95 |
'section_title', |
| 96 |
[ |
| 97 |
'label' => esc_html__( 'HTML Code', 'elementor' ), |
| 98 |
] |
| 99 |
); |
| 100 |
|
| 101 |
$this->add_control( |
| 102 |
'html', |
| 103 |
[ |
| 104 |
'label' => esc_html__( 'HTML Code', 'elementor' ), |
| 105 |
'type' => Controls_Manager::CODE, |
| 106 |
'default' => '', |
| 107 |
'placeholder' => esc_html__( 'Enter your code', 'elementor' ), |
| 108 |
'dynamic' => [ |
| 109 |
'active' => true, |
| 110 |
], |
| 111 |
'is_editable' => User::is_current_user_can_use_custom_html(), |
| 112 |
] |
| 113 |
); |
| 114 |
|
| 115 |
$this->end_controls_section(); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Render HTML widget output on the frontend. |
| 120 |
* |
| 121 |
* Written in PHP and used to generate the final HTML. |
| 122 |
* |
| 123 |
* @since 1.0.0 |
| 124 |
* @access protected |
| 125 |
*/ |
| 126 |
protected function render() { |
| 127 |
$this->print_unescaped_setting( 'html' ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Render HTML widget output in the editor. |
| 132 |
* |
| 133 |
* Written as a Backbone JavaScript template and used to generate the live preview. |
| 134 |
* |
| 135 |
* @since 2.9.0 |
| 136 |
* @access protected |
| 137 |
*/ |
| 138 |
protected function content_template() { |
| 139 |
?> |
| 140 |
{{{ settings.html }}} |
| 141 |
<?php |
| 142 |
} |
| 143 |
|
| 144 |
public function render_markdown(): string { |
| 145 |
$settings = $this->get_settings_for_display(); |
| 146 |
$html = $settings['html'] ?? ''; |
| 147 |
if ( empty( $html ) ) { |
| 148 |
return ''; |
| 149 |
} |
| 150 |
return \Elementor\Modules\MarkdownRender\Html_To_Markdown::convert( $html ); |
| 151 |
} |
| 152 |
} |
| 153 |
|