Featured Image From URL - Version 1.1

Version Description

  • Now it's possible to use external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server).

=

Download this release

Release Info

Developer marceljm
Plugin Icon 128x128 Featured Image From URL
Version 1.1
Comparing to
See all releases

Code changes from version 1.0.2 to 1.1

admin/html/js/menu.js CHANGED
@@ -1,20 +1,20 @@
1
- function invert() {
2
- if (jQuery("#fifu_toggle").attr("class") == "toggleon") {
3
- jQuery("#fifu_toggle").attr("class", "toggleoff");
4
- jQuery("#fifu_input_backlink").val(0);
5
  }
6
  else {
7
- jQuery("#fifu_toggle").attr("class", "toggleon");
8
- jQuery("#fifu_input_backlink").val(1);
9
  }
10
  }
11
 
12
  jQuery(function () {
13
  var url = window.location.href;
14
 
15
- jQuery("#fifu_form").submit(function () {
16
 
17
- var frm = jQuery("#fifu_form");
18
 
19
  jQuery.ajax({
20
  type: frm.attr('method'),
@@ -25,4 +25,19 @@ jQuery(function () {
25
  }
26
  });
27
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  });
1
+ function invert(id) {
2
+ if (jQuery("#fifu_toggle_" + id).attr("class") == "toggleon") {
3
+ jQuery("#fifu_toggle_" + id).attr("class", "toggleoff");
4
+ jQuery("#fifu_input_" + id).val('off');
5
  }
6
  else {
7
+ jQuery("#fifu_toggle_" + id).attr("class", "toggleon");
8
+ jQuery("#fifu_input_" + id).val('on');
9
  }
10
  }
11
 
12
  jQuery(function () {
13
  var url = window.location.href;
14
 
15
+ jQuery("#fifu_form_backlink").submit(function () {
16
 
17
+ var frm = jQuery("#fifu_form_backlink");
18
 
19
  jQuery.ajax({
20
  type: frm.attr('method'),
25
  }
26
  });
27
  });
28
+
29
+ jQuery("#fifu_form_woocommerce").submit(function () {
30
+
31
+ var frm = jQuery("#fifu_form_woocommerce");
32
+
33
+ jQuery.ajax({
34
+ type: frm.attr('method'),
35
+ url: url,
36
+ data: frm.serialize(),
37
+ success: function (data) {
38
+ //alert('saved');
39
+ }
40
+ });
41
+ });
42
+
43
  });
admin/html/js/wc-meta-box.js ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function wcRemoveImage(i) {
2
+ var inputUrl = "#fifu_input_url_" + i;
3
+ var button = "#fifu_button_" + i;
4
+ var image = "#fifu_image_" + i;
5
+ var inputAlt = "#fifu_input_alt_" + i;
6
+ var link = "#fifu_link_" + i;
7
+
8
+ jQuery(inputAlt).hide();
9
+ jQuery(image).hide();
10
+ jQuery(link).hide();
11
+
12
+ jQuery(inputAlt).val("");
13
+ jQuery(inputUrl).val("");
14
+
15
+ jQuery(inputUrl).show();
16
+ jQuery(button).show();
17
+ }
18
+
19
+ function wcPreviewImage(i) {
20
+ var inputUrl = "#fifu_input_url_" + i;
21
+ var button = "#fifu_button_" + i;
22
+ var image = "#fifu_image_" + i;
23
+ var inputAlt = "#fifu_input_alt_" + i;
24
+ var link = "#fifu_link_" + i;
25
+
26
+ var $url = jQuery(inputUrl).val();
27
+
28
+ if ($url) {
29
+ jQuery(inputUrl).hide();
30
+ jQuery(button).hide();
31
+
32
+ jQuery(image).css('background-image', "url('" + $url + "')");
33
+
34
+ jQuery(inputAlt).show();
35
+ jQuery(image).show();
36
+ jQuery(link).show();
37
+ }
38
+ }
admin/html/menu.html CHANGED
@@ -4,99 +4,139 @@
4
 
5
  <div class="wrap">
6
 
7
- <div class="box">
8
 
9
- <h2>Featured Image From URL</h2>
10
 
11
- <div class="greybox">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- <p>This plugin allows you to use an external image as Featured Image of your post, page or product (WooCommerce). For more information, refer to <a href="http://marceljm.com/wordpress/featured-image-from-url/" target="_blank">Featured Image From URL</a>. </p>
 
 
 
14
 
15
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- </div>
18
 
19
- <div class="box">
20
 
21
- <h2>Make a Donation</h2>
22
 
23
- <div class="greybox">
24
 
25
  <p>Featured Image From URL is completely free and without advertising. To help me to continue updating and improving it, please consider making a donation by <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8BLDLZ3HDBGQG" target="_blank">PayPal</a>. Thank you!</p>
26
 
27
- </div>
28
 
29
- </div>
30
 
31
- <div class="box">
32
 
33
- <h2>Suggestions For Improvement</h2>
34
 
35
- <div class="greybox">
36
 
37
  <p>Constructive suggestions for improvement are always welcome. Just send an email to <a href="mailto:contact@marceljm.com">contact@marceljm.com</a>. Your request can be available in next version.</p>
38
 
39
- </div>
40
 
41
- </div>
42
 
43
- <div class="box">
44
 
45
- <h2>Give This Plugin a 5-Star Rating</h2>
46
 
47
- <div class="greybox">
48
 
49
  <p>Do you really love Featured Image From URL? So give your <a href="https://wordpress.org/plugins/featured-image-from-url" target="_blank">rating</a> right now. It's very important for me and WordPress community too.</p>
50
 
51
- </div>
52
 
53
- </div>
54
 
55
- <div class="box">
56
 
57
- <h2>Backlink to Featured Image From URL</h2>
58
 
59
  <div class="greybox">
60
 
61
- <p>Do you mind if I put a invisible and not clickable backlink in your page/post? Just Googlebot will be able to see (but not follow) that. This may seem very simple but increases the plugin page position on Google without interfering with your site layout, performance or SEO : )</p>
62
 
63
  </div>
64
 
65
  <p/>
66
 
67
- <form
68
- id="fifu_form"
69
  action="javascript:void(0)"
70
  method="post">
71
 
72
- <input
73
  type="image"
74
  href="javascript:void(0)"
75
- id="fifu_toggle"
76
- onclick="invert()"
77
- name="fifu_toggle"
78
- class="<?php echo $enable; ?>"
79
  value=" ">
80
 
81
- <input
82
  type="hidden"
83
  id="fifu_input_backlink"
84
  name="fifu_input_backlink"
85
  value="" >
86
- </form>
87
 
88
- </div>
89
 
90
- <div class="box">
91
 
92
- <h2>About The Author</h2>
93
 
94
- <div class="greybox">
95
 
96
  <p>Hi! I'm Marcel Jacques Machado. Graduated in Computer Science, I work as a Software Engineer for almost a decade. I already worked with C, Python, Delphi, Shell Script and other programming languages and technologies. Nowadays, I develop web services for MasterCard in Brazil using Java. About PHP, this plugin, Featured Image From URL, is my first pratical experience. I also have a <a href="http://marceljm.com/" target="_blank">blog</a> in WordPress and I expect to post some useful content very soon.
97
 
98
- </div>
99
 
100
- </div>
101
 
102
  </div>
4
 
5
  <div class="wrap">
6
 
7
+ <div class="box">
8
 
9
+ <h2>Featured Image From URL</h2>
10
 
11
+ <div class="greybox">
12
+
13
+ <p>This plugin allows you to use an external image as Featured Image of your post, page or WooCommerce product. And now it's possible to use external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server). For more information, refer to <a href="https://wordpress.org/plugins/featured-image-from-url/faq/" target="_blank">FAQ</a> and <a href="https://wordpress.org/plugins/featured-image-from-url/screenshots/" target="_blank">screenshots</a>. </p>
14
+
15
+ </div>
16
+
17
+ </div>
18
+
19
+ <div class="box">
20
+
21
+ <h2>WooCommerce Full Integration</h2>
22
+
23
+ <div class="greybox">
24
+
25
+ <p>Would you like to integrate WooCommerce to Featured Image From URL? For that, a script will be executed to overwrite some lines of code from WooCommerce plugin. It's safe and reversible but it will only work if your site is hosted on a Linux server. So let me check...</p>
26
+
27
+ <p/>
28
+
29
+ <?php echo $compatible; ?>
30
+
31
+ </div>
32
+
33
+ <p/>
34
 
35
+ <form
36
+ id="fifu_form_woocommerce"
37
+ action="javascript:void(0)"
38
+ method="post">
39
 
40
+ <input
41
+ type="image"
42
+ href="javascript:void(0)"
43
+ id="fifu_toggle_woocommerce"
44
+ onclick="invert('woocommerce')"
45
+ name="fifu_toggle_woocommerce"
46
+ class="<?php echo $enable_woocommerce; ?>"
47
+ value=" "
48
+ style="<?php echo $show_woocommerce_button; ?>">
49
+
50
+ <input
51
+ type="hidden"
52
+ id="fifu_input_woocommerce"
53
+ name="fifu_input_woocommerce"
54
+ value="" >
55
+ </form>
56
 
57
+ </div>
58
 
59
+ <div class="box">
60
 
61
+ <h2>Make a Donation</h2>
62
 
63
+ <div class="greybox">
64
 
65
  <p>Featured Image From URL is completely free and without advertising. To help me to continue updating and improving it, please consider making a donation by <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8BLDLZ3HDBGQG" target="_blank">PayPal</a>. Thank you!</p>
66
 
67
+ </div>
68
 
69
+ </div>
70
 
71
+ <div class="box">
72
 
73
+ <h2>Suggestions For Improvement</h2>
74
 
75
+ <div class="greybox">
76
 
77
  <p>Constructive suggestions for improvement are always welcome. Just send an email to <a href="mailto:contact@marceljm.com">contact@marceljm.com</a>. Your request can be available in next version.</p>
78
 
79
+ </div>
80
 
81
+ </div>
82
 
83
+ <div class="box">
84
 
85
+ <h2>Give This Plugin a 5-Star Rating</h2>
86
 
87
+ <div class="greybox">
88
 
89
  <p>Do you really love Featured Image From URL? So give your <a href="https://wordpress.org/plugins/featured-image-from-url" target="_blank">rating</a> right now. It's very important for me and WordPress community too.</p>
90
 
91
+ </div>
92
 
93
+ </div>
94
 
95
+ <div class="box">
96
 
97
+ <h2>Backlink to Featured Image From URL</h2>
98
 
99
  <div class="greybox">
100
 
101
+ <p>Do you mind if I put a invisible and not clickable backlink in your page/post/product? Just Googlebot will be able to see (but not follow) that. This may seem very simple but increases the plugin page position on Google without interfering with your site layout, performance or SEO : )</p>
102
 
