Skip to content

Commit

Permalink
Merge pull request #40 from iamdharmesh/variation-support
Browse files Browse the repository at this point in the history
Added Product variation image support.
  • Loading branch information
HazemKhaled authored Oct 10, 2020
2 parents 0c6d727 + 1821a4e commit b0fa6a3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
8 changes: 6 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: dharm1025,knawat,esl4m,firstanonymous
Tags: featured image, url, image url, image, woocommerce, remote featured image, product gallery
Requires PHP: 5.3
Requires at least: 4.0
Tested up to: 5.4
Tested up to: 5.5
WC tested up to: 4.0.1
Stable tag: 1.1.6
Stable tag: 1.1.7
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -64,6 +64,10 @@ Featured Image by URL allows to use an external URL Images as Featured Image for

== Changelog ==

= 1.1.7 =
* Fixed: bug related to product variation image display.
* Tested with WP 5.5

= 1.1.6 =
* Fixed: bug fix with WP version 5.4.
* Tested with latest versions of both Wordpress 5.4 and WooCommece 4.0.1.
Expand Down
2 changes: 1 addition & 1 deletion featured-image-by-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Featured Image by URL
* Plugin URI: https://wordpress.org/plugins/featured-image-by-url/
* Description: This plugin allows to use an external URL Images as Featured Image for your post types. Includes support for Product Gallery (WooCommece).
* Version: 1.1.4
* Version: 1.1.7
* Author: Knawat Team
* Author URI: https://github.com/Knawat
* License: GPL-2.0+
Expand Down
44 changes: 42 additions & 2 deletions includes/class-featured-image-by-url-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public function __construct() {
add_filter( 'woocommerce_structured_data_product', array( $this, 'knawatfibu_woo_structured_data_product_support' ), 99, 2 );
add_filter( 'facebook_for_woocommerce_integration_prepare_product', array( $this, 'knawatfibu_facebook_for_woocommerce_support' ), 99, 2 );
add_filter( 'shopzio_product_image_from_id', array( $this, 'knawatfibu_shopzio_product_image_url' ), 10, 2 );

if( !is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
add_action( 'init', array( $this, 'knawatfibu_set_thumbnail_id_true' ) );
add_filter( 'wp_get_attachment_image_src', array( $this, 'knawatfibu_replace_attachment_image_src' ), 10, 4 );
add_filter( 'woocommerce_product_get_gallery_image_ids', array( $this, 'knawatfibu_set_customized_gallary_ids' ), 99, 2 );
// Product Variation image Support
add_filter( 'woocommerce_available_variation', array( $this, 'knawatfibu_woocommerce_available_variation' ), 99, 3 );
}
// Add WooCommerce Product listable Thumbnail Support for Woo 3.5 or greater
add_action( 'admin_init', array( $this, 'knawatfibu_woo_thumb_support' ) );
Expand Down Expand Up @@ -532,4 +534,42 @@ function knawatfibu_shopzio_product_image_url( $image, $attachment_id ) {

return $image;
}
}

function knawatfibu_woocommerce_available_variation( $value, $variable_product, $variation ){
$variation_id = $variation->get_id();
if( empty( $variation_id ) ){
return $value;
}

global $knawatfibu;
// Product Variation Image
$variation_image = $knawatfibu->admin->knawatfibu_get_image_meta( $variation_id, true );
if( isset( $variation_image['img_url'] ) && !empty( $variation_image['img_url'] ) && isset($value['image'])){
$image_url = $variation_image['img_url'];
$width = (isset( $variation_image['width'] ) && !empty($variation_image['width'])) ? $variation_image['width'] : '';
$height = (isset( $variation_image['height'] ) && !empty($variation_image['height'])) ? $variation_image['height'] : '';

$value['image']['url'] = $image_url;
// Large version.
$value['image']['full_src'] = $image_url;
$value['image']['full_src_w'] = $width;
$value['image']['full_src_h'] = $height;

// Gallery thumbnail.
$value['image']['gallery_thumbnail_src'] = $image_url;
$value['image']['gallery_thumbnail_src_w'] = $width;
$value['image']['gallery_thumbnail_src_h'] = $height;

// Thumbnail version.
$value['image']['thumb_src'] = $image_url;
$value['image']['thumb_src_w'] = $width;
$value['image']['thumb_src_h'] = $height;

// Image version.
$value['image']['src'] = $image_url;
$value['image']['src_w'] = $width;
$value['image']['src_h'] = $height;
}
return $value;
}
}
42 changes: 21 additions & 21 deletions languages/featured-image-by-url.pot
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Copyright (C) 2018 Featured Image by URL
# Copyright (C) 2020 Featured Image by URL
# This file is distributed under the same license as the Featured Image by URL package.
msgid ""
msgstr ""
"Project-Id-Version: Featured Image by URL 1.1.0\n"
"Project-Id-Version: Featured Image by URL 1.1.7\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/featured-image-by-"
"url\n"
"POT-Creation-Date: 2018-04-16 06:24:46+00:00\n"
"POT-Creation-Date: 2020-10-02 12:53:04+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"

