WordPress.org

Ready to get started?Download WordPress

Forums

WP Retina 2x
[resolved] Bug with method "HTML Rewrite" and fix (3 posts)

  1. Edward
    Member
    Posted 1 year ago #

    File: wp-retina-2x.php
    Version: 1.2.0
    Line: from 97

    $filepath = trailingslashit( $_SERVER['DOCUMENT_ROOT'] ) . $img_pathinfo;
    		$potential_retina = wr2x_get_retina( $filepath );
    		if ( $potential_retina != null ) {
    			$retina_pathinfo = ltrim( str_replace( $_SERVER['DOCUMENT_ROOT'], "", $potential_retina ), '/' );
    			$buffer = str_replace( $img_pathinfo, $retina_pathinfo, $buffer );
    		}

    The code here only works for WP site that installed in root directory, if the plugin is installed to a WP site that in a sub directory, it will fail to find the 2x version of image because the $filepath is wrong, to get the right path, replace $_SERVER['DOCUMENT_ROOT'] with ABSPATH which is set to the path of current site, so that the updated code:

    $filepath = trailingslashit( ABSPATH ) . $img_pathinfo;
    		$potential_retina = wr2x_get_retina( $filepath );
    		if ( $potential_retina != null ) {
    			$retina_pathinfo = ltrim( str_replace( ABSPATH, "", $potential_retina ), '/' );
    			$buffer = str_replace( $img_pathinfo, $retina_pathinfo, $buffer );
    		}

    http://wordpress.org/extend/plugins/wp-retina-2x/

  2. Edward
    Member
    Posted 1 year ago #

    By the way, what's the difference between "HTML Rewrite" and "Server Side"?

    Could there be a similar issue with "Server Side"?

  3. Jordy Meow
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks a lot, I love having my code reviewed, debugged, correct. I will commit those two changes in the next release :)

    HTML Rewrite REWRITES the HTML (haha) adding the retina images directly in the code when required (and if they are available).

    The Server-Side is a server handler for the images. The HTML is the same but the files sent by the server will be the retina one instead of the normal one if retina is detected.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic