Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Created March 1, 2015 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericnicolaas/73de7fbef576d875d235 to your computer and use it in GitHub Desktop.
Save ericnicolaas/73de7fbef576d875d235 to your computer and use it in GitHub Desktop.
Retina image helper
/**
* Based on a single key, retrieve the data for a particular image, including whether it is retina and its dimensions.
*
* @param string $key
* @return false if not set, or array if set
* @access private
* @since 1.0
*/
private function get_image_data($key) {
$data = array();
$key_value = get_theme_mod( $key );
if ( ! strlen( $key_value ) ) {
return false;
}
$data['width'] = $this->theme->get_theme_setting($key . '_width');
$data['height'] = $this->theme->get_theme_setting($key . '_height');
if ( $this->theme->get_theme_setting($key . '_is_retina') ) {
/**
* Retrieve the post ID of the logo, then get the non-retina version.
*/
$data['id'] = get_theme_mod( $key . '_id' );
$data['image'] = get_post_meta( $data['id'], '_non_retina', true );
$data['retina_image'] = $key_value;
}
else {
$data['image'] = $key_value;
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment