class ET_Builder_Module_Image extends ET_Builder_Module {
$this->name = et_builder_i18n( 'Image' );
$this->plural = esc_html__( 'Images', 'et_builder' );
$this->slug = 'et_pb_image';
$this->vb_support = 'on';
$this->settings_modal_toggles = array(
'main_content' => et_builder_i18n( 'Image' ),
'link' => et_builder_i18n( 'Link' ),
'overlay' => et_builder_i18n( 'Overlay' ),
'alignment' => esc_html__( 'Alignment', 'et_builder' ),
'title' => et_builder_i18n( 'Sizing' ),
'title' => esc_html__( 'Animation', 'et_builder' ),
'title' => esc_html__( 'Attributes', 'et_builder' ),
$this->advanced_fields = array(
'margin_padding' => array(
'important' => array( 'custom_margin' ),
'border_radii' => '%%order_class%% .et_pb_image_wrap',
'border_styles' => '%%order_class%% .et_pb_image_wrap',
'main' => '%%order_class%% .et_pb_image_wrap',
'depends_show_if' => 'off',
'depends_show_if' => 'off',
'main' => '%%order_class%% .et_pb_image_wrap img',
$this->help_videos = array(
'name' => esc_html__( 'An introduction to the Image module', 'et_builder' ),
'label' => et_builder_i18n( 'Image' ),
'option_category' => 'basic_option',
'upload_button_text' => et_builder_i18n( 'Upload an image' ),
'choose_text' => esc_attr__( 'Choose an Image', 'et_builder' ),
'update_text' => esc_attr__( 'Set As Image', 'et_builder' ),
'description' => esc_html__( 'Upload your desired image, or type in the URL to the image you would like to display.', 'et_builder' ),
'toggle_slug' => 'main_content',
'dynamic_content' => 'image',
'mobile_options' => true,
'label' => esc_html__( 'Image Alternative Text', 'et_builder' ),
'option_category' => 'basic_option',
'depends_show_if' => 'on',
'description' => esc_html__( 'This defines the HTML ALT text. A short description of your image can be placed here.', 'et_builder' ),
'tab_slug' => 'custom_css',
'toggle_slug' => 'attributes',
'dynamic_content' => 'text',
'label' => esc_html__( 'Image Title Text', 'et_builder' ),
'option_category' => 'basic_option',
'depends_show_if' => 'on',
'description' => esc_html__( 'This defines the HTML Title text.', 'et_builder' ),
'tab_slug' => 'custom_css',
'toggle_slug' => 'attributes',
'dynamic_content' => 'text',
'show_in_lightbox' => array(
'label' => esc_html__( 'Open in Lightbox', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'off' => et_builder_i18n( 'No' ),
'on' => et_builder_i18n( 'Yes' ),
'default_on_front' => 'off',
'description' => esc_html__( 'Here you can choose whether or not the image should open in Lightbox. Note: if you select to open the image in Lightbox, url options below will be ignored.', 'et_builder' ),
'label' => esc_html__( 'Image Link URL', 'et_builder' ),
'option_category' => 'basic_option',
'depends_show_if' => 'off',
'description' => esc_html__( 'If you would like your image to be a link, input your destination URL here. No link will be created if this field is left blank.', 'et_builder' ),
'dynamic_content' => 'url',
'url_new_window' => array(
'label' => esc_html__( 'Image Link Target', 'et_builder' ),
'option_category' => 'configuration',
'off' => esc_html__( 'In The Same Window', 'et_builder' ),
'on' => esc_html__( 'In The New Tab', 'et_builder' ),
'default_on_front' => 'off',
'depends_show_if' => 'off',
'description' => esc_html__( 'Here you can choose whether or not your link opens in a new window', 'et_builder' ),
'label' => esc_html__( 'Image Overlay', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'layout',
'off' => et_builder_i18n( 'Off' ),
'on' => et_builder_i18n( 'On' ),
'default_on_front' => 'off',
'function.showImageUseOverlayField' => 'on',
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'description' => esc_html__( 'If enabled, an overlay color and icon will be displayed when a visitors hovers over the image', 'et_builder' ),
'overlay_icon_color' => array(
'label' => esc_html__( 'Overlay Icon Color', 'et_builder' ),
'depends_show_if' => 'on',
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'description' => esc_html__( 'Here you can define a custom color for the overlay icon', 'et_builder' ),
'mobile_options' => true,
'hover_overlay_color' => array(
'label' => esc_html__( 'Hover Overlay Color', 'et_builder' ),
'depends_show_if' => 'on',
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'description' => esc_html__( 'Here you can define a custom color for the overlay', 'et_builder' ),
'mobile_options' => true,
'label' => esc_html__( 'Hover Icon Picker', 'et_builder' ),
'option_category' => 'configuration',
'class' => array( 'et-pb-font-icon' ),
'depends_show_if' => 'on',
'tab_slug' => 'advanced',
'toggle_slug' => 'overlay',
'description' => esc_html__( 'Here you can define a custom icon for the overlay', 'et_builder' ),
'mobile_options' => true,
'show_bottom_space' => array(
'label' => esc_html__( 'Show Space Below The Image', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'layout',
'on' => et_builder_i18n( 'Yes' ),
'off' => et_builder_i18n( 'No' ),
'default_on_front' => 'on',
'tab_slug' => 'advanced',
'toggle_slug' => 'margin_padding',
'description' => esc_html__( 'Here you can choose whether or not the image should have a space below it.', 'et_builder' ),
'mobile_options' => true,
'label' => esc_html__( 'Image Alignment', 'et_builder' ),
'option_category' => 'layout',
'options' => et_builder_get_text_orientation_options( array( 'justified' ) ),
'default_on_front' => 'left',
'tab_slug' => 'advanced',
'toggle_slug' => 'alignment',
'description' => esc_html__( 'Here you can choose the image alignment.', 'et_builder' ),
'options_icon' => 'module_align',
'mobile_options' => true,
'force_fullwidth' => array(
'label' => esc_html__( 'Force Fullwidth', 'et_builder' ),
'description' => esc_html__( "When enabled, this will force your image to extend 100% of the width of the column it's in.", 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'layout',
'off' => et_builder_i18n( 'No' ),
'on' => et_builder_i18n( 'Yes' ),
'default_on_front' => 'off',
'tab_slug' => 'advanced',
'toggle_slug' => 'width',
public function get_alignment( $device = 'desktop' ) {
$is_desktop = 'desktop' === $device;
$suffix = ! $is_desktop ? "_{$device}" : '';
$alignment = $is_desktop && isset( $this->props['align'] ) ? $this->props['align'] : '';
if ( ! $is_desktop && et_pb_responsive_options()->is_responsive_enabled( $this->props, 'align' ) ) {
$alignment = et_pb_responsive_options()->get_any_value( $this->props, "align{$suffix}" );
return et_pb_get_alignment( $alignment );
* Renders the module output.
* @param array $attrs List of attributes.
* @param string $content Content being processed.
* @param string $render_slug Slug of module that is used for rendering output.
public function render( $attrs, $content, $render_slug ) {
$sticky = et_pb_sticky_options();
$multi_view = et_pb_multi_view_options( $this );
$src = $this->props['src'];
$alt = $this->props['alt'];
$title_text = $this->props['title_text'];
$url = $this->props['url'];
$url_new_window = $this->props['url_new_window'];
$show_in_lightbox = $this->props['show_in_lightbox'];
$align = $this->get_alignment();
$align_tablet = $this->get_alignment( 'tablet' );
$align_phone = $this->get_alignment( 'phone' );
$force_fullwidth = $this->props['force_fullwidth'];
$hover_icon = $this->props['hover_icon'];
$hover_icon_tablet = $this->props['hover_icon_tablet'];
$hover_icon_phone = $this->props['hover_icon_phone'];
$hover_icon_sticky = $sticky->get_value( 'hover_icon', $this->props );
$use_overlay = $this->props['use_overlay'];
$animation_style = $this->props['animation_style'];
$box_shadow_style = self::$_->array_get( $this->props, 'box_shadow_style', '' );
$video_background = $this->video_background();
$parallax_image_background = $this->get_parallax_image_background();
$show_bottom_space = $this->props['show_bottom_space'];
$show_bottom_space_values = et_pb_responsive_options()->get_property_values( $this->props, 'show_bottom_space' );
$show_bottom_space_tablet = isset( $show_bottom_space_values['tablet'] ) ? $show_bottom_space_values['tablet'] : '';
$show_bottom_space_phone = isset( $show_bottom_space_values['phone'] ) ? $show_bottom_space_values['phone'] : '';
// Handle svg image behaviour
$src_pathinfo = pathinfo( $src );
$is_src_svg = isset( $src_pathinfo['extension'] ) ? 'svg' === $src_pathinfo['extension'] : false;
// overlay can be applied only if image has link or if lightbox enabled
$is_overlay_applied = 'on' === $use_overlay && ( 'on' === $show_in_lightbox || ( 'off' === $show_in_lightbox && '' !== $url ) ) ? 'on' : 'off';
if ( 'on' === $force_fullwidth ) {
'selector' => '%%order_class%%',
'declaration' => 'width: 100%; max-width: 100% !important;',
ET_Builder_Element::set_style( $render_slug, $el_style );
'selector' => '%%order_class%% .et_pb_image_wrap, %%order_class%% img',
'declaration' => 'width: 100%;',
ET_Builder_Element::set_style( $render_slug, $el_style );
// Responsive Image Alignment.
// Set CSS properties and values for the image alignment.
// 1. Text Align is necessary, just set it from current image alignment value.
// 2. Margin {Side} is optional. Used to pull the image to right/left side.
// 3. Margin Left and Right are optional. Used by Center to reset custom margin of point 2.
'text-align' => esc_html( $align ),
"margin-{$align}" => ! empty( $align ) && 'center' !== $align ? '0' : '',
if ( ! empty( $align_tablet ) ) {
$align_values['tablet'] = array(
'text-align' => esc_html( $align_tablet ),
'margin-left' => 'left' !== $align_tablet ? 'auto' : '',
'margin-right' => 'left' !== $align_tablet ? 'auto' : '',
"margin-{$align_tablet}" => ! empty( $align_tablet ) && 'center' !== $align_tablet ? '0' : '',
if ( ! empty( $align_phone ) ) {
$align_values['phone'] = array(
'text-align' => esc_html( $align_phone ),
'margin-left' => 'left' !== $align_phone ? 'auto' : '',
'margin-right' => 'left' !== $align_phone ? 'auto' : '',
"margin-{$align_phone}" => ! empty( $align_phone ) && 'center' !== $align_phone ? '0' : '',
et_pb_responsive_options()->generate_responsive_css( $align_values, '%%order_class%%', '', $render_slug, '', 'alignment' );
// Load up Dynamic Content (if needed) to capture Featured Image objects.
// In this way we can process `alt` and `title` attributes defined in
// the WP Media Library when they haven't been specified by the user in
if ( empty( $alt ) || empty( $title_text ) ) {
$raw_src = et_()->array_get( $this->attrs_unprocessed, 'src' );
$src_value = et_builder_parse_dynamic_content( $raw_src );
if ( $src_value->is_dynamic() && $src_value->get_content() === 'post_featured_image' ) {
// If there is no user-specified ALT attribute text, check the WP
// Media Library entry for text that may have been added there.
$alt = et_builder_resolve_dynamic_content( 'post_featured_image_alt_text', array(), get_the_ID(), 'display' );
// If there is no user-specified TITLE attribute text, check the WP
// Media Library entry for text that may have been added there.
if ( empty( $title_text ) ) {
$title_text = et_builder_resolve_dynamic_content( 'post_featured_image_title_text', array(), get_the_ID(), 'display' );
if ( 'on' === $is_overlay_applied ) {
'base_attr_name' => 'overlay_icon_color',
'selector' => '%%order_class%% .et_overlay:before',
'css_property' => 'color',
'render_slug' => $render_slug,
'base_attr_name' => 'hover_overlay_color',
'selector' => '%%order_class%% .et_overlay',
'css_property' => 'background-color',
'render_slug' => $render_slug,
$overlay_output = ET_Builder_Module_Helper_Overlay::render(
'icon_tablet' => $hover_icon_tablet,
'icon_phone' => $hover_icon_phone,
'icon_sticky' => $hover_icon_sticky,
// Set display block for svg image to avoid disappearing svg image
'selector' => '%%order_class%% .et_pb_image_wrap',
'declaration' => 'display: block;',
ET_Builder_Element::set_style( $render_slug, $el_style );
$box_shadow_overlay_wrap_class = 'none' !== $box_shadow_style
? 'has-box-shadow-overlay'
$box_shadow_overlay_element = 'none' !== $box_shadow_style
? '<div class="box-shadow-overlay"></div>'
'alt' => esc_attr( $alt ),
'title' => esc_attr( $title_text ),
$image_attachment_class = et_pb_media_options()->get_image_attachment_class( $this->props, 'src' );
if ( ! empty( $image_attachment_class ) ) {
$image_attrs['class'] = esc_attr( $image_attachment_class );
$image_html = $multi_view->render_element(
'<span class="et_pb_image_wrap %3$s">%4$s%1$s%2$s</span>',
'on' === $is_overlay_applied ? $overlay_output : '',
$box_shadow_overlay_wrap_class,
$box_shadow_overlay_element
if ( 'on' === $show_in_lightbox ) {
'<a href="%1$s" class="et_pb_lightbox_image" title="%3$s">%2$s</a>',
} elseif ( '' !== $url ) {
'<a href="%1$s"%3$s>%2$s</a>',
( 'on' === $url_new_window ? ' target="_blank"' : '' )