| 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 |
*/ |
| 14 |
class Widget_Read_More extends Widget_Base { |
| 15 |
|
| 16 |
/** |
| 17 |
* Get widget name. |
| 18 |
* |
| 19 |
* Retrieve Read More widget name. |
| 20 |
* |
| 21 |
* @since 2.4.0 |
| 22 |
* @access public |
| 23 |
* |
| 24 |
* @return string Widget name. |
| 25 |
*/ |
| 26 |
public function get_name() { |
| 27 |
return 'read-more'; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Get widget title. |
| 32 |
* |
| 33 |
* Retrieve Read More widget title. |
| 34 |
* |
| 35 |
* @since 2.4.0 |
| 36 |
* @access public |
| 37 |
* |
| 38 |
* @return string Widget title. |
| 39 |
*/ |
| 40 |
public function get_title() { |
| 41 |
return __( 'Read More', 'elementor' ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get widget icon. |
| 46 |
* |
| 47 |
* Retrieve Read More widget icon. |
| 48 |
* |
| 49 |
* @since 2.4.0 |
| 50 |
* @access public |
| 51 |
* |
| 52 |
* @return string Widget icon. |
| 53 |
*/ |
| 54 |
public function get_icon() { |
| 55 |
return 'eicon-post-excerpt'; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get widget keywords. |
| 60 |
* |
| 61 |
* Retrieve the list of keywords the widget belongs to. |
| 62 |
* |
| 63 |
* @since 2.4.0 |
| 64 |
* @access public |
| 65 |
* |
| 66 |
* @return array Widget keywords. |
| 67 |
*/ |
| 68 |
public function get_keywords() { |
| 69 |
return [ 'read', 'more', 'tag', 'excerpt' ]; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Register HTML widget controls. |
| 74 |
* |
| 75 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 76 |
* |
| 77 |
* @since 3.1.0 |
| 78 |
* @access protected |
| 79 |
*/ |
| 80 |
protected function register_controls() { |
| 81 |
$this->start_controls_section( |
| 82 |
'section_title', |
| 83 |
[ |
| 84 |
'label' => __( 'Read More', 'elementor' ), |
| 85 |
] |
| 86 |
); |
| 87 |
|
| 88 |
$default_link_text = apply_filters( 'elementor/widgets/read_more/default_link_text', __( 'Continue reading', 'elementor' ) ); |
| 89 |
|
| 90 |
$this->add_control( |
| 91 |
'theme_support', |
| 92 |
[ |
| 93 |
'type' => Controls_Manager::RAW_HTML, |
| 94 |
'raw' => sprintf( __( 'Note: This widget only affects themes that use `%s` in archive pages.', 'elementor' ), 'the_content' ), |
| 95 |
'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning', |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
$this->add_control( |
| 100 |
'link_text', |
| 101 |
[ |
| 102 |
'label' => __( 'Read More Text', 'elementor' ), |
| 103 |
'placeholder' => $default_link_text, |
| 104 |
'default' => $default_link_text, |
| 105 |
] |
| 106 |
); |
| 107 |
|
| 108 |
$this->end_controls_section(); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Render Read More widget output on the frontend. |
| 113 |
* |
| 114 |
* Written in PHP and used to generate the final HTML. |
| 115 |
* |
| 116 |
* @access protected |
| 117 |
*/ |
| 118 |
protected function render() { |
| 119 |
printf( '<!--more %s-->', $this->get_settings_for_display( 'link_text' ) ); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Render Read More widget output in the editor. |
| 124 |
* |
| 125 |
* Written as a Backbone JavaScript template and used to generate the live preview. |
| 126 |
* |
| 127 |
* @since 2.9.0 |
| 128 |
* @access protected |
| 129 |
*/ |
| 130 |
protected function content_template() { |
| 131 |
?> |
| 132 |
<!--more {{ settings.link_text }}--> |
| 133 |
<?php |
| 134 |
} |
| 135 |
} |
| 136 |
|