function get_header_image()
{
    // die('get_header_image');
    // return false;
    $url = get_theme_mod('header_image', get_theme_support('custom-header', 'default-image'));
    if ('remove-header' == $url) {
        return false;
    }
    if (is_random_header_image()) {
        $url = get_random_header_image();
    }
    return esc_url_raw(set_url_scheme($url));
}
/**
 * Retrieve header image for custom header.
 *
 * @since 0.1
 * @uses HEADER_IMAGE
 * @uses HEADER_IMAGE_WIDTH
 * @uses HEADER_IMAGE_HEIGHT
 *
 * @return string
 */
function boom_header_image($width = null, $height = null)
{
    $default = defined('HEADER_IMAGE') ? HEADER_IMAGE : '';
    $url = get_theme_mod('header_image', $default);
    $width = defined('HEADER_IMAGE_WIDTH') ? HEADER_IMAGE_WIDTH : $width;
    $height = defined('HEADER_IMAGE_HEIGHT') ? HEADER_IMAGE_HEIGHT : $height;
    if ('remove-header' == $url) {
        return false;
    } elseif ('boom-slider-uploaded' == $url || 'boom-slider-default' == $url) {
        // slider
        echo boom_build_nivo_slider(boom_get_header_images(), $width, $height);
        return;
    } elseif (is_random_header_image()) {
        // random header mode
        $url = get_random_header_image();
    }
    if (is_ssl()) {
        $url = str_replace('http://', 'https://', $url);
    } else {
        $url = str_replace('https://', 'http://', $url);
    }
    $output = "<img src='" . esc_url_raw($url) . "' alt='' />";
    echo $output;
}
Esempio n. 3
0
 /**
  * Display UI for selecting one of several default headers.
  *
  * Show the random image option if this theme has multiple header images.
  * Random image option is on by default if no header has been set.
  *
  * @since 3.0.0
  */
 function show_header_selector($type = 'default')
 {
     if ('default' == $type) {
         $headers = $this->default_headers;
     } else {
         $headers = get_uploaded_header_images();
         $type = 'uploaded';
     }
     if (1 < count($headers)) {
         echo '<div class="random-header">';
         echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked(is_random_header_image($type), true, false) . ' />';
         echo __('<strong>Random:</strong> Show a different image on each page.');
         echo '</label>';
         echo '</div>';
     }
     echo '<div class="available-headers">';
     foreach ($headers as $header_key => $header) {
         $header_thumbnail = $header['thumbnail_url'];
         $header_url = $header['url'];
         $header_desc = empty($header['description']) ? '' : $header['description'];
         echo '<div class="default-header">';
         echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod('header_image'), false) . ' />';
         $width = '';
         if (!empty($header['uploaded'])) {
             $width = ' width="230"';
         }
         echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) . '" title="' . esc_attr($header_desc) . '"' . $width . ' /></label>';
         echo '</div>';
     }
     echo '<div class="clear"></div></div>';
 }
Esempio n. 4
0
/**
 * Get the header image data.
 *
 * @since 3.4.0
 *
 * @return object
 */
function get_custom_header()
{
    $data = is_random_header_image() ? _get_random_header_data() : get_theme_mod('header_image_data');
    $default = array('url' => '', 'thumbnail_url' => '', 'width' => get_theme_support('custom-header', 'width'), 'height' => get_theme_support('custom-header', 'height'));
    return (object) wp_parse_args($data, $default);
}
/**
 *
 * @param WP_Post $post
 */
