Example #1
0
/**
 *  Returns logo html
 */
function get_navbar_logo()
{
    static $logo_markup = null;
    if (null === $logo_markup) {
        // Grab logo
        $logo = Core\get_proud_logo();
        $image_meta = [];
        $custom_width = false;
        if ($logo) {
            global $wpdb;
            // Try to grab ID
            $media_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $logo));
            // Build responsive image, get width
            if ($media_id) {
                // Build responsive meta
                if (get_theme_mod('proud_logo_includes_title')) {
                    $image_meta = Core\build_retina_image_meta($media_id, 'proud-logo-wide', 'proud-logo-wide-retina');
                } else {
                    $image_meta = Core\build_retina_image_meta($media_id, 'proud-logo', 'proud-logo-retina');
                }
                $image_meta['meta']['image_meta']['alt'] = 'Home';
                $image_meta['meta']['image_meta']['title'] = 'Home';
                $image_meta['meta']['image_meta']['class'] = 'logo';
                if (!get_theme_mod('proud_logo_includes_title')) {
                    // try to maximize height @ 64px (and not divide by zero)
                    // 64 = max height, 32 = current horizontal padding
                    $custom_width = $image_meta['meta']['height'] > 0 ? $image_meta['meta']['width'] / $image_meta['meta']['height'] * 64 + 32 : 140;
                    // 140 max width
                    $custom_width = $custom_width < 140 ? $custom_width : 140;
                }
            }
        }
        // Build user uploaded logo
        if (!empty($image_meta)) {
            ob_start();
            Proud\Core\print_retina_image($image_meta, false, true);
            $logo_markup = ob_get_contents();
            ob_end_clean();
        } else {
            ob_start();
            Proud\Core\print_proud_logo('icon-white', ['class' => 'logo', 'title' => 'Home', 'alt' => 'Home']);
            $logo_markup = ob_get_contents();
            ob_end_clean();
        }
    }
    return $logo_markup;
}
 /**
  * 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)
 {
     $instance['logo'] = Core\get_proud_logo();
     return !empty($instance['logo']);
 }