/** * Get icon HTML markup from icon attr value in shortcode. * Get icon HTML for Cherry shortcodes. * * @since 1.0.0 * * @param string $icon Passed icon. * @param string $class Custom class for icon. * @param string $alt Alt attribute value if icon is image. * @return string Icon HTML markup. */ public static function get_icon_html($icon, $class = 'cherry-icon', $alt = null, $style = array()) { if (!$icon || 'none' == $icon) { return false; } if (false !== strpos($icon, 'icon:')) { $icon = trim(str_replace('icon:', '', $icon)); $style = Cherry_Shortcodes_Tools::prepare_styles($style); $rand_class = Cherry_Shortcodes_Tools::rand_class('icon'); $style = sprintf('%s{%s}', $rand_class, $style); $class .= ' ' . Cherry_Shortcodes_Tools::esc_class($rand_class); Cherry_Shortcodes_Tools::print_styles($style); return sprintf('<span class="%1$s %2$s"></span>', esc_attr($icon), esc_attr($class)); } else { $icon = Cherry_Shortcodes_Tools::get_image_url($icon); return sprintf('<span class="%2$s"><img src="%1$s" alt="%3$s"></span>', esc_url($icon), esc_attr($class), esc_attr($alt)); } }
/** * Builds the Title Box shortcode output. * * @since 1.0.0 * @param array $atts Attributes of the title box shortcode. * @param string $content Shortcode content. * @return string HTML content to display the title box. */ public static function title_box($atts = null, $content = null) { $atts = shortcode_atts(array('title' => '', 'subtitle' => '', 'icon' => '', 'icon_size' => 20, 'icon_color' => '', 'title_color' => '', 'subtitle_color' => '', 'class' => ''), $atts, 'title_box'); if (!$atts['title']) { return; } $format = apply_filters('cherry_shortcodes_title_box_format', array('global' => '<div class="%4$s">%3$s<div class="title-box_content"><h2 class="title-box_title">%1$s</h2>%2$s</div></div>', 'subtitle' => '<h4 class="title-box_subtitle">%s</h4>'), $atts); $style = array(); $style['font-size'] = 0 != absint($atts['icon_size']) ? absint($atts['icon_size']) . 'px' : false; $style['color'] = !empty($atts['icon_color']) ? esc_attr($atts['icon_color']) : false; $icon = Cherry_Shortcodes_Tools::get_icon_html($atts['icon'], 'title-box_icon', $atts['title'], $style); $uniq_class = Cherry_Shortcodes_Tools::rand_class('title_box'); $title_color = esc_attr($atts['title_color']); $subtitle_color = esc_attr($atts['subtitle_color']); $title_style = ''; if ($title_color) { $title_style .= $uniq_class . ' .title-box_title { color: ' . $title_color . '; }'; } if ($subtitle_color) { $title_style .= $uniq_class . ' .title-box_subtitle { color: ' . $subtitle_color . '; }'; } $output = Cherry_Shortcodes_Tools::print_styles($title_style); $title = wp_kses($atts['title'], 'default'); $subtitle = !empty($atts['subtitle']) ? sprintf($format['subtitle'], wp_kses($atts['subtitle'], 'default')) : ''; $classes[] = 'title-box'; $classes[] = $atts['class']; $classes[] = Cherry_Shortcodes_Tools::esc_class($uniq_class); $class = implode(' ', array_filter($classes)); // Empty 5-th arguments for backward compatibility. $depraceted = ''; $output .= sprintf($format['global'], $title, $subtitle, $icon, $class, $depraceted); return apply_filters('cherry_shortcodes_output', $output, $atts, 'title_box'); }