• Resolved jappievw

    (@jappievw)


    We have a wordpress setup based on a boilerplate from Git. This works perfect, except for the retina images in combination with rewrite and srcset options. After some debugging this is caused by files which can’t be found on the disk by the wp-retina-2x plugin.

    It is caused by a specific local configuration file which overrides the UPLOADS and WP_SITEURL constants. The image urls as generated by WordPress look like this: https://royalfish.local/wordpress/../uploads/2013/10/logo2-51x73.png. With the current algorithm the local file can’t be found, since it looks in the ABSPATH . 'wordpress/../uploads/2013/10/logo2-51x73.png' directory.

    Supposing that there are more people with a similar problem, I created a patch for this as follows (visually: https://note.io/1bzIUO4):

    diff --git wp-content/plugins/wp-retina-2x/wp-retina-2x.php wp-content/plugins/wp-retina-2x/wp-retina-2x.php
    index 96f1d8589fee98ddf3bde5635e4c1e1901cc90d0..b76179a13ed0597c5e6b925bf19fb408fca3f8e5 100644
    --- wp-content/plugins/wp-retina-2x/wp-retina-2x.php
    +++ wp-content/plugins/wp-retina-2x/wp-retina-2x.php
    @@ -107,8 +107,7 @@ function wr2x_srcset_rewrite( $buffer ) {
     	@$doc->loadHTML( mb_convert_encoding( $buffer, 'HTML-ENTITIES', 'UTF-8' ) ); // = ($doc->strictErrorChecking = false;)
     	$imageTags = $doc->getElementsByTagName('img');
     	foreach ( $imageTags as $tag ) {
    -		$img_info = parse_url( $tag->getAttribute('src') );
    -		$img_pathinfo = ltrim( $img_info['path'], '/' );
    +		$img_pathinfo = wr2x_get_pathinfo_from_image_src($tag->getAttribute('src'));
     		$filepath = trailingslashit( ABSPATH ) . $img_pathinfo;
     		$potential_retina = wr2x_get_retina( $filepath );
     		if ( $potential_retina != null ) {
    @@ -145,8 +144,7 @@ function wr2x_html_rewrite( $buffer ) {
     	@$doc->loadHTML( $buffer ); // = ($doc->strictErrorChecking = false;)
     	$imageTags = $doc->getElementsByTagName('img');
     	foreach ( $imageTags as $tag ) {
    -		$img_info = parse_url( $tag->getAttribute('src') );
    -		$img_pathinfo = ltrim( $img_info['path'], '/' );
    +		$img_pathinfo = wr2x_get_pathinfo_from_image_src($tag->getAttribute('src'));
     		$filepath = trailingslashit( ABSPATH ) . $img_pathinfo;
     		$potential_retina = wr2x_get_retina( $filepath );
     		if ( $potential_retina != null ) {
    @@ -164,6 +162,17 @@ function wr2x_html_rewrite( $buffer ) {
      *
      */ 
    
    +function wr2x_get_pathinfo_from_image_src($image_src) {
    +	$site_url = trailingslashit(site_url());
    +	if (strpos($image_src, $site_url) === 0) {
    +		return substr($image_src, strlen($site_url));
    +	}
    +	else {
    +		$img_info = parse_url( $image_src );
    +		return ltrim( $img_info['path'], '/' );
    +	}
    +}
    +
     // UPDATE THE ISSUE STATUS OF THIS ATTACHMENT
     function wr2x_update_issue_status( $attachmentId, $issues = null, $info = null ) {
     	if ( wr2x_is_ignore( $attachmentId ) )

    Can you include this (or similar code) to be able to be upgrade proof again?

    https://www.ads-software.com/plugins/wp-retina-2x/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    Did you try the new version of the plugin? Does it work better for you? If not, please submit me a change and I will integrate it for sure.

    Thread Starter jappievw

    (@jappievw)

    Yes, I just verified it, it isn’t fixed with the new version yet. However, the patch is shown above. It is still valid!

    Plugin Author Jordy Meow

    (@tigroumeow)

    Got it and sorry for the delay.
    I will publish a new version of the plugin immediately.
    Thanks a lot for your ping and code ??

    This will cause an issue when you use a custom uploads constant but also use a virtual drive inside wp-contents/uploads. Which is a common setup on amazon servers hosting wordpress.

    It will look up the filepath without the wp-content/uploads inside the file path. Which will fill up your error logs.

    is it possible to create a hook for wr2x_get_pathinfo_from_image_src() ? That way i can change the value however i see fit.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can't find retina file with custom UPLOADS constant’ is closed to new replies.