dgbrt
Forum Replies Created
-
Forum: Plugins
In reply to: [Simple Custom Post Order] Posts not ordering on Term Archive pagesThank you it was very helpful.
This is awesome! Just tested it and it worked right out of the gate. Thank you for being so re-active, it really helps my workflow ??
Hey Jordy, thanks for your dedication to this!
I updated the plugin and tried to play with the wr2x_get_wordpress_upload_root function, to no luck however.
Upload’s dir basedir / path still have one too many folder (or more), just like abspath.
here’s an example of what I get with abspath in it:
2015-04-15 17:25:12: From URL: /app/uploads/Mise_en_Scene_Monogramme_900-480x340.jpg 2015-04-15 17:25:12: We build wr2x_get_wordpress_upload_root + wr2x_get_pathinfo_from_image_src 2015-04-15 17:25:12: /srv/www/kaleidoscopeye.dev/current/web/wp/ + app/uploads/Mise_en_Scene_Monogramme_900-480x340.jpg 2015-04-15 17:25:12: Result is filepath : /srv/www/kaleidoscopeye.dev/current/web/wp/app/uploads/Mise_en_Scene_Monogramme_900-480x340.jpg -> this last filepath should be : /srv/www/kaleidoscopeye.dev/current/web/app/uploads/Mise_en_Scene_Monogramme_900-480x340.jpg
The problem I see is that the wp folder is in the same root folder as the app folder, it is as follow:
– root of wp install
— wp (with wp core)
— app (with upload, theme, etc)
— index.php
— wp-config.phpSo we need to find “root of wp install”, however even something like WP_CONTENT_DIR only returns the source of wp dir, and we need the one above it.
I thought of just removing the last directory to ABSPATH, but it wouldn’t work with a more complex structure.
I’ll see if I find a solution, here’s one resource I found:
https://discourse.roots.io/t/bedrock-and-upload-dir/1006/2Yes, me too
@jordy I basically applied the fix supplied by grahamharper onto the latest version, because it wasn’t really clear for me at first (as the function had changed). However it’s likely to break the cdn functionality or other stuff. I’m not sure, I just wanted my dev environment to work.
Hey guys, I stumbled upon the same problem, and had trouble fixing it. Can it be added in the plugin code so we don’t need this dirty hack anymore?
Here’s what work for me with the latest version of the plugin.// Replace the IMG tags by PICTURE tags with SRCSET function wr2x_picture_rewrite( $buffer ) { if ( !isset( $buffer ) || trim( $buffer ) === '' ) return $buffer; if ( !function_exists( "str_get_html" ) ) require('inc/simple_html_dom.php'); $lazysize = wr2x_getoption( "picturefill_lazysizes", "wr2x_advanced", false ) && wr2x_is_pro(); $killsrc = !wr2x_is_pro() || !wr2x_getoption( "picturefill_keep_src", "wr2x_advanced", false ); $nodes_count = 0; $nodes_replaced = 0; $html = str_get_html( $buffer ); if ( !$html ) { wr2x_log( "The HTML buffer is null, another plugin might block the process." ); return $buffer; } foreach( $html->find( 'img' ) as $element ) { $nodes_count++; $parent = $element->parent(); if ( $parent->tag == "picture" ) { wr2x_log("The img tag is inside a picture tag already. Tag ignored."); continue; } else { // replacement code for bedrock compatibility $file = basename( $element->src ); $upload_dir = wp_upload_dir(); $filepath = trailingslashit( $upload_dir['path'] ) . $file; // old code below // $img_pathinfo = wr2x_get_pathinfo_from_image_src( $element->src ); // $filepath = trailingslashit( ABSPATH ) . $img_pathinfo; $potential_retina = wr2x_get_retina( $filepath ); $from = substr( $element, 0 ); if ( $potential_retina != null ) { // replacement code for bedrock compatibility $retina_pathinfo = ltrim( str_replace( WP_CONTENT_DIR, "", $potential_retina ), '/' ); $retina_url = trailingslashit( content_url() ) . $retina_pathinfo; $img_url = $element->src; // old code below // $retina_url = wr2x_cdn_this( wr2x_from_system_to_url( $potential_retina ) ); // $retina_url = apply_filters( 'wr2x_img_retina_url', $retina_url ); // $img_url = wr2x_cdn_this( site_url( $img_pathinfo ) ); // $img_url = apply_filters( 'wr2x_img_url', $img_url ); if ( $lazysize ) { $element->class = $element->class . ' lazyload'; $element->{'data-srcset'} = "$img_url, $retina_url 2x"; } else $element->srcset = "$img_url, $retina_url 2x"; if ( $killsrc ) $element->src = null; else { $img_src = wr2x_cdn_this( $element->src ); $element->src = apply_filters( 'wr2x_img_src', $img_src ); } $to = $element; $buffer = str_replace( trim( $from, "</> "), trim( $to, "</> " ), $buffer ); wr2x_log( "The img tag '$from' was rewritten to '$to'" ); $nodes_replaced++; } else { wr2x_log( "The img tag was not rewritten. No retina for '" . $element->src . "'." ); } } } wr2x_log( "$nodes_replaced/$nodes_count were replaced." ); return $buffer; }