PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.4
Elementor Website Builder – more than just a page builder v4.2.4
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
← All changes | includes/widgets/image.php +56 -0 4.0.84.2.4 View file →
@@ -773,8 +773,64 @@
773 773 <?php endif; ?>
774 774 <?php
775 775 }
776 776
777 + public function render_markdown(): string {
778 + $settings = $this->get_settings_for_display();
779 +
780 + if ( empty( $settings['image']['url'] ) ) {
781 + return '';
782 + }
783 +
784 + $url = esc_url( $settings['image']['url'] );
785 + $alt = $this->get_image_alt_text( $settings );
786 + $image_md = '![' . $alt . '](' . $url . ')';
787 +
788 + $link = $this->get_link_url( $settings );
789 +
790 + if ( ! empty( $link['url'] ) && $link['url'] !== $url ) {
791 + $image_md = '[' . $image_md . '](' . esc_url( $link['url'] ) . ')';
792 + }
793 +
794 + $caption = $this->get_visible_caption( $settings );
795 +
796 + if ( ! empty( $caption ) ) {
797 + $image_md .= "\n" . $caption;
798 + }
799 +
800 + return $image_md;
801 + }
802 +
803 + private function get_image_alt_text( array $settings ): string {
804 + if ( empty( $settings['image']['id'] ) ) {
805 + return '';
806 + }
807 +
808 + $attachment_id = $settings['image']['id'];
809 +
810 + $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
811 +
812 + if ( ! empty( $alt ) ) {
813 + return $alt;
814 + }
815 +
816 + $attachment = get_post( $attachment_id );
817 +
818 + if ( ! $attachment ) {
819 + return '';
820 + }
821 +
822 + return $attachment->post_title ?? '';
823 + }
824 +
825 + private function get_visible_caption( array $settings ): string {
826 + if ( ! $this->has_caption( $settings ) ) {
827 + return '';
828 + }
829 +
830 + return Utils::html_to_plain_text( $this->get_caption( $settings ) );
831 + }
832 +
777 833 /**
778 834 * Render image widget output in the editor.
779 835 *
780 836 * Written as a Backbone JavaScript template and used to generate the live preview.