'', 'previewImg' => '', // Image Settings 'imageUpload' => (object)[ 'id'=>'999999', 'url' => ULTP_URL.'assets/img/ultp-placeholder.jpg' ], 'darkImgEnable' => false, 'darkImage' => (object)[ 'id'=>'999999', 'url' => ULTP_URL.'assets/img/ultp-placeholder.jpg' ], 'linkType' => 'link', 'imgLink' => '', 'linkTarget' => '_blank', 'imgAlt' => 'Image', 'imgAlignment' => ['lg' => 'left'], 'imgCrop' => 'full', 'imgAnimation' => 'none', 'imgMargin' => (object)['lg'=>''], 'imgOverlay' => false, 'imgOverlayType' => 'default', 'imgSrcset' => false, 'imgLazy' => false, // Heading Setting/Style 'headingText' => 'This is a Image Example', 'headingEnable' => false, 'alignment' => ['lg' => 'left'], // Button Settings 'buttonEnable' => false, 'btnText' => 'Free Download', 'btnLink' => '#', 'btnTarget' => '_blank', 'btnPosition' => 'centerCenter', // Style 'advanceId' => '', 'advanceZindex' => '', 'hideExtraLarge' => false, 'hideTablet' => false, 'hideMobile' => false, 'advanceCss' => '', ); } public function register() { register_block_type( 'ultimate-post/image', array( 'editor_script' => 'ultp-blocks-editor-script', 'editor_style' => 'ultp-blocks-editor-css', 'render_callback' => array( $this, 'content' ) ) ); } public function content( $attr, $noAjax ) { $attr = wp_parse_args( $attr, $this->get_attributes() ); $wraper_before = ''; $block_name = 'image'; $attr['headingShow'] = true; $darkImageArr = (array)$attr['darkImage']; $darkImg = [ 'enable'=> $attr['darkImgEnable'], 'url'=> isset($darkImageArr['url']) ? $darkImageArr['url'] : ULTP_URL.'assets/img/ultp-placeholder.jpg', 'srcset' => $attr['imgSrcset'] ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($darkImageArr['id'])).'"' : '' ]; $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; $attr['imgAnimation'] = sanitize_html_class( $attr['imgAnimation'] ); $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] ); $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags(); $attr['btnText'] = wp_kses($attr['btnText'], $allowed_html_tags); $attr['headingText'] = wp_kses($attr['headingText'], $allowed_html_tags); $wraper_before .= '
'; $wraper_before .= '
'; $wraper_before .= '
'; $wraper_before .= '
'; // Single Image $img_arr = (array)$attr['imageUpload']; $img_url = ( isset($img_arr['size']) && isset($img_arr['size'][$attr['imgCrop']]) ) ? ( isset($img_arr['size'][$attr['imgCrop']]['url']) ? $img_arr['size'][$attr['imgCrop']]['url'] : $img_arr['size'][$attr['imgCrop']] ) : $img_arr['url']; if ( ! empty( $img_arr ) ) { $srcset_data = $attr['imgSrcset'] ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($img_arr['id'])).'"' : ''; if ( $attr['linkType'] == 'link' && $attr['imgLink'] ) { $wraper_before .= ''.ultimate_post()->get_image_html($img_url, 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg, $srcset_data).''; } else { // $wraper_before .= ultimate_post()->get_image_html($img_arr['url'], 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg); $wraper_before .= ultimate_post()->get_image_html( $img_url, 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg, $srcset_data ); } } if ( $attr['btnLink'] && $attr['linkType'] == 'button' ) { $wraper_before .= ''; } $wraper_before .= '
'; if ( $attr['headingEnable'] == 1 ) { $wraper_before .= '
'.$attr['headingText'].'
'; } $wraper_before .= '
'; $wraper_before .= '
'; $wraper_before .= '
'; return $wraper_before; } }