I didn’t mention, but I’m on version 1.4.2 of your plugin (last one I can see).
For now, I’ve worked around it with the following edits in wp-retina-2x.php (just on my local testing site):
Line 109:
//was $filepath = trailingslashit( ABSPATH ) . $img_pathinfo;
$filepath = '/Applications/MAMP/htdocs/' . $img_pathinfo;
Line 113:
//was $retina_pathinfo = ltrim( str_replace( ABSPATH, "", $potential_retina ), '/' );
$retina_pathinfo = ltrim( str_replace( 'Applications/MAMP/htdocs', "", $potential_retina ), '/' );
[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
So it’s ABSPATH that’s wrong – which comes from siteurl (I believe) – but changing that breaks my entire site!
It works on the live site, so I suspect my local install is wrong in some way, hopefully this can help other folks who might see something odd?
Hey Mark,
I am not sure what happens but ABSPATH could be defined wrongly, it happens…
By any chance, can you replace the wr2x_html_rewrite function with this one? It might work better…
function wr2x_html_rewrite( $buffer ) {
if ( !isset( $buffer ) || trim( $buffer ) === '' )
return $buffer;
$doc = new DOMDocument();
@$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'], '/' );
//$filepath = trailingslashit( ABSPATH ) . $img_pathinfo;
$filepath = site_url( $img_pathinfo );
$potential_retina = wr2x_get_retina( $filepath );
if ( $potential_retina != null ) {
wr2x_log( "Rewrite '{$filepath}' to '{$potential_retina}'." );
//$retina_pathinfo = ltrim( str_replace( ABSPATH, "", $potential_retina ), '/' );
$retina_pathinfo = ltrim( str_replace( site_url(), "", $potential_retina ), '/' );
$buffer = str_replace( $img_pathinfo, $retina_pathinfo, $buffer );
}
}
return $buffer;
}
If it works, I will do it this way and avoid using ABSPATH.
Sorry, I get the same error:
– The retina file ‘http://mac-pro.local:8888/wordpress/wordpress/wp-content/uploads/2013/06/Street-Art-Brighton-2-300×[email protected]’ cannot be found.
I wouldn’t worry about it – it works on my ‘live’ site without any changes, and if I’m the first to see it, I’m more than happy it’s my local test site being set up incorrectly.
I appreciate the efforts though, I suspect my ‘site_url’ is wrong, and it’s influencing everything that relies on it. If I change it, the site breaks but maybe I should look into that, since your plugin is clearly working OK otherwise 🙂
Yes, there is somebody strange on your localhost 🙂 Maybe you can try to check what gives your phpinfo()… Could be a starting point?