base = 'qode_cards_gallery'; add_action('qode_vc_map', array($this, 'vcMap')); } /** * @return string */ public function getBase() { return $this->base; } /** * */ public function vcMap() { vc_map(array( 'name' => 'Cards Gallery', 'base' => $this->base, 'category' => 'by QODE', 'icon' => 'icon-wpb-cards-gallery extended-custom-icon-qode', 'allowed_container_element' => 'vc_row', 'params' => array( array( 'type' => 'attach_images', 'heading' => 'Images', 'param_name' => 'images', 'description' => 'Select images from media library' ), array( 'type' => 'dropdown', 'heading' => 'Expanding Side', 'param_name' => 'expanding_side', 'description' => 'Choose on which side images will be expanded', 'value' => array( 'Left' => 'left', 'Right' => 'right', 'Top' => 'top', 'Bottom' => 'bottom' ), 'save_always' => true, 'admin_label' => true, ), array( 'type' => 'colorpicker', 'heading' => 'Cards Background Color', 'param_name' => 'background_color' ) ) )); } /** * @param array $atts * @param null $content * * @return string */ public function render($atts, $content = null) { $args = array( 'images' => '', 'expanding_side' => '', 'background_color' => '' ); $params = shortcode_atts($args, $atts); $params['images'] = $this->getGalleryImages($params); if($params['background_color'] !== ''){ $params['background_color'] = 'background-color:'.$params['background_color']; } $params['data_side'] = ''; if($params['expanding_side'] !== ''){ $params['data_side'] = 'data-side='.$params['expanding_side']; } return qode_get_shortcode_template_part('templates/cards-gallery', 'cards-gallery', '', $params); } /** * Return images for slider * * @param $params * * @return array */ private function getGalleryImages($params) { $image_ids = array(); $images = array(); $i = 0; if($params['images'] !== '') { $image_ids = explode(',', $params['images']); } foreach($image_ids as $id) { $image['image_id'] = $id; $image_original = wp_get_attachment_image_src($id, 'full'); $image['url'] = $image_original[0]; $image['title'] = get_the_title($id); $image['image_link'] = get_post_meta($id, 'attachment_image_custom_link', true); $image['image_target'] = get_post_meta($id, 'attachment_image_link_target', true); $image_dimensions = qode_get_image_dimensions($image['url']); if(is_array($image_dimensions) && array_key_exists('height', $image_dimensions)) { if(!empty($image_dimensions['height']) && $image_dimensions['width']) { $image['height'] = $image_dimensions['height']; $image['width'] = $image_dimensions['width']; } } $images[$i] = $image; $i++; } return $images; } }