예제 #1
0
/**
 * Return a single defined density label.
 *
 * @since 0.1.0
 * @param string $density The density value.
 * @return string
 */
function ev_get_density_label($density)
{
    $densities = ev_get_densities();
    if (isset($densities[$density])) {
        return $densities[$density];
    }
    return false;
}
예제 #2
0
/**
 * Return the markup for an image specifying a different srcset parameter according
 * to the available densities.
 *
 * @since 1.0.0
 * @param array $data The image data.
 * @param string $type The image size.
 * @param string $breakpoint The breakpoint name.
 * @return string
 */
function ev_get_density_image($data, $size = 'full', $breakpoint = 'desktop')
{
    if (empty($data[$breakpoint]['1']['id'])) {
        return '';
    }
    $src = wp_get_attachment_image_url($data[$breakpoint]['1']['id'], $size);
    if (empty($src)) {
        return '';
    }
    $srcset = array();
    $densities = ev_get_densities();
    array_shift($densities);
    foreach ($densities as $density => $label) {
        $density_src = wp_get_attachment_image_url($data[$breakpoint][$density]['id'], $size);
        if (!empty($density_src)) {
            $srcset[] = $density_src . ' ' . $density . 'x';
        }
    }
    $args = array();
    if (!empty($srcset)) {
        $args['srcset'] = esc_attr(implode(', ', $srcset));
    }
    return wp_get_attachment_image($data[$breakpoint]['1']['id'], $size, false, $args);
}
예제 #3
0
<?php

$value = $field->value();
$densities = ev_get_densities();
$breakpoints = ev_get_breakpoints();
$thumb_size = $field->config('thumb_size');
$multiple = $field->config('multiple');
$sortable = $field->config('sortable');
$config_density = $field->config('density');
$config_breakpoints = $field->config('breakpoints');
$manage_densities = $config_density !== false;
$manage_breakpoints = $config_breakpoints !== false;
$image_densities = array();
$image_breakpoints = array();
if ($manage_breakpoints) {
    if (is_array($config_breakpoints)) {
        foreach ($config_breakpoints as $breakpoint) {
            if (isset($breakpoints[$breakpoint])) {
                $image_breakpoints[$breakpoint] = $breakpoints[$breakpoint];
            }
        }
    } else {
        $image_breakpoints = $breakpoints;
    }
} else {
    $image_breakpoints = array('desktop' => $breakpoints['desktop']);
}
if ($manage_densities) {
    if (is_array($config_density)) {
        foreach ($config_density as $density) {
            if (isset($densities[$density])) {