103
  </div>
104
 
105
  <p/>
106
 
107
+ <form
108
+ id="fifu_form_backlink"
109
  action="javascript:void(0)"
110
  method="post">
111
 
112
+ <input
113
  type="image"
114
  href="javascript:void(0)"
115
+ id="fifu_toggle_backlink"
116
+ onclick="invert('backlink')"
117
+ name="fifu_toggle_backlink"
118
+ class="<?php echo $enable_backlink; ?>"
119
  value=" ">
120
 
121
+ <input
122
  type="hidden"
123
  id="fifu_input_backlink"
124
  name="fifu_input_backlink"
125
  value="" >
126
+ </form>
127
 
128
+ </div>
129
 
130
+ <div class="box">
131
 
132
+ <h2>About The Author</h2>
133
 
134
+ <div class="greybox">
135
 
136
  <p>Hi! I'm Marcel Jacques Machado. Graduated in Computer Science, I work as a Software Engineer for almost a decade. I already worked with C, Python, Delphi, Shell Script and other programming languages and technologies. Nowadays, I develop web services for MasterCard in Brazil using Java. About PHP, this plugin, Featured Image From URL, is my first pratical experience. I also have a <a href="http://marceljm.com/" target="_blank">blog</a> in WordPress and I expect to post some useful content very soon.
137
 
138
+ </div>
139
 
140
+ </div>
141
 
142
  </div>
admin/html/meta-box.html CHANGED
@@ -3,16 +3,16 @@
3
  <!-- show alt field, image and remove link if URL was already provided -->
4
 
5
  <input id="fifu_input_alt"
6
- type="text"
7
- name="fifu_input_alt"
8
- placeholder="alt attribute (optional)"
9
- value="<?php echo $alt; ?>"
10
- style="<?php echo $width, $margin, $show_alt ?>" />
11
 
12
  <div id="fifu_image"
13
- style="<?php echo $height, $margin, $show_image ?>
14
- background:url('<?php echo $url; ?>') no-repeat center center;
15
- background-size:cover;" >
16
  </div>
17
 
18
  <p/>
@@ -25,11 +25,11 @@
25
  <!-- show URL field and preview button if URL was not provided yet -->
26
 
27
  <input id="fifu_input_url"
28
- type="text"
29
- name="fifu_input_url"
30
- placeholder="URL"
31
- value="<?php echo $url; ?>"
32
- style="<?php echo $width, $margin, $show_url ?>" />
33
 
34
  <a id="fifu_button"
35
  class="button"
3
  <!-- show alt field, image and remove link if URL was already provided -->
4
 
5
  <input id="fifu_input_alt"
6
+ type="text"
7
+ name="fifu_input_alt"
8
+ placeholder="alt attribute (optional)"
9
+ value="<?php echo $alt; ?>"
10
+ style="<?php echo $width, $margin, $show_alt ?>" />
11
 
12
  <div id="fifu_image"
13
+ style="<?php echo $height, $margin, $show_image ?>
14
+ background:url('<?php echo $url; ?>') no-repeat center center;
15
+ background-size:cover;" >
16
  </div>
17
 
18
  <p/>
25
  <!-- show URL field and preview button if URL was not provided yet -->
26
 
27
  <input id="fifu_input_url"
28
+ type="text"
29
+ name="fifu_input_url"
30
+ placeholder="URL"
31
+ value="<?php echo $url; ?>"
32
+ style="<?php echo $width, $margin, $show_url ?>" />
33
 
34
  <a id="fifu_button"
35
  class="button"
admin/html/wc-meta-box.html ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script><?php include 'js/wc-meta-box.js' ?></script>
2
+
3
+ <!-- show alt field, remove button and image if URL was already provided -->
4
+
5
+ <input id="fifu_input_alt_<?php echo $i; ?>"
6
+ type="text"
7
+ name="fifu_input_alt_<?php echo $i; ?>"
8
+ placeholder="alt attribute (required)"
9
+ value="<?php echo $alt[$i]; ?>"
10
+ style="<?php echo $altWidth, $show_alt[$i], $top ?>" />
11
+
12
+ <a id="fifu_link_<?php echo $i; ?>"
13
+ class="button"
14
+ href="#"
15
+ onClick="wcRemoveImage(<?php echo $i; ?>);"
16
+ style="<?php echo $show_link[$i], $top ?>" >x</a>
17
+
18
+ <div id="fifu_image_<?php echo $i; ?>"
19
+ style="<?php echo $height, $margin, $show_image[$i] ?>
20
+ background:url('<?php echo $url[$i]; ?>') no-repeat center center;
21
+ background-size:cover;" >
22
+ </div>
23
+
24
+ <!-- show URL field and preview button if URL was not provided yet -->
25
+
26
+ <input id="fifu_input_url_<?php echo $i; ?>"
27
+ type="text"
28
+ name="fifu_input_url_<?php echo $i; ?>"
29
+ placeholder="URL"
30
+ value="<?php echo $url[$i]; ?>"
31
+ style="<?php echo $width, $margin, $show_url[$i] ?>" />
32
+
33
+ <a id="fifu_button_<?php echo $i; ?>"
34
+ class="button"
35
+ onClick="wcPreviewImage(<?php echo $i; ?>);"
36
+ style="<?php echo $align, $margin, $show_button[$i] ?>" >Preview</a>
admin/menu.php CHANGED
@@ -10,7 +10,7 @@ function fifu_insert_menu() {
10
  'featured-image-from-url',
11
  'fifu_get_menu_html',
12
  plugins_url() . '/featured-image-from-url/admin/images/favicon.png'
13
- );
14
 
15
  add_action('admin_init', 'fifu_get_menu_settings');
16
  }
@@ -18,20 +18,57 @@ function fifu_insert_menu() {
18
  function fifu_get_menu_html() {
19
  $image_button = plugins_url() . '/featured-image-from-url/admin/images/onoff.jpg';
20
 
21
- $enable = get_option('fifu_backlink');
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  include 'html/menu.html';
24
 
25
- if ((int) $_POST['fifu_input_backlink'])
26
- update_option('fifu_backlink', 'toggleon');
27
- else
28
- update_option('fifu_backlink', 'toggleoff');
29
  }
30
 
31
  function fifu_get_menu_settings() {
32
- register_setting('settings-group', 'fifu_backlink');
 
 
 
 
 
 
 
33
 
34
- if (!get_option('fifu_backlink'))
35
- update_option('fifu_backlink', 'toggleoff');
 
 
 
 
 
 
 
 
 
 
36
  }
37
 
 
 
 
 
 
 
 
 
10
  'featured-image-from-url',
11
  'fifu_get_menu_html',
12
  plugins_url() . '/featured-image-from-url/admin/images/favicon.png'
13
+ );
14
 
15
  add_action('admin_init', 'fifu_get_menu_settings');
16
  }
18
  function fifu_get_menu_html() {
19
  $image_button = plugins_url() . '/featured-image-from-url/admin/images/onoff.jpg';
20
 
21
+ $enable_backlink = get_option('fifu_backlink');
22
+ $enable_woocommerce = get_option('fifu_woocommerce');
23
+
24
+ $show_woocommerce_button = "";
25
+ $output = shell_exec('uname -s');
26
+ if ($output == "") {
27
+ $compatible = "Unfortunatelly, the script and your server system are not compatible =/";
28
+ $show_woocommerce_button = "display:none";
29
+ } else {
30
+ if (strpos($output, "Linux") !== false)
31
+ $compatible = "You server is using $output system. Great! The script will work =)";
32
+ else
33
+ $compatible = "You server is using $output system. The script may work. <p/>Please, send an email to <a href='mailto:contact@marceljm.com'>contact@marceljm.com</a> informing your server system and let me know if it worked for you.";
34
+ }
35
 
36
  include 'html/menu.html';
37
 
38
+ fifu_update_menu_options();
39
+
40
+ fifu_script_woocommerce();
 
41
  }
42
 
43
  function fifu_get_menu_settings() {
44
+ fifu_get_setting('fifu_backlink');
45
+ fifu_get_setting('fifu_woocommerce');
46
+ }
47
+
48
+ function fifu_update_menu_options() {
49
+ fifu_update_option('fifu_input_backlink', 'fifu_backlink');
50
+ fifu_update_option('fifu_input_woocommerce', 'fifu_woocommerce');
51
+ }
52
 
53
+ function fifu_get_setting($type) {
54
+ register_setting('settings-group', $type);
55
+
56
+ if (!get_option($type))
57
+ update_option($type, 'toggleoff');
58
+ }
59
+
60
+ function fifu_update_option($input, $type) {
61
+ if ($_POST[$input] == 'on')
62
+ update_option($type, 'toggleon');
63
+ else if ($_POST[$input] == 'off')
64
+ update_option($type, 'toggleoff');
65
  }
66
 
