From 331fd2e2716aca710d0756777ea071cf20cbb3e8 Mon Sep 17 00:00:00 2001 From: MickeyKay Date: Mon, 20 Jul 2015 11:26:36 -0700 Subject: [PATCH 1/3] Add helper function to check if img has size. --- includes/functions/theme-functions.php | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/includes/functions/theme-functions.php b/includes/functions/theme-functions.php index aeaa964..6f0459b 100755 --- a/includes/functions/theme-functions.php +++ b/includes/functions/theme-functions.php @@ -418,3 +418,42 @@ function trestle_read_more_link( $default_text ) { return $default_text; } } + + +/*=========================================== + * Helper Functions +===========================================*/ + +/** + * Check if image has specified image size. + * + * @since 2.2.0 + * + * @param int $image_id ID of image to check. + * @param string $image_size Slug of image size to check for. + * + * @return [type] [description] + */ +function trestle_image_has_size( $image_id, $image_size = null ) { + + global $_wp_additional_image_sizes; + + // Return with error if no image_size is specified. + if ( ! $image_size ) { + return new WP_Error( 'no_image_size_specified', __( 'Please specify an image size.', 'trestle' ) ); + } + + // Get the attributes for the specified image size. + $image_size_atts = $_wp_additional_image_sizes[ $image_size ]; + + // Get data for specified image ID and size. + $img_data = wp_get_attachment_image_src( $image_id, $image_size ); + + // Check if the dimensions match. + if ( $img_data[1] == $image_size_atts['width'] && $img_data[2] == $image_size_atts['height'] ) { + return true; + } + + return false; + +} \ No newline at end of file From 59ec252bc4f4346f55ca3458708763f5cb94a23f Mon Sep 17 00:00:00 2001 From: MickeyKay Date: Mon, 20 Jul 2015 11:27:49 -0700 Subject: [PATCH 2/3] Update comment --- includes/functions/theme-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/functions/theme-functions.php b/includes/functions/theme-functions.php index 6f0459b..6594049 100755 --- a/includes/functions/theme-functions.php +++ b/includes/functions/theme-functions.php @@ -432,7 +432,7 @@ function trestle_read_more_link( $default_text ) { * @param int $image_id ID of image to check. * @param string $image_size Slug of image size to check for. * - * @return [type] [description] + * @return true|false Whether or not the image has the specified size generated. */ function trestle_image_has_size( $image_id, $image_size = null ) { From b52e7e3387161750fa481ca3f4c91342255bdd95 Mon Sep 17 00:00:00 2001 From: MickeyKay Date: Mon, 20 Jul 2015 11:31:19 -0700 Subject: [PATCH 3/3] Add empty line at file end. --- includes/functions/theme-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/functions/theme-functions.php b/includes/functions/theme-functions.php index 6594049..cd556cb 100755 --- a/includes/functions/theme-functions.php +++ b/includes/functions/theme-functions.php @@ -456,4 +456,4 @@ function trestle_image_has_size( $image_id, $image_size = null ) { return false; -} \ No newline at end of file +}