function _media_states($post)
{
    $media_states = array();
    $stylesheet = get_option('stylesheet');
    if (current_theme_supports('custom-header')) {
        $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true);
        if (is_random_header_image()) {
            $header_images = wp_list_pluck(get_uploaded_header_images(), 'attachment_id');
            if ($meta_header == $stylesheet && in_array($post->ID, $header_images)) {
                $media_states[] = __('Header Image');
            }
        } else {
            $header_image = get_header_image();
            // Display "Header Image" if the image was ever used as a header image
            if (!empty($meta_header) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url($post->ID)) {
                $media_states[] = __('Header Image');
            }
            // Display "Current Header Image" if the image is currently the header image
            if ($header_image && $header_image == wp_get_attachment_url($post->ID)) {
                $media_states[] = __('Current Header Image');
            }
        }
    }
    if (current_theme_supports('custom-background')) {
        $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true);
        if (!empty($meta_background) && $meta_background == $stylesheet) {
            $media_states[] = __('Background Image');
            $background_image = get_background_image();
            if ($background_image && $background_image == wp_get_attachment_url($post->ID)) {
                $media_states[] = __('Current Background Image');
            }
        }
    }
    if ($post->ID == get_option('site_icon')) {
        $media_states[] = __('Site Icon');
    }
    if ($post->ID == get_theme_mod('site_logo')) {
        $media_states[] = __('Logo');
    }
    /**
     * Filters the default media display states for items in the Media list table.
     *
     * @since 3.2.0
     *
     * @param array $media_states An array of media states. Default 'Header Image',
     *                            'Background Image', 'Site Icon', 'Logo'.
     */
    $media_states = apply_filters('display_media_states', $media_states);
    if (!empty($media_states)) {
        $state_count = count($media_states);
        $i = 0;
        echo ' &mdash; ';
        foreach ($media_states as $state) {
            ++$i;
            $i == $state_count ? $sep = '' : ($sep = ', ');
            echo "<span class='post-state'>{$state}{$sep}</span>";
        }
    }
}
Esempio n. 6
0
/**
 * Get the header image data.
 *
 * @since 3.4.0
 *
 * @global array $_wp_default_headers
 *
 * @return object
 */
function get_custom_header()
{
    global $_wp_default_headers;
    if (is_random_header_image()) {
        $data = _get_random_header_data();
    } else {
        $data = get_theme_mod('header_image_data');
        if (!$data && current_theme_supports('custom-header', 'default-image')) {
            $directory_args = array(get_template_directory_uri(), get_stylesheet_directory_uri());
            $data = array();
            $data['url'] = $data['thumbnail_url'] = vsprintf(get_theme_support('custom-header', 'default-image'), $directory_args);
            if (!empty($_wp_default_headers)) {
                foreach ((array) $_wp_default_headers as $default_header) {
                    $url = vsprintf($default_header['url'], $directory_args);
                    if ($data['url'] == $url) {
                        $data = $default_header;
                        $data['url'] = $url;
                        $data['thumbnail_url'] = vsprintf($data['thumbnail_url'], $directory_args);
                        break;
                    }
                }
            }
        }
    }
    $default = array('url' => '', 'thumbnail_url' => '', 'width' => get_theme_support('custom-header', 'width'), 'height' => get_theme_support('custom-header', 'height'));
    return (object) wp_parse_args($data, $default);
}
    /**
     * Template for Featured Header Image from theme options
     *
     * To override this in a child theme
     * simply create your own catchbase_featured_image(), and that function will be used instead.
     *
     * @since Catch Base 1.0
     */
    function catchbase_featured_image()
    {
        $options = catchbase_get_theme_options();
        $header_image = get_header_image();
        //Support Random Header Image
        if (is_random_header_image()) {
            delete_transient('catchbase_featured_image');
        }
        if (!($catchbase_featured_image = get_transient('catchbase_featured_image'))) {
            echo '<!-- refreshing cache -->';
            if ($header_image != '') {
                // Header Image Link and Target
                if (!empty($options['featured_header_image_url'])) {
                    //support for qtranslate custom link
                    if (function_exists('qtrans_convertURL')) {
                        $link = qtrans_convertURL($options['featured_header_image_url']);
                    } else {
                        $link = esc_url($options['featured_header_image_url']);
                    }
                    //Checking Link Target
                    if (!empty($options['featured_header_image_base'])) {
                        $target = '_blank';
                    } else {
                        $target = '_self';
                    }
                } else {
                    $link = '';
                    $target = '';
                }
                // Header Image Title/Alt
                if (!empty($options['featured_header_image_alt'])) {
                    $title = esc_attr($options['featured_header_image_alt']);
                } else {
                    $title = '';
                }
                // Header Image
                $feat_image = '<img class="wp-post-image" alt="' . $title . '" src="' . esc_url($header_image) . '" />';
                $catchbase_featured_image = '<div id="header-featured-image">
					<div class="wrapper">';
                // Header Image Link
                if (!empty($options['featured_header_image_url'])) {
                    $catchbase_featured_image .= '<a title="' . esc_attr($title) . '" href="' . esc_url($link) . '" target="' . $target . '">' . $feat_image . '</a>';
                } else {
                    // if empty featured_header_image on theme options, display default
                    $catchbase_featured_image .= $feat_image;
                }
                $catchbase_featured_image .= '</div><!-- .wrapper -->
				</div><!-- #header-featured-image -->';
            }
            set_transient('catchbase_featured_image', $catchbase_featured_image, 86940);
        }
        echo $catchbase_featured_image;
    }
