get_option( "{$size}_size_w" ), 'height' => get_option( "{$size}_size_h" ), 'crop' => (bool) get_option( "{$size}_crop" ), ); } elseif ( isset( $wais[ $size ] ) ) { $sizes[ $size ] = array( 'width' => $wais[ $size ]['width'], 'height' => $wais[ $size ]['height'], 'crop' => $wais[ $size ]['crop'], ); } // Size registered, but has 0 width and height. if ( 0 === (int) $sizes[ $size ]['width'] || 0 === (int) $sizes[ $size ]['height'] ) { unset( $sizes[ $size ] ); } } } return $sizes; } /** * Gets the data of a specific image size. * * @param string $size Name of the size. */ function powerkit_lazy_get_image_size( $size ) { if ( ! is_string( $size ) ) { return; } $sizes = powerkit_lazy_get_available_image_sizes(); return isset( $sizes[ $size ] ) ? $sizes[ $size ] : false; } /** * Tries to convert an attachment IMG attr into a post object. * * @param string $attr The img attr. */ function powerkit_lazy_attachment_attr_to_object( $attr ) { if ( ! isset( $attr['src'] ) ) { return; } // Set ID by class. if ( isset( $attr['class'] ) && preg_match( '/wp-image-(\d*)/i', $attr['class'], $matche ) ) { return array( 'ID' => $matche[1], ); } // Remove the thumbnail size. $src = preg_replace( '~-[0-9]+x[0-9]+(?=\..{2,6})~', '', $attr['src'] ); // Set ID by src. return array( 'ID' => attachment_url_to_postid( $src ), ); } /** * Tries to convert an attachment IMG attr into a image size. * * @param string $attr The img attr. * @param string $content The all content. */ function powerkit_attachment_attr_to_size( $attr, $content = false ) { if ( ! isset( $attr['class'] ) ) { return; } // Set ID by class. if ( preg_match( '/size-(\S*)/i', $attr['class'], $matche ) ) { return $matche[1]; } // Set ID by parent class. if ( isset( $attr['src'] ) && $attr['src'] ) { $clear_content = str_replace( array( "\r\n", "\r", "\n" ), '', $content ); if ( preg_match( '#
[^<]*]*src="' . $attr['src'] . '"[^>]*>#', $clear_content, $matche ) ) { return $matche[1]; } } }