#: featured-image-by-url.php:79 featured-image-by-url.php:86
msgid "Cheatin&#8217; huh?"
msgstr ""

#. #-#-#-#-# featured-image-by-url.pot (Featured Image by URL 1.1.0) #-#-#-#-#
#. #-#-#-#-# feature-image-by-url.pot (Featured Image by URL 1.1.7) #-#-#-#-#
#. Plugin Name of the plugin/theme
#: includes/class-featured-image-by-url-admin.php:58
#: includes/class-featured-image-by-url-admin.php:275
#: includes/class-featured-image-by-url-admin.php:279
msgid "Featured Image by URL"
msgstr ""

Expand All @@ -32,67 +32,67 @@ msgstr ""
msgid "Error in Image URL"
msgstr ""

#: includes/class-featured-image-by-url-admin.php:319
#: includes/class-featured-image-by-url-admin.php:323
msgid "Settings"
msgstr ""

#: includes/class-featured-image-by-url-admin.php:327
#: includes/class-featured-image-by-url-admin.php:331
msgid "Disable Post types"
msgstr ""

#: includes/class-featured-image-by-url-admin.php:339
#: includes/class-featured-image-by-url-admin.php:343
msgid "Display Resized Images"
msgstr ""

#: includes/class-featured-image-by-url-admin.php:386
#: includes/class-featured-image-by-url-admin.php:390
msgid ""
"Please check checkbox for posttypes on which you want to disable Featured "
"image by URL."
msgstr ""

#: includes/class-featured-image-by-url-admin.php:405
#: includes/class-featured-image-by-url-admin.php:409
msgid ""
"Enable display resized images for image sizes like thumbnail, medium, large "
"etc.."
msgstr ""

#: includes/class-featured-image-by-url-admin.php:409
#: includes/class-featured-image-by-url-admin.php:413
msgid ""
"You need Jetpack plugin installed & connected for enable this functionality."
msgstr ""

#: includes/class-featured-image-by-url-admin.php:459
#: includes/class-featured-image-by-url-admin.php:463
msgid "Product Variation Image by URL"
msgstr ""

#: includes/class-featured-image-by-url-admin.php:467
#: includes/class-featured-image-by-url-admin.php:471
msgid "Product Variation Image URL"
msgstr ""

#: includes/class-featured-image-by-url-admin.php:469
#: templates/knawatfibu-metabox.php:12
#: includes/class-featured-image-by-url-admin.php:473
#: templates/knawatfibu-metabox.php:20
#: templates/knawatfibu-wcgallary-metabox.php:14
msgid "Preview"
msgstr ""

#: templates/knawatfibu-metabox.php:10
#: templates/knawatfibu-metabox.php:18
#: templates/knawatfibu-wcgallary-metabox.php:12
msgid "Image URL"
msgstr ""

#: templates/knawatfibu-metabox.php:15
#: templates/knawatfibu-metabox.php:23
msgid "Alt text (Optional)"
msgstr ""

#: templates/knawatfibu-metabox.php:18
#: templates/knawatfibu-metabox.php:26
msgid "No image"
msgstr ""

#: templates/knawatfibu-metabox.php:22
#: templates/knawatfibu-metabox.php:30
msgid "Remove Image"
msgstr ""

#: templates/knawatfibu-metabox.php:53
#: templates/knawatfibu-metabox.php:59
#: templates/knawatfibu-wcgallary-metabox.php:61
msgid "Error URL Image"
msgstr ""
Expand Down

0 comments on commit b0fa6a3

Please sign in to comment.