PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
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 / read-more.php

read-more.php in Elementor Website Builder – more than just a page builder 4.2.0, at includes/widgets/read-more.php

171 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 HTML widget.
10 *
11 * Elementor widget that insert a custom HTML code into the page.
12 */
13 class Widget_Read_More extends Widget_Base {
14
15 /**
16 * Get widget name.
17 *
18 * Retrieve Read More widget name.
19 *
20 * @since 2.4.0
21 * @access public
22 *
23 * @return string Widget name.
24 */
25 public function get_name() {
26 return 'read-more';
27 }
28
29 /**
30 * Get widget title.
31 *
32 * Retrieve Read More widget title.
33 *
34 * @since 2.4.0
35 * @access public
36 *
37 * @return string Widget title.
38 */
39 public function get_title() {
40 return esc_html__( 'Read More', 'elementor' );
41 }
42
43 /**
44 * Get widget icon.
45 *
46 * Retrieve Read More widget icon.
47 *
48 * @since 2.4.0
49 * @access public
50 *
51 * @return string Widget icon.
52 */
53 public function get_icon() {
54 return 'eicon-post-excerpt';
55 }
56
57 /**
58 * Get widget keywords.
59 *
60 * Retrieve the list of keywords the widget belongs to.
61 *
62 * @since 2.4.0
63 * @access public
64 *
65 * @return array Widget keywords.
66 */
67 public function get_keywords() {
68 return [ 'read', 'more', 'tag', 'excerpt' ];
69 }
70
71 protected function is_dynamic_content(): bool {
72 return false;
73 }
74
75 public function has_widget_inner_wrapper(): bool {
76 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
77 }
78
79 /**
80 * Register HTML widget controls.
81 *
82 * Adds different input fields to allow the user to change and customize the widget settings.
83 *
84 * @since 3.1.0
85 * @access protected
86 */
87 protected function register_controls() {
88 $this->start_controls_section(
89 'section_title',
90 [
91 'label' => esc_html__( 'Read More', 'elementor' ),
92 ]
93 );
94
95 $default_link_text = esc_html__( 'Continue reading', 'elementor' );
96
97 /**
98 * Read More widgets link text.
99 *
100 * Filters the link text in the "Read More" widget.
101 *
102 * This hook can be used to set different default text in the widget.
103 *
104 * @param string $default_link_text The link text in the "Read More" widget. Default is "Continue reading".
105 */
106 $default_link_text = apply_filters( 'elementor/widgets/read_more/default_link_text', $default_link_text );
107
108 $this->add_control(
109 'theme_support',
110 [
111 'type' => Controls_Manager::ALERT,
112 'alert_type' => 'warning',
113 'content' => sprintf(
114 /* translators: %s: The `the_content` function. */
115 esc_html__( 'Note: This widget only affects themes that use `%s` in archive pages.', 'elementor' ),
116 'the_content'
117 ),
118 ]
119 );
120
121 $this->add_control(
122 'link_text',
123 [
124 'label' => esc_html__( 'Read More Text', 'elementor' ),
125 'placeholder' => $default_link_text,
126 'default' => $default_link_text,
127 'dynamic' => [
128 'active' => true,
129 ],
130 ]
131 );
132
133 $this->end_controls_section();
134 }
135
136 /**
137 * Render Read More widget output on the frontend.
138 *
139 * Written in PHP and used to generate the final HTML.
140 *
141 * @access protected
142 */
143 protected function render() {
144 printf( '<!--more %s-->', wp_kses_post( $this->get_settings_for_display( 'link_text' ) ) );
145 }
146
147 /**
148 * Render Read More widget output in the editor.
149 *
150 * Written as a Backbone JavaScript template and used to generate the live preview.
151 *
152 * @since 2.9.0
153 * @access protected
154 */
155 protected function content_template() {
156 ?>
157 <!--more {{ settings.link_text }}-->
158 <?php
159 }
160
161 public function render_markdown(): string {
162 $settings = $this->get_settings_for_display();
163 $text = Utils::html_to_plain_text( $settings['link_text'] ?? 'Read More' );
164 $url = ( $settings['link'] ?? [] )['url'] ?? '';
165 if ( ! empty( $url ) ) {
166 return '[' . $text . '](' . esc_url( $url ) . ')';
167 }
168 return $text;
169 }
170 }
171