/**
 * Retrieve header image for custom header.
 *
 * @since 2.1.0
 * @uses HEADER_IMAGE
 *
 * @return string
 */
function get_header_image()
{
    $default = defined('HEADER_IMAGE') ? HEADER_IMAGE : '';
    $url = get_theme_mod('header_image', $default);
    if ('remove-header' == $url) {
        return false;
    }
    if (is_random_header_image()) {
        $url = get_random_header_image();
    }
    if (is_ssl()) {
        $url = str_replace('http://', 'https://', $url);
    } else {
        $url = str_replace('https://', 'http://', $url);
    }
    return esc_url_raw($url);
}
Esempio n. 9
0
function manduca_get_header_image_alt()
{
    $attachment_id = 0;
    if (is_random_header_image() && ($header_url = get_header_image())) {
        // For a random header, we have to search for a match against all headers.
        foreach (get_uploaded_header_images() as $header) {
            if ($header['url'] == $header_url) {
                $attachment_id = $header['attachment_id'];
                break;
            }
        }
    } elseif ($data = get_custom_header()) {
        // For static headers, less intensive approach.
        $attachment_id = $data->attachment_id;
    }
    if ($attachment_id) {
        $alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
        if (!$alt) {
            $alt = trim(strip_tags(get_post_field('post_excerpt', $attachment_id)));
        }
        if (!$alt) {
            $alt = trim(strip_tags(get_post_field('post_title', $attachment_id)));
        }
    } else {
        $alt = '';
    }
    return $alt;
}
Esempio n. 10
0
/**
 * Default image property, using the post-thumbnail and any attached images.
 */
function opengraph_default_image($image)
{
    if ($image) {
        return $image;
    }
    // As of July 2014, Facebook seems to only let you select from the first 3 images
    $max_images = apply_filters('opengraph_max_images', 3);
    if (is_singular()) {
        $id = get_queried_object_id();
        $image_ids = array();
        // list post thumbnail first if this post has one
        if (function_exists('has_post_thumbnail') && has_post_thumbnail($id)) {
            $image_ids[] = get_post_thumbnail_id($id);
        }
        // then list any image attachments
        $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
        foreach ($attachments as $attachment) {
            if (!in_array($attachment->ID, $image_ids)) {
                $image_ids[] = $attachment->ID;
                if (sizeof($image_ids) >= $max_images) {
                    break;
                }
            }
        }
        // get URLs for each image
        $image = array();
        foreach ($image_ids as $id) {
            $thumbnail = wp_get_attachment_image_src($id, 'full');
            if ($thumbnail) {
                $image[] = $thumbnail[0];
            }
        }
    } elseif (is_attachment() && wp_attachment_is_image()) {
        $id = get_queried_object_id();
        $image = array(wp_get_attachment_url($id));
    }
    if (empty($image)) {
        $image = array();
        // add site icon
        if (function_exists('get_site_icon_url') && has_site_icon()) {
            $image[] = get_site_icon_url(512);
        }
        // add header images
        if (function_exists('get_uploaded_header_images')) {
            if (is_random_header_image()) {
                foreach (get_uploaded_header_images() as $header_image) {
                    $image[] = $header_image['url'];
                    if (sizeof($image) >= $max_images) {
                        break;
                    }
                }
            } elseif (get_header_image()) {
                $image[] = get_header_image();
            }
        }
    }
    return $image;
}