67
+ function fifu_script_woocommerce() {
68
+ if (get_option('fifu_woocommerce') == 'toggleon')
69
+ $command = "sh ../wp-content/plugins/featured-image-from-url/scripts/enableWoocommerce.sh";
70
+ else
71
+ $command = "sh ../wp-content/plugins/featured-image-from-url/scripts/disableWoocommerce.sh";
72
+
73
+ shell_exec($command);
74
+ }
admin/meta-box.php CHANGED
@@ -6,18 +6,45 @@ function fifu_insert_meta_box() {
6
  $post_types = array('post', 'page', 'product');
7
 
8
  foreach ($post_types as $post_type) {
9
- add_meta_box(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  'Url Meta Box',
11
  'External Featured Image',
12
  'fifu_show_elements',
13
  $post_type,
14
  'side',
15
  'default'
16
- );
 
17
  }
18
  }
19
 
20
  function fifu_show_elements($post) {
 
 
 
 
 
21
  $url = get_post_meta($post->ID, 'fifu_image_url', true);
22
  $alt = get_post_meta($post->ID, 'fifu_image_alt', true);
23
 
@@ -26,12 +53,27 @@ function fifu_show_elements($post) {
26
  else
27
  $show_alt = $show_image = $show_link = 'display:none;';
28
 
29
- $margin = 'margin-top:10px;';
30
- $width = 'width:100%;';
 
 
 
 
31
  $height = 'height:266px;';
32
  $align = 'text-align:left;';
 
33
 
34
- include 'html/meta-box.html';
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
  add_action('save_post', 'fifu_save_image_properties');
@@ -42,5 +84,20 @@ function fifu_save_image_properties($post_id) {
42
 
43
  if (isset($_POST['fifu_input_alt']))
44
  update_post_meta($post_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
 
 
6
  $post_types = array('post', 'page', 'product');
7
 
8
  foreach ($post_types as $post_type) {
9
+ if ($post_type == 'product') {
10
+ add_meta_box(
11
+ 'Url Meta Box',
12
+ 'External Product Image',
13
+ 'fifu_show_elements',
14
+ $post_type,
15
+ 'side',
16
+ 'default'
17
+ );
18
+ if (get_option('fifu_woocommerce') == 'toggleon') {
19
+ add_meta_box(
20
+ 'WooCommerce Gallery Meta Box',
21
+ 'External Product Gallery',
22
+ 'fifu_wc_show_elements',
23
+ $post_type,
24
+ 'side',
25
+ 'default'
26
+ );
27
+ }
28
+ }
29
+ else {
30
+ add_meta_box(
31
  'Url Meta Box',
32
  'External Featured Image',
33
  'fifu_show_elements',
34
  $post_type,
35
  'side',
36
  'default'
37
+ );
38
+ }
39
  }
40
  }
41
 
42
  function fifu_show_elements($post) {
43
+ $margin = 'margin-top:10px;';
44
+ $width = 'width:100%;';
45
+ $height = 'height:266px;';
46
+ $align = 'text-align:left;';
47
+
48
  $url = get_post_meta($post->ID, 'fifu_image_url', true);
49
  $alt = get_post_meta($post->ID, 'fifu_image_alt', true);
50
 
53
  else
54
  $show_alt = $show_image = $show_link = 'display:none;';
55
 
56
+ include 'html/meta-box.html';
57
+ }
58
+
59
+ function fifu_wc_show_elements($post) {
60
+ $margin = 'margin-top:1px;';
61
+ $width = 'width:70%;';
62
  $height = 'height:266px;';
63
  $align = 'text-align:left;';
64
+ $altWidth = 'width:86%;';
65
 
66
+ for ($i = 0; $i < 10; $i++) {
67
+ $url[$i] = get_post_meta($post->ID, 'fifu_image_url_' . $i, true);
68
+ $alt[$i] = get_post_meta($post->ID, 'fifu_image_alt_' . $i, true);
69
+
70
+ if ($url[$i])
71
+ $show_url[$i] = $show_button[$i] = 'display:none;';
72
+ else
73
+ $show_alt[$i] = $show_image[$i] = $show_link[$i] = 'display:none;';
74
+
75
+ include 'html/wc-meta-box.html';
76
+ }
77
  }
78
 
79
  add_action('save_post', 'fifu_save_image_properties');
84
 
85
  if (isset($_POST['fifu_input_alt']))
86
  update_post_meta($post_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
87
+
88
+ if (get_post_type(get_the_ID() == 'product')) {
89
+ for ($i = 0; $i < 10; $i++) {
90
+ if (isset($_POST['fifu_input_url_' . $i]) && isset($_POST['fifu_input_alt_' . $i])) {
91
+ if ($_POST['fifu_input_url_' . $i] != '' && $_POST['fifu_input_alt_' . $i] != '') {
92
+ update_post_meta($post_id, 'fifu_image_url_' . $i, esc_url($_POST['fifu_input_url_' . $i]));
93
+ update_post_meta($post_id, 'fifu_image_alt_' . $i, wp_strip_all_tags($_POST['fifu_input_alt_' . $i]));
94
+ } else {
95
+ delete_post_meta($post_id, 'fifu_image_url_' . $i);
96
+ delete_post_meta($post_id, 'fifu_image_alt_' . $i);
97
+ }
98
+ }
99
+ }
100
+ }
101
  }
102
 
103
+
featured-image-from-url.php CHANGED
@@ -2,8 +2,8 @@
2
 
3
  /*
4
  * Plugin Name: Featured Image From URL
5
- * Description: Allows you to use an external image as Featured Image of your post, page or product (WooCommerce).
6
- * Version: 1.0.2
7
  * Author: Marcel Jacques Machado
8
  * Author URI: http://marceljm.com
9
  */
@@ -17,3 +17,10 @@ if (is_admin()) {
17
  require_once( FIFU_ADMIN_DIR . '/meta-box.php' );
18
  require_once( FIFU_ADMIN_DIR . '/menu.php' );
19
  }
 
 
 
 
 
 
 
2
 
3
  /*
4
  * Plugin Name: Featured Image From URL
5
+ * Description: Allows you to use an external image as Featured Image of your post, page or WooCommerce product. And now it's possible to use external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server).
6
+ * Version: 1.1
7
  * Author: Marcel Jacques Machado
8
  * Author URI: http://marceljm.com
9
  */
17
  require_once( FIFU_ADMIN_DIR . '/meta-box.php' );
18
  require_once( FIFU_ADMIN_DIR . '/menu.php' );
19
  }
20
+
21
+ register_deactivation_hook( __FILE__, 'fifu_desactivate' );
22
+
23
+ function fifu_desactivate() {
24
+ update_option('fifu_woocommerce', 'toggleoff');
25
+ shell_exec('sh ../wp-content/plugins/featured-image-from-url/scripts/disableWoocommerce.sh');
26
+ }
includes/html/backlink.html CHANGED
@@ -1,6 +1,6 @@
1
  <a
2
  rel="nofollow"
3
- href="http://marceljm.com/wordpress/featured-image-from-url/"
4
  style="display:none;">
5
- Featured Image From URL is a WordPress plugin developed by marceljm.
6
  </a>
1
  <a
2
  rel="nofollow"
3
+ href="http://marceljm.com/"
4
  style="display:none;">
5
+ Featured Image From URL is a WordPress plugin developed by marceljm.com
6
  </a>
includes/html/thumbnail.html DELETED
@@ -1,5 +0,0 @@
1
- <!-- Featured Image from URL: http://marceljm.com/wordpress/featured-image-from-url/ -->
2
- <img
3
- src="<?php echo $image_url; ?>"
4
- alt="<?php echo $alt; ?>" >
5
- </img>
 
 
 
 
 
includes/thumbnail.php CHANGED
@@ -34,18 +34,16 @@ add_filter('post_thumbnail_html', 'fifu_replace', 10, 2);
34
 
35
  function fifu_replace($html, $post_id) {
36
  $image_url = get_post_meta($post_id, 'fifu_image_url', true);
 
37
 
38
  if ($image_url) {
39
- $html = fifu_get_html($post_id, $image_url);
40
  if (get_option('fifu_backlink') == 'toggleon')
41
  include 'html/backlink.html';
42
  }
43
-
44
  return $html;
45
  }
46
 
47
- function fifu_get_html($id, $image_url) {
48
- $alt = get_post_meta($id, 'fifu_image_alt', true);
49
- include 'html/thumbnail.html';
50
  }
51
-
34
 
35
  function fifu_replace($html, $post_id) {
36
  $image_url = get_post_meta($post_id, 'fifu_image_url', true);
37
+ $image_alt = get_post_meta($post_id, 'fifu_image_alt', true);
38
 
39
  if ($image_url) {
40
+ $html = fifu_get_html($post_id, $image_url, $image_alt);
41
  if (get_option('fifu_backlink') == 'toggleon')
42
  include 'html/backlink.html';
43
  }
 
44
  return $html;
45
  }
46
 
47
+ function fifu_get_html($id, $image_url, $image_alt) {
48
+ return sprintf('<!-- Featured Image from URL: http://marceljm.com/wordpress/featured-image-from-url/ --> <img src="%s" alt="%s"></img>', $image_url, $image_alt);
 
49
  }
 
readme.txt CHANGED
@@ -1,24 +1,25 @@
1
  === Plugin Name ===
2
  Contributors: marceljm
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8BLDLZ3HDBGQG
4
- Tags: featured image, external featured image, featured image from url, url featured image, featured, image, external, from, url, flickr, woocommerce
5
  Requires at least: 4.0
6
- Tested up to: 4.3.1
7
- Stable tag: 4.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Allows you to use an external image as Featured Image of your post, page or product (WooCommerce).
12
 
13
  == Description ==
14
 
15
- Allows you to use an external image (from Flickr, Picasa, Amazon S3, anywhere etc) as Featured Image of your post, page or product (WooCommerce).
16
 
17
  == Installation ==
18
 
19
  1. Install automatically or by uploading the ZIP file.
20
  1. Activate the plugin through the 'Plugins' menu in WordPress.
21
- 1. The plugin settings will be immediately below or above the traditional "Featured Image" box, in the page/post editor.
 
22
 
23
  == Frequently Asked Questions ==
24
 
@@ -40,7 +41,7 @@ Allows you to use an external image (from Flickr, Picasa, Amazon S3, anywhere et
40
 
41
  = What's the "alt attribute" field? =
42
 
43
- * There you can write a short description of the image. It is optional.
44
 
45
  = What's the "Remove external featured image" link? =
46
 
@@ -48,19 +49,67 @@ Allows you to use an external image (from Flickr, Picasa, Amazon S3, anywhere et
48
 
49
  = What happens if I have two featured images (internal and external)? =
50
 
51
- * The external image has priority in this case and the internal image won't be showed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  == Screenshots ==
54
 
55
- 1. This plugin allows you to use an external image as Featured Image of your posts, pages or products (WooCommerce). Just fill the URL field with the image address and click on preview button.
56
 
57
  2. If the URL is correct, the image preview will be shown. Then you can define the image title, filling the ALT field.
58
 
59
- 3. The external image will be displayed with your post description.
 
 
 
 
 
 
 
 
60
 
61
- 4. The external image will be displayed on your post, page or product (WooCommerce).
62
-
63
- 5. The external image will be displayed when someone shares your post, page or product (WooCommerce) on social networks.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  == Changelog ==
66
 
@@ -73,6 +122,9 @@ Allows you to use an external image (from Flickr, Picasa, Amazon S3, anywhere et
73
  = 1.0.2 =
74
  * Now it's possible to use an external image as Featured Image of your WooCommerce products.
75
 
 
 
 
76
  == Upgrade Notice ==
77
 
78
  = 1.0 =
@@ -83,3 +135,6 @@ Allows you to use an external image (from Flickr, Picasa, Amazon S3, anywhere et
83
 
84
  = 1.0.2 =
85
  * Now it's possible to use an external image as Featured Image of your WooCommerce products.
 
 
 
1
  === Plugin Name ===
2
  Contributors: marceljm
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8BLDLZ3HDBGQG
4
+ Tags: featured image, external featured image, featured image from url, url featured image, featured, image, external, url, flickr, woocommerce, product image, product gallery, product, gallery
5
  Requires at least: 4.0
6
+ Tested up to: 4.4
7
+ Stable tag: 4.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Allows you to use an external image as Featured Image of your post, page or WooCommerce product. And now it's possible to use external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server).
12
 
13
  == Description ==
14
 
15
+ Allows you to use an external image (from Flickr, Picasa, Amazon S3, anywhere etc) as Featured Image of your post, page or WooCommerce product. And now it's possible to use external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server).
16
 
17
  == Installation ==
18
 
19
  1. Install automatically or by uploading the ZIP file.
20
  1. Activate the plugin through the 'Plugins' menu in WordPress.
21
+ 1. The plugin settings will be in the left column, between 'Appearance' and 'Collapse menu' icons.
22
+ 1. And a new box will be shown immediately below or above the traditional "Featured Image" box, in the page/post/product editor.
23
 
24
  == Frequently Asked Questions ==
25
 
41
 
42
  = What's the "alt attribute" field? =
43
 
44
+ * There you can write a short description of the image. It is optional for pages and posts, but required for products.
45
 
46
  = What's the "Remove external featured image" link? =
47
 
49
 
50
  = What happens if I have two featured images (internal and external)? =
51
 
52
+ * The external image has priority in this case and the internal image won't be shown.
53
+
54
+ = Why aren't the external images showing in my site?
55
+
56
+ * Because your theme is nonstandard. For US$ 50,00, I can analyse your theme code and make the required changes.
57
+
58
+ = How to integrate WooCommerce and Featured Image From URL?
59
+
60
+ * There is a toggle (on/off) in Featured Image From URL settings. When enabled, a shell script is executed to overwrite some code lines from WooCommerce plugin. Otherwise, the changes are undone.
61
+
62
+ = What happens to the WooCommerce plugin if I deactivate Featured Image From URL?
63
+
64
+ * When the plugin is deactivated, all the changes done by Featured Image From URL in WooCommerce code are undone.
65
+
66
+ = Why WooCommerce integration isn't working/possible?
67
+
68
+ * Because the integration script just work on a Linux server.
69
+
70
+ = Why aren't my external images in WooCommerce Product Gallery being saved?
71
+
72
+ * Because you are not filling the alt attribute field. It's required by WooCommerce.
73
 
74
  == Screenshots ==
75
 
76
+ 1. This plugin allows you to use an external image as Featured Image of your pages. Just fill the URL field with the image address and click on preview button.
77
 
78
  2. If the URL is correct, the image preview will be shown. Then you can define the image title, filling the ALT field.
79
 
80
+ 3. The external image will be displayed on your page.
81
+
82
+ 4. The external image will be displayed when someone shares your page on social networks.
83
+
84
+ 5. Besides that, this plugin allows you to use an external image as Featured Image of your posts. Just fill the URL field with the image address and click on preview button.
85
+
86
+ 6. If the URL is correct, the image preview will be shown. Then you can define the image title, filling the ALT field.
87
+
88
+ 7. The external image will be displayed in your post gallery.
89
 
90
+ 8. The external image will be displayed in your post.
91
+
92
+ 9. The external image will be displayed when someone shares your post on social networks.
93
+
94
+ 10. Moreover, you can integrate this plugin to WooCommerce. Just access Featured Image From URL settings and enable that. Then a shell script will be executed to overwrite some code lines from WooCommerce plugin. But don't worry about that, because moving the toggle to off will undone the changes. Unfortunatelly, the integration requires your site be running in a Linux server. So, if the toggle didn't appear, it's because your server uses a different system.
95
+
96
+ 11. Now you can use an external image as Featured Image of your WooCommerce products. Just fill the URL field with the image address and click on preview button.
97
+
98
+ 12. If the URL is correct, the image preview will be shown. Then you can define the image title, filling the ALT field.
99
+
100
+ 13. It's also possible to use external images in the WooCommerce Product Gallery. Fill an URL field with the image address and click on preview button.
101
+
102
+ 14. If the URL is correct, the image preview will be shown. Then you must define the image title, filling the ALT field.
103
+
104
+ 15. And if you have more images, just fill the others URL fields with the image address and click on preview button.
105
+
106
+ 16. If the URL is correct, the image preview will be shown. Then you must define the image title, filling the ALT field.
107
+
108
+ 17. The external images will be displayed on your product.
109
+
110
+ 18. The same effects of the internal featured image will work for your external featured image.
111
+
112
+ 19. The same effects of internal images will work for your external images in the product gallery.
113
 
114
  == Changelog ==
115
 
122
  = 1.0.2 =
123
  * Now it's possible to use an external image as Featured Image of your WooCommerce products.
124
 
125
+ = 1.1 =
126
+ * Now it's possible to use external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server).
127
+
128
  == Upgrade Notice ==
129
 
130
  = 1.0 =
135
 
136
  = 1.0.2 =
137
  * Now it's possible to use an external image as Featured Image of your WooCommerce products.
138
+
139
+ = 1.1 =
140
+ * Now it's possible to use until 10 external images in the WooCommerce Product Gallery (since your site is hosted on a Linux server). Go to Featured Image From URL settings to enable that.
scripts/disableWoocommerce.sh ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ dir='../wp-content/plugins/woocommerce/templates/single-product/'
4
+
5
+ restoreProductImage()
6
+ {
7
+ file=$dir'product-image.php'
8
+ mv $file'.bkp' $file
9
+ }
10
+
11
+ restoreProductThumbnails()
12
+ {
13
+ file=$dir'product-thumbnails.php'
14
+ mv $file'.bkp' $file
15
+ }
16
+
17
+ restore()
18
+ {
19
+ restoreProductImage
20
+ restoreProductThumbnails
21
+ }
22
+
23
+ restore
scripts/enableWoocommerce.sh ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ dir='../wp-content/plugins/woocommerce/templates/single-product/'
4
+
5
+ featured_image()
6
+ {
7
+ file=$dir'product-image.php'
8
+ old='$image_link.*wp_get_attachment_url.*get_post_thumbnail_id.*;'
9
+ new='$image_link=get_post_meta($post->ID,"fifu_image_url",true);\
10
+ if($image_link=="")\
11
+ $image_link=wp_get_attachment_url(get_post_thumbnail_id());'
12
+ replace
13
+ }
14
+
15
+ gallery()
16
+ {
17
+ file=$dir'product-thumbnails.php'
18
+ old='if.*$attachment_ids.*{'
19
+ new='if(true){'
20
+ replace
21
+
22
+ old='?><\/div>'
23
+ new='\
24
+ for($i=0;$i<10;$i++){\
25
+ $image_link=get_post_meta($post->ID,"fifu_image_url_".$i,true);\
26
+ if($image_link){\
27
+ $image_caption=get_post_meta($post->ID,"fifu_image_alt_".$i,true);\
28
+ $image_class="attachment-shop_thumbnail";\
29
+ $image=fifu_get_html($post->ID,$image_link,$image_caption);\
30
+ $attachment_id=1;\
31
+ echo\ apply_filters("woocommerce_single_product_image_thumbnail_html",\
32
+ sprintf("<a\ href='%s'\ class='%s'\ title='%s'\ data-rel='prettyPhoto[product-gallery]'>%s<\/a>",\
33
+ $image_link,$image_class,$image_caption,$image),$attachment_id,$post->ID,$image_class);\
34
+ }\
35
+ }\
36
+ ?><\/div>'
37
+ replace
38
+ }
39
+
40
+ replace()
41
+ {
42
+ integrated=`egrep "fifu_image_url" $file`
43
+ if [[ ! $integrated ]]
44
+ then
45
+ backup
46
+ sed -i "s/$old/$new/" $file
47
+ fi
48
+ }
49
+
50
+ backup()
51
+ {
52
+ cp $file $file'.bkp'
53
+ }
54
+
55
+ featured_image
56
+
57
+ gallery