/** * @param string $key The option key * @param string $default_url An absolute URL to be used as the default * @param string|array $extra_attr Extra HTML attributes for the <img> tag * @param bool $echo Wether to echo or return the result */ function editable_image($key, $default_url, $extra_attr = '', $echo = true) { $attr = wp_parse_args($extra_attr, array('id' => $key)); if (!($src = FEE_Field_Image::get(compact('key')))) { $src = $default_url; } $attr['src'] = $src; $img = apply_filters('editable_image', html('img', $attr), $key, $default_url); if ($echo) { echo $img; } return $img; }
/** * @param string $key The option key * @param string $default_url An absolute URL to be used as the default * @param string|array $extra_attr Extra HTML attributes for the <img> tag * @param bool $echo Wether to echo or return the result */ function editable_image($key, $default_url, $extra_attr = '', $echo = true) { $attr = wp_parse_args($extra_attr, array('id' => $key)); if (!($src = FEE_Field_Image::get(compact('key')))) { $src = $default_url; } $attr['src'] = $src; $attr_str = ''; foreach ($attr as $a_key => $a_value) { $a_key = trim(strip_tags($a_key)); $a_value = trim(esc_attr($a_value)); if (empty($a_key)) { continue; } $attr_str .= " {$a_key}='{$a_value}'"; } $attr_str = ltrim($attr_str); $img = apply_filters('editable_image', "<img {$attr_str} />", $key, $default_url); if ($echo) { echo $img; } return $img; }