Skip to content

Commit

Permalink
Fix relative image uris (#181)
Browse files Browse the repository at this point in the history
* Added base path for images relative urls
  • Loading branch information
pedromcp90 authored Aug 11, 2023
1 parent 00a22c0 commit 89a33df
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doofinder-for-woocommerce/doofinder-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Doofinder WP & WooCommerce Search
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Version: 2.0.11
* Version: 2.0.12
* Author: Doofinder
* Description: Integrate Doofinder Search in your WordPress site or WooCommerce shop.
*
Expand Down Expand Up @@ -35,7 +35,7 @@ class Doofinder_For_WordPress
*
* @var string
*/
public static $version = '2.0.11';
public static $version = '2.0.12';

/**
* The only instance of Doofinder_For_WordPress
Expand Down
20 changes: 19 additions & 1 deletion doofinder-for-woocommerce/includes/class-rest-api-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ private static function add_df_image_link($product)
$thumbnail = new Thumbnail(get_post($post->post_parent));
$image_link = $thumbnail->get();
}

//If neither the variant and the product have an image, return the woocommerce placeholder image
$product['df_image_link'] = empty($image_link) ? wc_placeholder_img_src(Thumbnail::get_size()) : $image_link;
$image_link = empty($image_link) ? wc_placeholder_img_src(Thumbnail::get_size()) : $image_link;
$image_link = self::add_base_url_if_needed($image_link);

$product['df_image_link'] = $image_link;
return $product;
}

Expand Down Expand Up @@ -159,4 +163,18 @@ private static function add_df_prices($product)
}
return $product;
}

/**
* Check that image link is absolute, if not, add the site url
*
* @param string $image_link
* @return string $image_link
*/
private static function add_base_url_if_needed($image_link)
{
if (0 === strpos($image_link, "/")) {
$image_link = get_site_url() . $image_link;
}
return $image_link;
}
}
5 changes: 4 additions & 1 deletion doofinder-for-woocommerce/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== Doofinder WP & WooCommerce Search ===
Contributors: Doofinder
Tags: search, autocomplete
Version: 2.0.11
Version: 2.0.12
Requires at least: 4.1
Tested up to: 6.2.2
Requires PHP: 5.6
Expand Down Expand Up @@ -82,6 +82,9 @@ Just send your questions to <mailto:[email protected]> and we will try to an

== Changelog ==

= 2.0.12 =
Fixed relative image urls.

= 2.0.11 =
Added some improvements in REST API Handler

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doofinder-woocommerce",
"version": "2.0.11",
"version": "2.0.12",
"description": "Integrate Doofinder in your WooCommerce site with (almost) no effort.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 89a33df

Please sign in to comment.