Ejemplo n.º 1
0
function hocwp_get_post_thumbnail_url($post_id = '', $size = 'full')
{
    $result = '';
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    if (has_post_thumbnail($post_id)) {
        $thumbnail_id = get_post_thumbnail_id($post_id);
        if (hocwp_media_file_exists($thumbnail_id)) {
            $image_attributes = wp_get_attachment_image_src($thumbnail_id, $size);
            if ($image_attributes) {
                $result = $image_attributes[0];
            }
        }
    }
    if (empty($result)) {
        $result = get_post_meta($post_id, 'thumbnail_url', true);
    }
    $result = apply_filters('hocwp_post_thumbnail_pre_from_content', $result, $post_id, $size);
    if (empty($result)) {
        $post = get_post($post_id);
        if (hocwp_object_valid($post)) {
            $result = hocwp_get_first_image_source($post->post_content);
        }
    }
    $result = apply_filters('hocwp_post_pre_post_thumbnail', $result, $post_id);
    if (empty($result)) {
        $thumbnail = hocwp_option_get_value('writing', 'default_post_thumbnail');
        $thumbnail = hocwp_sanitize_media_value($thumbnail);
        $result = $thumbnail['url'];
    }
    if (empty($result)) {
        $no_thumbnail = HOCWP_URL . '/images/no-thumbnail.png';
        $no_thumbnail = apply_filters('hocwp_no_thumbnail_url', $no_thumbnail);
        $result = $no_thumbnail;
    }
    $result = apply_filters('hocwp_post_thumbnail', $result, $post_id);
    return $result;
}
Ejemplo n.º 2
0
function hocwp_sanitize_media_value($value)
{
    $url = isset($value['url']) ? $value['url'] : '';
    $has_url = false;
    if (!empty($url)) {
        $has_url = true;
    }
    $id = isset($value['id']) ? $value['id'] : '';
    $id = absint($id);
    if (0 < $id && hocwp_media_file_exists($id)) {
        $url = hocwp_get_media_image_url($id);
    }
    if (0 >= $id && !is_array($value) && !empty($value)) {
        $url = $value;
    }
    if ($has_url && empty($url)) {
        $url = wp_get_attachment_url($id);
    }
    $icon = wp_mime_type_icon($id);
    $size = hocwp_get_media_size($id);
    $result = array('id' => $id, 'url' => $url, 'type_icon' => $icon, 'is_image' => hocwp_is_image($url, $id), 'size' => $size, 'size_format' => hocwp_size_converter($size), 'mime_type' => get_post_mime_type($id));
    return $result;
}