Image Resizer Fails in Some WPML Configurations
-
I have fix for this issue, which I want to bring it to your attention, and I need you to confirm my proposed fix will not have an unintended consequence I am yet to discover.
The Details
I have a WPML site that uses domain mapping. The Spanish and English versions of the site have different root domain names. Domain mapping is provided through a WPML feature that allows different domains to be used for different sites as opposed to the standard set up of different directories, subdomains or query strings for each site.
The root site is Spanish.
The secondary site is English.Images are not created for the English site. It appears the image resizer is not able to ascertain the URL of feature images because the domain name of the English site is not the same as the domain name of the Spanish site.
The first time I created a WP Show Posts shortcode for this specific site I used the same shortcode in both En & Es versions of the site. The image src was not found for the En site (that’s pretty much the message in the HTML source). Images did show in the Es site.
The second time I created a WP Show Posts shortcode I duplicated the (first) Spanish site’s shortcode post then switched to the English site to reconfigure the taxonomy settings. Images still failed to show for the English site.
The third time I tested WP Show Posts I connected the En and Es translations. Same error. No images shown by WP Show Posts shortcodes in the English version of the site.
Proposed Fix
Looking at the WP Show Posts code I can see the below function at the bottom of the inc/image-resizer.php:
if ( ! function_exists( 'WPSP_Resize' ) ) : /** * This is just a tiny wrapper function for the class above so that there is no * need to change any code in your own WP themes. Usage is still the same :) */ function WPSP_Resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { /* WPML Fix */ if ( defined( 'ICL_SITEPRESS_VERSION' ) ){ global $sitepress; $url = $sitepress->convert_url( $url, $sitepress->get_default_language() ); } /* Jetpack Photon fix */ if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) && function_exists( 'jetpack_photon_url' ) ) { $type = ( $crop ) ? 'resize' : 'fit'; $args = array( $type => $width . ',' . $height ); return jetpack_photon_url( $url, $args ); } $WPSP_Resize = WPSP_Resize::getInstance(); return $WPSP_Resize->process( $url, $width, $height, $crop, $single, $upscale ); } endif;
That WPML fix in that block of PHP is part of the problem. Disabling the fix resolves the issue to allow WP Show posts to display feature images in both En and Es versions of the site.
I suspect that where domain mapping is used within WPML that the WPML fix is unable to grab the correct details for mapped secondary sites.
I have used WP Show Posts with other WPML sites that do not use domain mapping. This issue does not exists in these sites.
- The topic ‘Image Resizer Fails in Some WPML Configurations’ is closed to new replies.