From b4129a41039a3244c9283c93d8f16363901fc480 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Wed, 12 Sep 2018 21:40:48 +0800 Subject: [PATCH] Add support for WP Retina 2x (tested with free version), for post cover title image --- inc/template-tags.php | 80 ++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/inc/template-tags.php b/inc/template-tags.php index b74b09c..c7fbf8b 100755 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -629,6 +629,7 @@ function independent_publisher_full_width_featured_image() { $featured_image_srcset = function_exists( 'wp_get_attachment_image_srcset' ) ? wp_get_attachment_image_srcset( get_post_thumbnail_id() ) : false; $featured_image_srcset = $featured_image_srcset ? explode( ',', $featured_image_srcset ) : false; $featured_image_versions = array(); + $featured_image_high_dpi = array(); if ( $featured_image_srcset ) { foreach ( $featured_image_srcset as $url_width_str ) { @@ -640,44 +641,75 @@ function independent_publisher_full_width_featured_image() { } } - if ( $featured_image_versions ) { - usort( $featured_image_versions, - function ( $a, $b ) { - $a = intval( $a[1] ); - $b = intval( $b[1] ); - return $a < $b ? -1 : ($a > $b ? 1 : 0); + if ( $featured_image_versions && class_exists( 'Meow_WR2X_Core' ) ) { // WP Retina 2x support + $featured_image_base = array(); + foreach ( $featured_image_versions as $url_width ) { + if ( preg_match( '/.@2x\.\w+$/', $url_width[0] ) ) { + $url_width[1] = $url_width[1] / 2; + array_push( $featured_image_high_dpi, $url_width ); + } else { + array_push( $featured_image_base, $url_width ); } - ); + } + $featured_image_versions = $featured_image_base; + } + + function url_width_cmp( $a, $b ) { + $a = intval( $a[1] ); + $b = intval( $b[1] ); + return $a < $b ? -1 : ( $a > $b ? 1 : 0 ); + } + + usort( $featured_image_versions, 'url_width_cmp' ); + usort( $featured_image_high_dpi, 'url_width_cmp' ); + + function post_cover_title_image_css( $url ) { + ?> + .single.post-cover-overlay-post-title .post-cover-title-image, + .page.post-cover-overlay-post-title .post-cover-title-image { + background-image: url(); + } + +