Created
March 1, 2015 23:16
-
-
Save ericnicolaas/73de7fbef576d875d235 to your computer and use it in GitHub Desktop.
Retina image helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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