$post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', ) ) ); if ( isset( $image_ids[$index] ) ) { return $image_ids[$index]; } return false; } /** * Return an image pulled from the media gallery. * * @since 1.0.0 */ function bizznis_get_image( $args = array() ) { global $post; $defaults = apply_filters( 'bizznis_get_image_default_args', array( 'format' => 'html', 'size' => 'full', 'num' => 0, 'attr' => '', 'fallback' => 'first-attached', 'context' => '', ) ); $args = wp_parse_args( $args, $defaults ); # Allow child theme to short-circuit this function $pre = apply_filters( 'bizznis_pre_get_image', false, $args, $post ); if ( false !== $pre ) { return $pre; } # Check for post image (native WP) if ( has_post_thumbnail() && ( 0 === $args['num'] ) ) { $id = get_post_thumbnail_id(); $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] ); } # Else if first-attached, pull the first (default) image attachment elseif ( 'first-attached' == $args['fallback'] ) { $id = bizznis_get_image_id( $args['num'] ); $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] ); } # Else if fallback array exists elseif ( is_array( $args['fallback'] ) ) { $id = 0; $html = $args['fallback']['html']; $url = $args['fallback']['url']; } # Else, return false (no image) else { return false; } # Source path, relative to the root $src = str_replace( home_url(), '', $url ); # Determine output if ( 'html' === strtolower( $args['format'] ) ) { $output = $html; } elseif ( 'url' === strtolower( $args['format'] ) ) { $output = $url; } else { $output = $src; } # Return false if $url is blank if ( empty( $url ) ) { $output = false; } # Return data, filtered return apply_filters( 'bizznis_get_image', $output, $args, $id, $html, $url, $src ); } /** * Echo an image pulled from the media gallery. * * @since 1.0.0 */ function bizznis_image( $args = array() ) { /* Supported $args keys are: - format - string, default is 'html', may be 'url' - size - string, default is 'full' - num - integer, default is 0 - attr - string, default is '' */ $image = bizznis_get_image( $args ); if ( $image ) { echo $image; } else { return false; } } /** * Return registered image sizes. Return two-dimensional, with width, height and crop sub-keys. * * @since 1.0.0 */ function bizznis_get_additional_image_sizes() { global $_wp_additional_image_sizes; if ( $_wp_additional_image_sizes ) { return $_wp_additional_image_sizes; } return array(); } /** * Return all registered image sizes arrays, including the standard sizes. Return two-dimensional, with width, height and crop sub-keys. * * @since 1.0.0 */ function bizznis_get_image_sizes() { $builtin_sizes = array( 'large' => array( 'width' => get_option( 'large_size_w' ), 'height' => get_option( 'large_size_h' ), ), 'medium' => array( 'width' => get_option( 'medium_size_w' ), 'height' => get_option( 'medium_size_h' ), ), 'thumbnail' => array( 'width' => get_option( 'thumbnail_size_w' ), 'height' => get_option( 'thumbnail_size_h' ), 'crop' => get_option( 'thumbnail_crop' ), ), ); $additional_sizes = bizznis_get_additional_image_sizes(); return array_merge( $builtin_sizes, $additional_sizes ); }