/** * Determines if content empty, show widget, title ect? * * @see self::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function hasContent($args, &$instance) { if (!empty($instance['form_id'])) { $instance['shortcode'] = '[gravityform id="' . $instance['form_id'] . '" title="false" description="false"]'; // If we're in the loop (content), let form be a shortcode if (in_the_loop()) { $instance['form'] = $instance['shortcode']; } else { $instance['form'] = Core\sanitize_input_text_output($instance['shortcode'], true); } return true; } return false; }
/** * Generate HTML code from shortcode content. * * @param array $atts Shortcode attributes. * @param string $content Current content. * * @return string */ function printWidget($args, $instance) { // Container Styles $arr_styles = []; // init classes $classes = []; if (!empty($instance['background']) && $instance['headertype'] !== 'slideshow') { // For random do a little processing if ($instance['headertype'] === 'random') { $rand = array_rand($instance['random']); $instance['image'] = $instance['random'][$rand]['random_image']; // Fudge as image $instance['background'] = 'image'; // Fudge as full $instance['headertype'] = 'full'; // Remove featured option $instance['featured_image'] = false; } switch ($instance['background']) { case 'solid': $solid_color = $instance['solid_color_value']; $background_style = "background-color: {$solid_color};"; break; case 'pattern': $pattern_img = wp_get_attachment_image_url($instance['pattern'], 'full'); $background_style = "background-image:url('{$pattern_img}');"; $background_style .= "background-size:initial;"; $background_repeat = self::background_repeat($instance['repeat']); if (!empty($background_repeat)) { $background_style .= "background-repeat:{$background_repeat};"; } break; case 'image': // Use featured image? if ($instance['featured_image'] === 'yes') { global $post; $instance['image'] = get_post_thumbnail_id($post->ID); } $resp_img = $this->getResponsiveImage($instance['image']); break; } if (!empty($background_style)) { $arr_styles[] = $background_style; } } else { if ($instance['headertype'] === 'slideshow') { // d($instance); foreach ($instance['slideshow'] as $key => $value) { $instance['slideshow'][$key]['resp_img'] = $this->getResponsiveImage($value['slide_image']); } } } // Init a random id for the element $random_id = 'proud-header-' . rand(); // init file location $file = plugin_dir_path(__FILE__) . 'templates/'; $content = Core\sanitize_input_text_output($instance['text']); // normal header type if ($instance['headertype'] == 'header') { $jumbotron_col_classes = apply_filters('proud_jumbotron_col_classes', 'col-lg-5 col-md-8 col-sm-8', 'header'); // Classes $classes[] = 'jumbotron'; if ($instance['background'] == 'pattern' || $instance['background'] == 'image') { $classes[] = 'jumbotron-image'; } // Inverse? if ($instance['make_inverse'] == 'yes') { $classes[] = 'jumbotron-inverse'; } $file .= 'jumbotron-header.php'; } else { if ($instance['headertype'] == 'full') { $jumbotron_col_classes = apply_filters('proud_jumbotron_col_classes', 'col-lg-7 col-md-8 col-sm-9', 'full'); // Classes $classes[] = 'full-image jumbotron-header-container'; // Box styles // Init classes $boxclasses = ['jumbotron', 'jumbotron-image', 'full']; // Inverse? if ($instance['make_inverse'] == 'yes') { $boxclasses[] = 'jumbotron-inverse'; } // Vertical horizontal positions $pos_options = !empty($instance['box_position']) ? explode('_', $instance['box_position']) : ['middle', 'left']; $boxclasses[] = 'full-v-align-' . $pos_options[0]; $boxclasses[] = 'full-h-align-' . $pos_options[1]; $file .= 'jumbotron-full.php'; } else { if ($instance['headertype'] === 'slideshow') { $classes[] = 'jumbotron'; // Inverse? if ($instance['make_inverse'] == 'yes') { $classes[] = 'jumbotron-inverse'; } $file .= 'jumbotron-slideshow.php'; } else { // Classes $classes[] = 'jumbotron'; // Inverse? if ($instance['make_inverse'] == 'yes') { $classes[] = 'jumbotron-inverse'; } $file .= 'jumbotron-simple.php'; } } } // Include the template file include $file; }