Featured Image From URL - Version 2.0.0

Version Description

  • Beta Version (NOT STABLE): a lot of changes were done to overcome some old known issues in FIFU 1, such as problems in image sizes or images that were not shown in some areas, including WooCommerce lightbox and categories. Fake Internal Featured Image and Default External Featured Image features have changed. And Default Width was created.
Download this release

Release Info

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

Code changes from version 1.9.13 to 2.0.0

admin/category.php CHANGED
@@ -1,25 +1,27 @@
1
  <?php
2
 
3
- add_action('product_cat_edit_form_fields', 'fifu_cat_show_box');
4
- add_action('product_cat_add_form_fields', 'fifu_cat_show_box');
5
 
6
- function fifu_cat_show_box($term) {
7
  $margin = 'margin-top:10px;';
8
  $width = 'width:100%;';
9
  $height = 'height:200px;';
10
  $align = 'text-align:left;';
11
  $show_news = 'display:none';
12
  $is_sirv_active = is_plugin_active('sirv/sirv.php');
13
- $url = $alt = $show_button = $show_alt = $show_image = $show_link = null;
14
 
15
  if (is_object($term)) {
16
  $url = get_term_meta($term->term_id, 'fifu_image_url', true);
17
  $alt = get_term_meta($term->term_id, 'fifu_image_alt', true);
18
  }
19
 
20
- if ($url)
21
  $show_button = $show_sirv = 'display:none;';
22
- else {
 
 
23
  $show_alt = $show_image = $show_link = 'display:none;';
24
  $show_sirv = ($is_sirv_active ? '' : 'display:none;');
25
  }
@@ -27,13 +29,30 @@ function fifu_cat_show_box($term) {
27
  include 'html/category.html';
28
  }
29
 
30
- add_action('edited_product_cat', 'fifu_cat_save_properties', 10, 2);
31
- add_action('create_product_cat', 'fifu_cat_save_properties', 10, 2);
 
 
 
 
 
 
 
 
32
 
33
- function fifu_cat_save_properties($term_id) {
 
 
 
 
 
 
34
  if (isset($_POST['fifu_input_url']))
35
  update_term_meta($term_id, 'fifu_image_url', fifu_convert(esc_url($_POST['fifu_input_url'])));
36
 
37
  if (isset($_POST['fifu_input_alt']))
38
  update_term_meta($term_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
 
 
39
  }
 
1
  <?php
2
 
3
+ add_action('product_cat_edit_form_fields', 'fifu_ctgr_edit_box');
4
+ add_action('product_cat_add_form_fields', 'fifu_ctgr_add_box');
5
 
6
+ function fifu_ctgr_edit_box($term) {
7
  $margin = 'margin-top:10px;';
8
  $width = 'width:100%;';
9
  $height = 'height:200px;';
10
  $align = 'text-align:left;';
11
  $show_news = 'display:none';
12
  $is_sirv_active = is_plugin_active('sirv/sirv.php');
13
+ $url = $alt = null;
14
 
15
  if (is_object($term)) {
16
  $url = get_term_meta($term->term_id, 'fifu_image_url', true);
17
  $alt = get_term_meta($term->term_id, 'fifu_image_alt', true);
18
  }
19
 
20
+ if ($url) {
21
  $show_button = $show_sirv = 'display:none;';
22
+ $show_alt = $show_image = $show_link = '';
23
+ } else {
24
+ $show_button = $show_sirv = '';
25
  $show_alt = $show_image = $show_link = 'display:none;';
26
  $show_sirv = ($is_sirv_active ? '' : 'display:none;');
27
  }
29
  include 'html/category.html';
30
  }
31
 
32
+ function fifu_ctgr_add_box() {
33
+ $margin = 'margin-top:10px;';
34
+ $width = 'width:100%;';
35
+ $height = 'height:200px;';
36
+ $align = 'text-align:left;';
37
+ $is_sirv_active = is_plugin_active('sirv/sirv.php');
38
+
39
+ $show_button = $show_sirv = $url = $alt = '';
40
+ $show_alt = $show_image = $show_link = 'display:none;';
41
+ $show_sirv = ($is_sirv_active ? '' : 'display:none;');
42
 
43
+ include 'html/category.html';
44
+ }
45
+
46
+ add_action('edited_product_cat', 'fifu_ctgr_save_properties', 10, 2);
47
+ add_action('create_product_cat', 'fifu_ctgr_save_properties', 10, 2);
48
+
49
+ function fifu_ctgr_save_properties($term_id) {
50
  if (isset($_POST['fifu_input_url']))
51
  update_term_meta($term_id, 'fifu_image_url', fifu_convert(esc_url($_POST['fifu_input_url'])));
52
 
53
  if (isset($_POST['fifu_input_alt']))
54
  update_term_meta($term_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
55
+
56
+ fifu_ctgr_update_fake_attach_id($term_id);
57
  }
58
+
admin/column.php CHANGED
@@ -9,7 +9,7 @@ function fifu_column() {
9
  fifu_column_custom_post_type();
10
  add_action('manage_posts_custom_column', 'fifu_column_content', 10, 2);
11
  add_action('manage_pages_custom_column', 'fifu_column_content', 10, 2);
12
- add_action('manage_product_cat_custom_column', 'fifu_cat_column_content', 10, 3);
13
  }
14
 
15
  function fifu_column_head($default) {
@@ -17,7 +17,7 @@ function fifu_column_head($default) {
17
  return $default;
18
  }
19
 
20
- function fifu_cat_column_content($internal_image, $column, $term_id) {
21
  if ($column == 'featured_image') {
22
  $url = get_term_meta($term_id, 'fifu_image_url', true);
23
  if ($url != '')
9
  fifu_column_custom_post_type();
10
  add_action('manage_posts_custom_column', 'fifu_column_content', 10, 2);
11
  add_action('manage_pages_custom_column', 'fifu_column_content', 10, 2);
12
+ add_action('manage_product_cat_custom_column', 'fifu_ctgr_column_content', 10, 3);
13
  }
14
 
15
  function fifu_column_head($default) {
17
  return $default;
18
  }
19
 
20
+ function fifu_ctgr_column_content($internal_image, $column, $term_id) {
21
  if ($column == 'featured_image') {
22
  $url = get_term_meta($term_id, 'fifu_image_url', true);
23
  if ($url != '')
admin/html/css/menu.css CHANGED
@@ -44,6 +44,6 @@ th {
44
  }
45
 
46
  #grad2 {
47
- border: 1px solid red;
48
- border-radius: 15px;
49
  }
44
  }
45
 
46
  #grad2 {
47
+ border: 1px dashed red;
48
+ border-radius: 1px;
49
  }
admin/html/menu.html CHANGED
@@ -15,7 +15,7 @@
15
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid red; color: black;
16
  background-color: #eee; border-radius: 25px 5px;">If you have any problem please report immediately to <a href="mailto:marcel@featuredimagefromurl.com">marcel@featuredimagefromurl.com</a>. It should be fixed in some hours.</p>
17
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
18
- background-color: #eee; border-radius: 25px 5px;">You also can go back to the last stable version while the issue is not solved: <a href="https://downloads.wordpress.org/plugin/featured-image-from-url.1.9.5.zip">download</a></p>
19
  </div>
20
 
21
  <div class="box">
@@ -201,9 +201,7 @@
201
  <h2>CSS Style</h2>
202
  <div class="greybox">
203
  Here you can define a CSS style to be applied to all external featured images. Usage example:<br><br>
204
- width: 100%; border-radius: 8px; border: 1px solid #ddd; padding: 5px;
205
- <br><br>
206
- <i>If this new FREE feature is useful to you, please cherish my work. Give FIFU a <a href="https://wordpress.org/support/view/plugin-reviews/featured-image-from-url?filter=5" target="_blank">5-star</a> rating!</i>
207
  </div>
208
  <br>
209
  <form
@@ -220,57 +218,161 @@
220
  <input type="submit"
221
  value="Submit" >
222
  </form>
223
- </div>
224
 
225
  <div class="box">
226
- <h2>Default External Featured Image</h2>
 
 
227
  <div class="greybox">
228
- Here you can define the URL of a default external featured image that will be shown when you create/update a post/page/product without an internal/external featured image.
 
 
229
  </div>
 
230
  <br>
 
231
  <form
232
- id="fifu_form_default_url"
233
  action="javascript:void(0)"
234
  method="post">
235
 
236
- <input id="fifu_input_default_url"
 
237
  type="text"
238
- name="fifu_input_default_url"
239
- style="width:675px"
240
- value="<?php echo $default_url; ?>">
241
 
242
- <input type="submit"
243
- value="Submit" >
244
  </form>
 
245
  </div>
246
 
247
  <div class="box">
248
- <h2>Fake Internal Featured Image</h2>
249
  <div class="greybox">
250
- Even though FIFU works fine with the most of themes/plugins, some of them are not able to show the external featured image if there is no internal featured image associated to your post/page/product. Enabling the toggle below, a symbolic empty file will be added to your Media Library as an attempt to overcome that limitation.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  </div>
252
- <p/>
 
 
253
  <form
254
- id="fifu_form_fake"
255
  action="javascript:void(0)"
256
  method="post">
 
257
  <input
258
  type="image"
259
  href="javascript:void(0)"
260
- id="fifu_toggle_fake"
261
- onclick="invert('fake')"
262
- name="fifu_toggle_fake"
263
- class="<?php echo $enable_fake; ?>"
264
  value=""
265
  style="display:block" >
 
266
  <input
267
  type="hidden"
268
- id="fifu_input_fake"
269
- name="fifu_input_fake"
270
  value="" >
271
  </form>
272
  </div>
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  <div class="box">
275
  <h2>Featured Image Column</h2>
276
  <div class="greybox">
@@ -510,7 +612,9 @@
510
  <div class="box">
511
  <h2>WooCommerce</h2>
512
  <div class="greybox">
513
- You can disable the product lightbox and zoom here once these features are only compatible with the premium version.
 
 
514
  </div>
515
  <br>
516
  <table style="text-align:left">
@@ -1651,7 +1755,9 @@
1651
  <?php echo get_plugin_data(FIFU_PLUGIN_DIR.'featured-image-from-url.php')['Name'] ?>:<?php echo get_plugin_data(FIFU_PLUGIN_DIR.'featured-image-from-url.php')['Version'] ?>;
1652
  Site:<?php echo get_home_url() ?>;
1653
  Theme:<?php echo wp_get_theme() ?>;
 
1654
  WooCommerce:<?php echo class_exists('WooCommerce') ? WC()->version : '' ?>;
 
1655
  Pages:<?php echo wp_count_posts('page')->publish ?>;
1656
  Posts:<?php echo wp_count_posts('post')->publish ?>;
1657
  Products:<?php echo wp_count_posts('product')->publish ?>;
@@ -1673,7 +1779,10 @@ fifu_css:<?php echo $css_style ?>;
1673
  fifu_data_clean:<?php echo $enable_data_clean ?>;
1674
  fifu_data_generation:<?php echo $enable_data_generation ?>;
1675
  fifu_default_url:<?php echo $default_url ?>;
 
 
1676
  fifu_fake:<?php echo $enable_fake ?>;
 
1677
  fifu_get_first:<?php echo $enable_get_first ?>;
1678
  fifu_hide_page:<?php echo $enable_hide_page ?>;
1679
  fifu_hide_post:<?php echo $enable_hide_post ?>;
15
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid red; color: black;
16
  background-color: #eee; border-radius: 25px 5px;">If you have any problem please report immediately to <a href="mailto:marcel@featuredimagefromurl.com">marcel@featuredimagefromurl.com</a>. It should be fixed in some hours.</p>
17
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
18
+ background-color: #eee; border-radius: 25px 5px;">You also can go back to the last stable version while the issue is not solved: <a href="https://downloads.wordpress.org/plugin/featured-image-from-url.1.9.13.zip">download</a></p>
19
  </div>
20
 
21
  <div class="box">
201
  <h2>CSS Style</h2>
202
  <div class="greybox">
203
  Here you can define a CSS style to be applied to all external featured images. Usage example:<br><br>
204
+ width: 100%; border-radius: 8px; border: 1px solid #ddd; padding: 5px;
 
 
205
  </div>
206
  <br>
207
  <form
218
  <input type="submit"
219
  value="Submit" >
220
  </form>
221
+ </div>
222
 
223
  <div class="box">
224
+
225
+ <h2>Default Width</h2>
226
+
227
  <div class="greybox">
228
+
229
+ If your theme doesn't define an image width in some area of the site, FIFU can use a default value (px).
230
+
231
  </div>
232
+
233
  <br>
234
+
235
  <form
236
+ id="fifu_form_default_width"
237
  action="javascript:void(0)"
238
  method="post">
239
 
240
+ <input id="fifu_input_default_width"
241
+ size=4
242
  type="text"
243
+ name="fifu_input_default_width"
244
+ value="<?php echo $default_width; ?>">
 
245
 
246
+ <input type="submit" value="Submit" >
 
247
  </form>
248
+
249
  </div>
250
 
251
  <div class="box">
252
+ <h2>Default External Featured Image</h2>
253
  <div class="greybox">
254
+ Here you can define the URL of a default external featured image that will be shown when you create/update a post/page/product without an internal/external featured image.
255
+ <br><br>
256
+ <form
257
+ id="fifu_form_default_url"
258
+ action="javascript:void(0)"
259
+ method="post">
260
+
261
+ <input id="fifu_input_default_url"
262
+ type="text"
263
+ name="fifu_input_default_url"
264
+ style="width:675px"
265
+ value="<?php echo $default_url; ?>">
266
+
267
+ <input type="submit"
268
+ value="Submit" >
269
+ </form>
270
  </div>
271
+
272
+ <br>
273
+
274
  <form
275
+ id="fifu_form_enable_default_url"
276
  action="javascript:void(0)"
277
  method="post">
278
+
279
  <input
280
  type="image"
281
  href="javascript:void(0)"
282
+ id="fifu_toggle_enable_default_url"
283
+ onclick="invert('enable_default_url')"
284
+ name="fifu_toggle_enable_default_url"
285
+ class="<?php echo $enable_default_url; ?>"
286
  value=""
287
  style="display:block" >
288
+
289
  <input
290
  type="hidden"
291
+ id="fifu_input_enable_default_url"
292
+ name="fifu_input_enable_default_url"
293
  value="" >
294
  </form>
295
  </div>
296
 
297
+ <div class="box">
298
+ <h2>Fake Internal Featured Image</h2>
299
+ <div class="greybox">
300
+ Even though FIFU works fine with the most of themes/plugins, some of them are not able to show the external featured image if there is no internal featured image associated to your post/page/product. Enabling the toggle below, a symbolic empty file will be added to your Media Library as an attempt to overcome that limitation.
301
+ </div>
302
+ <p/>
303
+ <table>
304
+ <tr>
305
+ <td style="width:50px"></td>
306
+ <td style="width:100px">action</td>
307
+ <td style="width:200px">pros</td>
308
+ <td style="width:200px">cons</td>
309
+ </tr>
310
+ <tr>
311
+ <form
312
+ id="fifu_form_fake"
313
+ action="javascript:void(0)"
314
+ method="post">
315
+ <td>
316
+ <input
317
+ type="image"
318
+ href="javascript:void(0)"
319
+ id="fifu_toggle_fake"
320
+ onclick="invert('fake')"
321
+ name="fifu_toggle_fake"
322
+ class="<?php echo $enable_fake; ?>"
323
+ value=""
324
+ style="display:block" >
325
+ <input
326
+ type="hidden"
327
+ id="fifu_input_fake"
328
+ name="fifu_input_fake"
329
+ value="" >
330
+ </td>
331
+ <td>
332
+ create one fake image for all URLs
333
+ </td>
334
+ <td>
335
+ you can keep your real internal featured image. <b>Stable feature</b>.
336
+ </td>
337
+ <td>
338
+ the site may have some problems to show the external images in some areas, such as WooCommerce lightbox, or in determined sizes. It'll be deprecated in the next months.
339
+ </td>
340
+ </form>
341
+ </tr>
342
+ <tr>
343
+ <form
344
+ id="fifu_form_fake2"
345
+ action="javascript:void(0)"
346
+ method="post">
347
+ <td>
348
+ <input
349
+ type="image"
350
+ href="javascript:void(0)"
351
+ id="fifu_toggle_fake2"
352
+ onclick="invert('fake2')"
353
+ name="fifu_toggle_fake2"
354
+ class="<?php echo $enable_fake2; ?>"
355
+ value=""
356
+ style="display:block" >
357
+ <input
358
+ type="hidden"
359
+ id="fifu_input_fake2"
360
+ name="fifu_input_fake2"
361
+ value="" >
362
+ </td>
363
+ <td>
364
+ create a different fake image for each URL
365
+ </td>
366
+ <td>
367
+ the site can show the images anywhere and in the correct size in most cases. Greater chance of the external images being supported by other plugins.
368
+ </td>
369
+ <td>
370
+ it'll replace your real internal featured image. And if you have many posts/pages/products, the fake image generation can take some minutes to finish (~10 posts/s). <b>Beta feature</b>.
371
+ </td>
372
+ </form>
373
+ </tr></table>
374
+ </div>
375
+
376
  <div class="box">
377
  <h2>Featured Image Column</h2>
378
  <div class="greybox">
612
  <div class="box">
613
  <h2>WooCommerce</h2>
614
  <div class="greybox">
615
+ You can enable/disable the product lightbox and zoom here. They are compatible with this free version now.
616
+ <br><br>
617
+ <i>If this new FREE feature is useful to you, please cherish my work. Give FIFU a <a href="https://wordpress.org/support/view/plugin-reviews/featured-image-from-url?filter=5" target="_blank">5-star</a> rating!</i>
618
  </div>
619
  <br>
620
  <table style="text-align:left">
1755
  <?php echo get_plugin_data(FIFU_PLUGIN_DIR.'featured-image-from-url.php')['Name'] ?>:<?php echo get_plugin_data(FIFU_PLUGIN_DIR.'featured-image-from-url.php')['Version'] ?>;
1756
  Site:<?php echo get_home_url() ?>;
1757
  Theme:<?php echo wp_get_theme() ?>;
1758
+ PHP:<?php echo phpversion() ?>;
1759
  WooCommerce:<?php echo class_exists('WooCommerce') ? WC()->version : '' ?>;
1760
+ WordPress:<?php echo get_bloginfo('version') ?>;
1761
  Pages:<?php echo wp_count_posts('page')->publish ?>;
1762
  Posts:<?php echo wp_count_posts('post')->publish ?>;
1763
  Products:<?php echo wp_count_posts('product')->publish ?>;
1779
  fifu_data_clean:<?php echo $enable_data_clean ?>;
1780
  fifu_data_generation:<?php echo $enable_data_generation ?>;
1781
  fifu_default_url:<?php echo $default_url ?>;
1782
+ fifu_default_width:<?php echo $default_width ?>;
1783
+ fifu_enable_default_url:<?php echo $enable_default_url ?>;
1784
  fifu_fake:<?php echo $enable_fake ?>;
1785
+ fifu_fake2:<?php echo $enable_fake2 ?>;
1786
  fifu_get_first:<?php echo $enable_get_first ?>;
1787
  fifu_hide_page:<?php echo $enable_hide_page ?>;
1788
  fifu_hide_post:<?php echo $enable_hide_post ?>;
admin/html/meta-box.html CHANGED
@@ -24,6 +24,7 @@
24
  style="<?php echo $width, $margin ?>" />
25
 
26
  <p/>
 
27
  <center>
28
  <a id="fifu_link"
29
  href="#"
@@ -55,7 +56,7 @@
55
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid red; color: black;
56
  background-color: #eee; border-radius: 25px 5px;">If you have any problem please report to <a href="mailto:support@featuredimagefromurl.com">marcel@featuredimagefromurl.com</a></p>
57
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
58
- background-color: #eee; border-radius: 25px 5px;">You also can go back to the last stable version: <a href="https://downloads.wordpress.org/plugin/featured-image-from-url.1.9.5.zip">download</a></p>
59
  <!--p style="font-size: 12px; padding: 5px; border-left: 6px solid #b20ab8; color: black;
60
  background-color: #eee; border-radius: 25px 5px;">New: WooCommerce <a href="admin.php?page=featured-image-from-url#variable">Product Variable</a> support (<a href="https://shop.featuredimagefromurl.com/product/variable-product/">live preview</a>)</p-->
61
  <!--p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
24
  style="<?php echo $width, $margin ?>" />
25
 
26
  <p/>
27
+
28
  <center>
29
  <a id="fifu_link"
30
  href="#"
56
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid red; color: black;
57
  background-color: #eee; border-radius: 25px 5px;">If you have any problem please report to <a href="mailto:support@featuredimagefromurl.com">marcel@featuredimagefromurl.com</a></p>
58
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
59
+ background-color: #eee; border-radius: 25px 5px;">You also can go back to the last stable version: <a href="https://downloads.wordpress.org/plugin/featured-image-from-url.1.9.13.zip">download</a></p>
60
  <!--p style="font-size: 12px; padding: 5px; border-left: 6px solid #b20ab8; color: black;
61
  background-color: #eee; border-radius: 25px 5px;">New: WooCommerce <a href="admin.php?page=featured-image-from-url#variable">Product Variable</a> support (<a href="https://shop.featuredimagefromurl.com/product/variable-product/">live preview</a>)</p-->
62
  <!--p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
admin/menu.php CHANGED
@@ -11,6 +11,7 @@ function fifu_insert_menu() {
11
  }
12
 
13
  function fifu_get_menu_html() {
 
14
  $image_button = plugins_url() . '/featured-image-from-url/admin/images/onoff.jpg';
15
 
16
  $enable_social = get_option('fifu_social');
@@ -18,8 +19,11 @@ function fifu_get_menu_html() {
18
  $enable_content = get_option('fifu_content');
19
  $enable_content_page = get_option('fifu_content_page');
20
  $enable_fake = get_option('fifu_fake');
 
21
  $css_style = get_option('fifu_css');
22
  $default_url = get_option('fifu_default_url');
 
 
23
  $enable_wc_lbox = get_option('fifu_wc_lbox');
24
  $enable_wc_zoom = get_option('fifu_wc_zoom');
25
  $enable_hide_page = get_option('fifu_hide_page');
@@ -41,10 +45,37 @@ function fifu_get_menu_html() {
41
 
42
  fifu_update_menu_options();
43
 
44
- if (fifu_is_on('fifu_fake'))
 
45
  fifu_enable_fake();
46
- else
47
  fifu_disable_fake();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  if (fifu_is_on('fifu_data_clean')) {
50
  fifu_enable_clean();
@@ -57,9 +88,12 @@ function fifu_get_menu_settings() {
57
  fifu_get_setting('fifu_lazy');
58
  fifu_get_setting('fifu_content');
59
  fifu_get_setting('fifu_content_page');
 
60
  fifu_get_setting('fifu_fake');
 
61
  fifu_get_setting('fifu_css');
62
  fifu_get_setting('fifu_default_url');
 
63
  fifu_get_setting('fifu_wc_lbox');
64
  fifu_get_setting('fifu_wc_zoom');
65
  fifu_get_setting('fifu_hide_page');
@@ -81,7 +115,7 @@ function fifu_get_setting($type) {
81
  register_setting('settings-group', $type);
82
 
83
  if (!get_option($type)) {
84
- if (strpos($type, "cpt") !== false || strpos($type, "default") !== false || strpos($type, "css") !== false)
85
  update_option($type, '');
86
  else if (strpos($type, "fifu_column_height") !== false)
87
  update_option($type, "64");
@@ -98,8 +132,11 @@ function fifu_update_menu_options() {
98
  fifu_update_option('fifu_input_content', 'fifu_content');
99
  fifu_update_option('fifu_input_content_page', 'fifu_content_page');
100
  fifu_update_option('fifu_input_fake', 'fifu_fake');
 
101
  fifu_update_option('fifu_input_css', 'fifu_css');
102
  fifu_update_option('fifu_input_default_url', 'fifu_default_url');
 
 
103
  fifu_update_option('fifu_input_wc_lbox', 'fifu_wc_lbox');
104
  fifu_update_option('fifu_input_wc_zoom', 'fifu_wc_zoom');
105
  fifu_update_option('fifu_input_hide_page', 'fifu_hide_page');
@@ -128,6 +165,217 @@ function fifu_update_option($input, $type) {
128
  }
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  function fifu_enable_fake() {
132
  if (get_option('fifu_fake_attach_id'))
133
  return;
@@ -208,6 +456,28 @@ function fifu_disable_fake() {
208
  delete_option('fifu_fake_attach_id');
209
  }
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  function fifu_enable_clean() {
212
  global $wpdb;
213
 
@@ -239,7 +509,52 @@ function fifu_enable_clean() {
239
  wp_delete_attachment(get_option('fifu_default_attach_id'));
240
  delete_option('fifu_fake_attach_id');
241
  fifu_disable_fake();
 
242
  update_option('fifu_fake', 'toggleoff');
 
243
  update_option('fifu_fake_created', false);
244
  }
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
 
13
  function fifu_get_menu_html() {
14
+ flush();
15
  $image_button = plugins_url() . '/featured-image-from-url/admin/images/onoff.jpg';
16
 
17
  $enable_social = get_option('fifu_social');
19
  $enable_content = get_option('fifu_content');
20
  $enable_content_page = get_option('fifu_content_page');
21
  $enable_fake = get_option('fifu_fake');
22
+ $enable_fake2 = get_option('fifu_fake2');
23
  $css_style = get_option('fifu_css');
24
  $default_url = get_option('fifu_default_url');
25
+ $default_width = get_option('fifu_default_width');
26
+ $enable_default_url = get_option('fifu_enable_default_url');
27
  $enable_wc_lbox = get_option('fifu_wc_lbox');
28
  $enable_wc_zoom = get_option('fifu_wc_zoom');
29
  $enable_hide_page = get_option('fifu_hide_page');
45
 
46
  fifu_update_menu_options();
47
 
48
+ if (fifu_is_on('fifu_fake')) {
49
+ update_option('fifu_data_generation', 'toggleon');
50
  fifu_enable_fake();
51
+ } else {
52
  fifu_disable_fake();
53
+ //
54
+ update_option('fifu_fake_created', true);
55
+ fifu_disable_fake2();
56
+ update_option('fifu_fake_created', false);
57
+ }
58
+
59
+ if (fifu_is_on('fifu_fake2')) {
60
+ update_option('fifu_data_generation', 'toggleoff');
61
+ fifu_enable_fake2();
62
+ } else {
63
+ fifu_disable_fake2();
64
+ delete_option('fifu_fake_attach_id');
65
+ update_option('fifu_fake_created', false);
66
+ }
67
+
68
+ if ($default_url && fifu_is_on('fifu_enable_default_url') && fifu_is_on('fifu_fake2')) {
69
+ if (!wp_get_attachment_url(get_option('fifu_default_attach_id'))) {
70
+ $attach_id = fifu_create_attachment_url($default_url);
71
+ update_option('fifu_default_attach_id', $attach_id);
72
+ fifu_set_default_url($attach_id);
73
+ } else {
74
+ fifu_update_default_url($default_url);
75
+ }
76
+ } else {
77
+ fifu_delete_default_url();
78
+ }
79
 
80
  if (fifu_is_on('fifu_data_clean')) {
81
  fifu_enable_clean();
88
  fifu_get_setting('fifu_lazy');
89
  fifu_get_setting('fifu_content');
90
  fifu_get_setting('fifu_content_page');
91
+ fifu_get_setting('fifu_enable_default_url');
92
  fifu_get_setting('fifu_fake');
93
+ fifu_get_setting('fifu_fake2');
94
  fifu_get_setting('fifu_css');
95
  fifu_get_setting('fifu_default_url');
96
+ fifu_get_setting('fifu_default_width');
97
  fifu_get_setting('fifu_wc_lbox');
98
  fifu_get_setting('fifu_wc_zoom');
99
  fifu_get_setting('fifu_hide_page');
115
  register_setting('settings-group', $type);
116
 
117
  if (!get_option($type)) {
118
+ if (strpos($type, "cpt") !== false || strpos($type, "fifu_default_width") !== false || strpos($type, "fifu_default_url") !== false || strpos($type, "css") !== false)
119
  update_option($type, '');
120
  else if (strpos($type, "fifu_column_height") !== false)
121
  update_option($type, "64");
132
  fifu_update_option('fifu_input_content', 'fifu_content');
133
  fifu_update_option('fifu_input_content_page', 'fifu_content_page');
134
  fifu_update_option('fifu_input_fake', 'fifu_fake');
135
+ fifu_update_option('fifu_input_fake2', 'fifu_fake2');
136
  fifu_update_option('fifu_input_css', 'fifu_css');
137
  fifu_update_option('fifu_input_default_url', 'fifu_default_url');
138
+ fifu_update_option('fifu_input_default_width', 'fifu_default_width');
139
+ fifu_update_option('fifu_input_enable_default_url', 'fifu_enable_default_url');
140
  fifu_update_option('fifu_input_wc_lbox', 'fifu_wc_lbox');
141
  fifu_update_option('fifu_input_wc_zoom', 'fifu_wc_zoom');
142
  fifu_update_option('fifu_input_hide_page', 'fifu_hide_page');
165
  }
166
  }
167
 
168
+ function fifu_enable_fake2() {
169
+ if (get_option('fifu_fake_created'))
170
+ return;
171
+ update_option('fifu_fake_created', true);
172
+
173
+ global $wpdb;
174
+
175
+ $table = $wpdb->prefix . 'postmeta';
176
+ $query = "
177
+ SELECT DISTINCT post_id
178
+ FROM " . $table . " a
179
+ WHERE a.post_id in (
180
+ SELECT post_id
181
+ FROM " . $table . " b
182
+ WHERE b.meta_key IN ('fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
183
+ AND b.meta_value IS NOT NULL
184
+ AND b.meta_value <> ''
185
+ )
186
+ AND NOT EXISTS (
187
+ SELECT 1
188
+ FROM " . $table . " c
189
+ WHERE a.post_id = c.post_id
190
+ AND c.meta_key = '_thumbnail_id'
191
+ )";
192
+ $result = $wpdb->get_results($query);
193
+ foreach ($result as $i) {
194
+ $alt = get_post_meta($i->post_id, 'fifu_image_alt', true);
195
+ // create attachment
196
+ $filename = ';' . fifu_main_image_url($i->post_id);
197
+ $parent_post_id = $i->post_id;
198
+ $filetype = wp_check_filetype('fifu.png', null);
199
+ $attachment = array(
200
+ 'guid' => fifu_main_image_url($i->post_id),
201
+ 'post_mime_type' => $filetype['type'],
202
+ 'post_author' => 77777,
203
+ 'post_title' => $alt,
204
+ 'post_excerpt' => '',
205
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
206
+ '(some themes/plugins depend on having an attached file to work). But you are free to use any image you want instead of this file.',
207
+ 'post_status' => 'inherit'
208
+ );
209
+ $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
210
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
211
+ $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
212
+ wp_update_attachment_metadata($attach_id, $attach_data);
213
+
214
+ // create _thumbnail_id
215
+ $data = array('post_id' => $i->post_id, 'meta_key' => '_thumbnail_id', 'meta_value' => $attach_id);
216
+ $wpdb->insert($table, $data);
217
+
218
+ update_post_meta($attach_id, '_wp_attachment_image_alt', $alt);
219
+ }
220
+ fifu_enable_fake_ctgr();
221
+ }
222
+
223
+ function fifu_enable_fake_ctgr() {
224
+ global $wpdb;
225
+
226
+ $table_termmeta = $wpdb->prefix . 'termmeta';
227
+ $query = "
228
+ SELECT DISTINCT term_id
229
+ FROM " . $table_termmeta . " a
230
+ WHERE a.term_id in (
231
+ SELECT term_id
232
+ FROM " . $table_termmeta . " b
233
+ WHERE b.meta_key IN ('fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
234
+ AND b.meta_value IS NOT NULL
235
+ AND b.meta_value <> ''
236
+ )
237
+ AND NOT EXISTS (
238
+ SELECT 1
239
+ FROM " . $table_termmeta . " c
240
+ WHERE a.term_id = c.term_id
241
+ AND c.meta_key = 'thumbnail_id'
242
+ AND c.meta_value <> 0
243
+ )";
244
+ $result = $wpdb->get_results($query);
245
+ foreach ($result as $i) {
246
+ $alt = get_term_meta($i->term_id, 'fifu_image_alt', true);
247
+ $url = get_term_meta($i->term_id, 'fifu_image_url', true);
248
+ // create attachment
249
+ $filename = ';' . $url;
250
+ $parent_post_id = 0;
251
+ $filetype = wp_check_filetype('fifu.png', null);
252
+ $attachment = array(
253
+ 'guid' => $url,
254
+ 'post_mime_type' => $filetype['type'],
255
+ 'post_author' => 77777,
256
+ 'post_title' => $alt,
257
+ 'post_excerpt' => '',
258
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
259
+ '(some themes/plugins depend on having an attached file to work). But you are free to use any image you want instead of this file.',
260
+ 'post_status' => 'inherit'
261
+ );
262
+ $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
263
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
264
+ $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
265
+ wp_update_attachment_metadata($attach_id, $attach_data);
266
+
267
+ // create thumbnail_id
268
+ update_term_meta($i->term_id, 'thumbnail_id', $attach_id);
269
+
270
+ update_post_meta($attach_id, '_wp_attachment_image_alt', $alt);
271
+ }
272
+ }
273
+
274
+ function fifu_disable_fake2() {
275
+ if (!get_option('fifu_fake_created'))
276
+ return;
277
+
278
+ global $wpdb;
279
+
280
+ $table = $wpdb->prefix . 'postmeta';
281
+ $table_posts = $wpdb->prefix . 'posts';
282
+ $table_termmeta = $wpdb->prefix . 'termmeta';
283
+
284
+ // delete attachment created by fifu
285
+ $query = "SELECT id FROM " . $table_posts . " WHERE post_type = 'attachment' AND post_content LIKE 'Please don%'";
286
+ $result = $wpdb->get_results($query);
287
+ foreach ($result as $i) {
288
+ $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $i->id);
289
+ $wpdb->delete($table, $where);
290
+
291
+ $where = array('meta_key' => 'thumbnail_id', 'meta_value' => $i->id);
292
+ $wpdb->delete($table_termmeta, $where);
293
+
294
+ wp_delete_attachment($i->id);
295
+ }
296
+
297
+ // delete meta values
298
+ $query = "SELECT post_id FROM " . $table . " WHERE meta_key = 'fifu_image_url'";
299
+ $result = $wpdb->get_results($query);
300
+ foreach ($result as $i) {
301
+ $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => -1);
302
+ $wpdb->delete($table, $where);
303
+
304
+ $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => null);
305
+ $wpdb->delete($table, $where);
306
+
307
+ $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => 'fifu:' . $i->post_id);
308
+ $wpdb->delete($table, $where);
309
+
310
+ $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => get_option('fifu_fake_attach_id'));
311
+ $wpdb->delete($table, $where);
312
+
313
+ $where = array('meta_key' => '_wp_attached_file', 'post_id' => $i->post_id, 'meta_value' => 'Featured Image from URL');
314
+ $wpdb->delete($table, $where);
315
+
316
+ // delete _thumbnail_id withouth attachment
317
+ $query = "SELECT 1 FROM " . $table . " pm WHERE pm.meta_key = '_thumbnail_id' AND pm.post_id = " . $i->post_id . " AND NOT EXISTS (SELECT 1 FROM " . $table_posts . " p WHERE p.id = pm.meta_value)";
318
+ $result = $wpdb->get_results($query);
319
+ foreach ($result as $x) {
320
+ $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id);
321
+ $wpdb->delete($table, $where);
322
+ }
323
+ }
324
+
325
+ // delete attachments
326
+ $query = "SELECT post_id FROM " . $table . " WHERE meta_key = '_wp_attached_file' AND meta_value = 'Featured Image from URL'";
327
+ $result = $wpdb->get_results($query);
328
+ foreach ($result as $i) {
329
+ $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $i->post_id);
330
+ $wpdb->delete($table, $where);
331
+ wp_delete_attachment($i->post_id);
332
+ }
333
+ fifu_disable_fake_ctgr();
334
+ }
335
+
336
+ function fifu_disable_fake_ctgr() {
337
+ global $wpdb;
338
+
339
+ $table = $wpdb->prefix . 'postmeta';
340
+ $table_posts = $wpdb->prefix . 'posts';
341
+ $table_termmeta = $wpdb->prefix . 'termmeta';
342
+
343
+ // delete meta values
344
+ $query = "SELECT term_id FROM " . $table_termmeta . " WHERE meta_key = 'fifu_image_url'";
345
+ $result = $wpdb->get_results($query);
346
+ foreach ($result as $i) {
347
+ $where = array('meta_key' => 'thumbnail_id', 'term_id' => $i->term_id, 'meta_value' => 0);
348
+ $wpdb->delete($table_termmeta, $where);
349
+
350
+ $where = array('meta_key' => 'thumbnail_id', 'term_id' => $i->term_id, 'meta_value' => -1);
351
+ $wpdb->delete($table_termmeta, $where);
352
+
353
+ $where = array('meta_key' => 'thumbnail_id', 'term_id' => $i->term_id, 'meta_value' => null);
354
+ $wpdb->delete($table_termmeta, $where);
355
+
356
+ $where = array('meta_key' => 'thumbnail_id', 'term_id' => $i->term_id, 'meta_value' => 'fifu:' . $i->term_id);
357
+ $wpdb->delete($table_termmeta, $where);
358
+
359
+ $where = array('meta_key' => 'thumbnail_id', 'term_id' => $i->term_id, 'meta_value' => get_option('fifu_fake_attach_id'));
360
+ $wpdb->delete($table_termmeta, $where);
361
+
362
+ $query = "SELECT meta_value FROM " . $table_termmeta . " tm WHERE tm.meta_key = 'thumbnail_id' AND tm.term_id = " . $i->term_id;
363
+ $result2 = $wpdb->get_results($query);
364
+ foreach ($result2 as $j) {
365
+ $where = array('meta_key' => '_wp_attached_file', 'post_id' => $j->meta_value);
366
+ $wpdb->delete($table, $where);
367
+ }
368
+
369
+ // delete thumbnail_id withouth attachment
370
+ $query = "SELECT 1 FROM " . $table_termmeta . " tm WHERE tm.meta_key = 'thumbnail_id' AND tm.term_id = " . $i->term_id . " AND NOT EXISTS (SELECT 1 FROM " . $table_posts . " p WHERE p.id = tm.meta_value)";
371
+ $result3 = $wpdb->get_results($query);
372
+ foreach ($result3 as $k) {
373
+ $where = array('meta_key' => 'thumbnail_id', 'term_id' => $i->term_id);
374
+ $wpdb->delete($table_termmeta, $where);
375
+ }
376
+ }
377
+ }
378
+
379
  function fifu_enable_fake() {
380
  if (get_option('fifu_fake_attach_id'))
381
  return;
456
  delete_option('fifu_fake_attach_id');
457
  }
458
 
459
+ function fifu_create_attachment_url($url) {
460
+ // create attachment
461
+ $filename = ';' . $url;
462
+ $parent_post_id = null;
463
+ $filetype = wp_check_filetype('fifu.png', null);
464
+ $attachment = array(
465
+ 'guid' => $url,
466
+ 'post_mime_type' => $filetype['type'],
467
+ 'post_author' => 77777,
468
+ 'post_title' => '',
469
+ 'post_excerpt' => '',
470
+ 'post_content' => 'Please don\'t remove me. I\'m just an empty symbolic file that keeps the attached field filled ' .
471
+ '(some themes/plugins depend on having an attached file to work). Anyway you are free to use any internal image you want instead of me.',
472
+ 'post_status' => 'inherit'
473
+ );
474
+ $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
475
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
476
+ $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
477
+ wp_update_attachment_metadata($attach_id, $attach_data);
478
+ return $attach_id;
479
+ }
480
+
481
  function fifu_enable_clean() {
482
  global $wpdb;
483
 
509
  wp_delete_attachment(get_option('fifu_default_attach_id'));
510
  delete_option('fifu_fake_attach_id');
511
  fifu_disable_fake();
512
+ fifu_disable_fake2();
513
  update_option('fifu_fake', 'toggleoff');
514
+ update_option('fifu_fake2', 'toggleoff');
515
  update_option('fifu_fake_created', false);
516
  }
517
 
518
+ function fifu_set_default_url($attach_id) {
519
+ global $wpdb;
520
+ $table_postmeta = $wpdb->prefix . 'postmeta';
521
+ $table_posts = $wpdb->prefix . 'posts';
522
+ $query = "
523
+ SELECT id
524
+ FROM " . $table_posts . " p
525
+ INNER JOIN " . $table_postmeta . " pm ON p.id = pm.post_id
526
+ WHERE post_type IN ('post','page','product')
527
+ AND post_status = 'publish'
528
+ AND NOT EXISTS (
529
+ SELECT 1 FROM " . $table_postmeta . " pm2
530
+ WHERE pm2.post_id = pm.post_id
531
+ AND pm2.meta_key IN ('_thumbnail_id', 'fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
532
+ AND pm2.meta_value <> -1
533
+ )";
534
+ $result = $wpdb->get_results($query);
535
+ foreach ($result as $i) {
536
+ set_post_thumbnail($i->id, $attach_id);
537
+ }
538
+ }
539
+
540
+ function fifu_update_default_url($url) {
541
+ global $wpdb;
542
+ $table_posts = $wpdb->prefix . 'posts';
543
+ $attach_id = get_option('fifu_default_attach_id');
544
+ if ($url != wp_get_attachment_url($attach_id)) {
545
+ $wpdb->update($table_posts, $set = array('guid' => $url), $where = array('id' => $attach_id), null, null);
546
+ update_post_meta($attach_id, '_wp_attached_file', ';' . $url);
547
+ }
548
+ }
549
+
550
+ function fifu_delete_default_url() {
551
+ $attach_id = get_option('fifu_default_attach_id');
552
+ wp_delete_attachment($attach_id);
553
+ delete_option('fifu_default_attach_id');
554
+
555
+ global $wpdb;
556
+ $table_postmeta = $wpdb->prefix . 'postmeta';
557
+ $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $attach_id);
558
+ $wpdb->delete($table_postmeta, $where);
559
+ }
560
+
admin/meta-box.php CHANGED
@@ -86,15 +86,46 @@ function fifu_save_properties($post_id) {
86
  if (isset($_POST['fifu_input_alt'])) {
87
  $alt = wp_strip_all_tags($_POST['fifu_input_alt']);
88
  $alt = !$alt && $url && fifu_is_on('fifu_auto_alt') ? get_the_title() : $alt;
89
- fifu_update_or_delete($post_id, 'fifu_image_alt', $alt);
90
  }
 
 
91
  }
92
 
93
  function fifu_update_or_delete($post_id, $field, $url) {
94
  if ($url) {
95
  update_post_meta($post_id, $field, fifu_convert($url));
96
- fifu_update_fake_attach_id($post_id);
97
  } else
98
  delete_post_meta($post_id, $field, $url);
99
  }
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  if (isset($_POST['fifu_input_alt'])) {
87
  $alt = wp_strip_all_tags($_POST['fifu_input_alt']);
88
  $alt = !$alt && $url && fifu_is_on('fifu_auto_alt') ? get_the_title() : $alt;
89
+ fifu_update_or_delete_alt($post_id, 'fifu_image_alt', $alt);
90
  }
91
+
92
+ fifu_update_fake_attach_id($post_id);
93
  }
94
 
95
  function fifu_update_or_delete($post_id, $field, $url) {
96
  if ($url) {
97
  update_post_meta($post_id, $field, fifu_convert($url));
 
98
  } else
99
  delete_post_meta($post_id, $field, $url);
100
  }
101
 
102
+ function fifu_update_or_delete_alt($post_id, $field, $value) {
103
+ if ($value)
104
+ update_post_meta($post_id, $field, $value);
105
+ else
106
+ delete_post_meta($post_id, $field, $value);
107
+ }
108
+
109
+ add_action('before_delete_post', 'fifu_remove_product_gallery');
110
+
111
+ function fifu_remove_product_gallery($post_id) {
112
+ global $wpdb;
113
+ $table_postmeta = $wpdb->prefix . 'postmeta';
114
+ $table_posts = $wpdb->prefix . 'posts';
115
+ $query = "
116
+ SELECT GROUP_CONCAT(meta_value SEPARATOR ',') as 'ids'
117
+ FROM " . $table_postmeta . " pm
118
+ WHERE pm.post_id = " . $post_id . "
119
+ AND pm.meta_key IN ('_thumbnail_id', '_product_image_gallery')";
120
+ $result = $wpdb->get_results($query);
121
+ if ($result) {
122
+ $ids = explode(',', $result[0]->ids);
123
+ foreach ($ids as $id) {
124
+ if ($id) {
125
+ $where = array('id' => $id, 'post_author' => 77777, 'post_type' => 'attachment');
126
+ $wpdb->delete($table_posts, $where);
127
+ }
128
+ }
129
+ }
130
+ }
131
+
featured-image-from-url.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Featured Image From URL
5
  * Plugin URI: https://featuredimagefromurl.com/
6
  * Description: Use an external image as Featured Image of your post/page/custom post type (WooCommerce). Includes Auto Set (External Post), Product Gallery, Social Tags and more.
7
- * Version: 1.9.13
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
@@ -13,16 +13,18 @@ define('FIFU_PLUGIN_DIR', plugin_dir_path(__FILE__));
13
  define('FIFU_INCLUDES_DIR', FIFU_PLUGIN_DIR . 'includes');
14
  define('FIFU_ADMIN_DIR', FIFU_PLUGIN_DIR . 'admin');
15
 
 
 
 
16
  require_once( FIFU_INCLUDES_DIR . '/thumbnail.php' );
17
  require_once( FIFU_INCLUDES_DIR . '/thumbnail-category.php' );
18
- require_once( FIFU_INCLUDES_DIR . '/external-post.php' );
19
- require_once( FIFU_INCLUDES_DIR . '/convert-url.php' );
20
  require_once (FIFU_INCLUDES_DIR . '/util.php');
21
  require_once (FIFU_INCLUDES_DIR . '/woo.php');
22
 
23
  if (is_admin()) {
24
- require_once( FIFU_ADMIN_DIR . '/meta-box.php' );
25
- require_once( FIFU_ADMIN_DIR . '/menu.php' );
26
- require_once( FIFU_ADMIN_DIR . '/column.php' );
27
  require_once( FIFU_ADMIN_DIR . '/category.php' );
 
 
28
  }
 
 
4
  * Plugin Name: Featured Image From URL
5
  * Plugin URI: https://featuredimagefromurl.com/
6
  * Description: Use an external image as Featured Image of your post/page/custom post type (WooCommerce). Includes Auto Set (External Post), Product Gallery, Social Tags and more.
7
+ * Version: 2.0.0
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
13
  define('FIFU_INCLUDES_DIR', FIFU_PLUGIN_DIR . 'includes');
14
  define('FIFU_ADMIN_DIR', FIFU_PLUGIN_DIR . 'admin');
15
 
16
+ require_once (FIFU_INCLUDES_DIR . '/attachment.php');
17
+ require_once( FIFU_INCLUDES_DIR . '/convert-url.php' );
18
+ require_once( FIFU_INCLUDES_DIR . '/external-post.php' );
19
  require_once( FIFU_INCLUDES_DIR . '/thumbnail.php' );
20
  require_once( FIFU_INCLUDES_DIR . '/thumbnail-category.php' );
 
 
21
  require_once (FIFU_INCLUDES_DIR . '/util.php');
22
  require_once (FIFU_INCLUDES_DIR . '/woo.php');
23
 
24
  if (is_admin()) {
 
 
 
25
  require_once( FIFU_ADMIN_DIR . '/category.php' );
26
+ require_once( FIFU_ADMIN_DIR . '/column.php' );
27
+ require_once( FIFU_ADMIN_DIR . '/menu.php' );
28
  }
29
+ require_once( FIFU_ADMIN_DIR . '/meta-box.php' );
30
+
includes/attachment.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ define("FIFU_URL", "/localhost/fifu/");
4
+
5
+ add_filter('get_attached_file', 'fifu_replace_attached_file', 10, 2);
6
+
7
+ function fifu_replace_attached_file($att_url, $att_id) {
8
+ if (fifu_is_off('fifu_data_generation')) {
9
+ if ($att_url) {
10
+ $url = explode(";", $att_url);
11
+ if (sizeof($url) > 1)
12
+ return strpos($url[1], "/wp-content/uploads/") !== false ? get_post($att_id)->guid : $url[1];
13
+ }
14
+ }
15
+ return $att_url;
16
+ }
17
+
18
+ add_filter('wp_get_attachment_url', 'fifu_replace_attachment_url', 10, 2);
19
+
20
+ function fifu_replace_attachment_url($att_url, $att_id) {
21
+ if (fifu_is_off('fifu_data_generation')) {
22
+ if ($att_url) {
23
+ $url = explode(";", $att_url);
24
+ if (sizeof($url) > 1)
25
+ return strpos($url[1], "/wp-content/uploads/") !== false ? get_post($att_id)->guid : $url[1];
26
+ }
27
+ }
28
+
29
+ if (fifu_show_internal_instead_of_external(get_the_ID()))
30
+ return $att_url;
31
+
32
+ if ($att_id == get_post_thumbnail_id(get_the_ID())) {
33
+ $url = fifu_main_image_url(get_the_ID());
34
+ if ($url)
35
+ $att_url = $url;
36
+ }
37
+ return $att_url;
38
+ }
39
+
40
+ add_filter('posts_where', 'fifu_query_attachments');
41
+
42
+ function fifu_query_attachments($where) {
43
+ if (isset($_POST['action']) && ($_POST['action'] == 'query-attachments'))
44
+ $where .= ' AND post_author <> 77777 ';
45
+ return $where;
46
+ }
47
+
48
+ add_filter('wp_get_attachment_image_src', 'fifu_replace_attachment_image_src', 10, 3);
49
+
50
+ function fifu_replace_attachment_image_src($image, $att_id, $size) {
51
+ $post = get_post($att_id);
52
+
53
+ if (fifu_is_off('fifu_data_generation')) {
54
+ if (fifu_should_hide())
55
+ return null;
56
+ $image_size = fifu_get_image_size($size);
57
+ return array(
58
+ strpos($image[0], "/wp-content/uploads/") !== false ? get_post($att_id)->guid : $image[0],
59
+ isset($image_size['width']) ? $image_size['width'] : (get_option('fifu_default_width') ? get_option('fifu_default_width') : 800),
60
+ isset($image_size['height']) ? $image_size['height'] : 600,
61
+ isset($image_size['crop']) ? $image_size['crop'] : '',
62
+ );
63
+ }
64
+
65
+ if (fifu_show_internal_instead_of_external(get_the_ID()))
66
+ return $image;
67
+
68
+ if ($att_id == get_post_thumbnail_id(get_the_ID())) {
69
+ $url = fifu_main_image_url(get_the_ID());
70
+ if ($url) {
71
+ return array(
72
+ $url,
73
+ 0,
74
+ 0,
75
+ false
76
+ );
77
+ }
78
+ }
79
+ return $image;
80
+ }
81
+
includes/external-post.php CHANGED
@@ -88,7 +88,128 @@ function fifu_first_url_in_content($post_id) {
88
  }
89
 
90
  function fifu_update_fake_attach_id($post_id) {
91
- if (get_option('fifu_fake_attach_id') && !get_post_thumbnail_id($post_id))
92
- set_post_thumbnail($post_id, get_option('fifu_fake_attach_id'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
 
88
  }
89
 
90
  function fifu_update_fake_attach_id($post_id) {
91
+ if (fifu_is_on('fifu_data_generation')) {
92
+ if (get_option('fifu_fake_attach_id') && !get_post_thumbnail_id($post_id))
93
+ set_post_thumbnail($post_id, get_option('fifu_fake_attach_id'));
94
+ return;
95
+ }
96
+
97
+ global $wpdb;
98
+ $posts_table = $wpdb->prefix . 'posts';
99
+ $postmeta_table = $wpdb->prefix . 'postmeta';
100
+ $att_id = get_post_thumbnail_id($post_id);
101
+ $url = fifu_main_image_url($post_id);
102
+ $AUTHOR = 77777;
103
+ if ($att_id && $att_id != null)
104
+ $has_fifu_attachment = $wpdb->get_row('SELECT 1 FROM ' . $posts_table . ' WHERE ID = ' . $att_id . ' AND POST_AUTHOR = ' . $AUTHOR) != null;
105
+ else
106
+ $has_fifu_attachment = false;
107
+
108
+ // delete
109
+ if (!fifu_main_image_url($post_id)) {
110
+ if ($has_fifu_attachment) {
111
+ if (fifu_get_default_url()) {
112
+ set_post_thumbnail($post_id, get_option('fifu_default_attach_id'));
113
+ } else {
114
+ wp_delete_attachment($att_id);
115
+ delete_post_thumbnail($post_id);
116
+ }
117
+ } else {
118
+ if (fifu_get_default_url())
119
+ set_post_thumbnail($post_id, get_option('fifu_default_attach_id'));
120
+ }
121
+ }
122
+ // update
123
+ else {
124
+ $alt = get_post_meta($post_id, 'fifu_image_alt', true);
125
+ if ($has_fifu_attachment) {
126
+ update_post_meta($att_id, '_wp_attached_file', ';' . $url);
127
+ update_post_meta($att_id, '_wp_attachment_image_alt', $alt);
128
+ $wpdb->update($posts_table, $set = array('post_title' => $alt), $where = array('id' => $att_id), null, null);
129
+ $wpdb->update($posts_table, $set = array('guid' => $url), $where = array('id' => $att_id), null, null);
130
+ }
131
+ // insert
132
+ else {
133
+ $filename = ';' . fifu_main_image_url($post_id);
134
+ $parent_post_id = $post_id;
135
+ $filetype = wp_check_filetype('fifu.png', null);
136
+ $attachment = array(
137
+ 'guid' => fifu_main_image_url($post_id),
138
+ 'post_mime_type' => $filetype['type'],
139
+ 'post_author' => $AUTHOR,
140
+ 'post_title' => $alt,
141
+ 'post_excerpt' => '',
142
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
143
+ '(some themes/plugins depend on having an attached file to work). But you are free to use any image you want instead of this file.',
144
+ 'post_status' => 'inherit'
145
+ );
146
+ $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
147
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
148
+ $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
149
+ wp_update_attachment_metadata($attach_id, $attach_data);
150
+ set_post_thumbnail($post_id, $attach_id);
151
+ update_post_meta($attach_id, '_wp_attachment_image_alt', $alt);
152
+ }
153
+ }
154
+ }
155
+
156
+ function fifu_ctgr_update_fake_attach_id($term_id) {
157
+ if (fifu_is_on('fifu_data_generation'))
158
+ return;
159
+
160
+ global $wpdb;
161
+ $posts_table = $wpdb->prefix . 'posts';
162
+ $postmeta_table = $wpdb->prefix . 'postmeta';
163
+ $termmeta_table = $wpdb->prefix . 'termmeta';
164
+ $aux = $wpdb->get_row('SELECT meta_value FROM ' . $termmeta_table . ' WHERE term_id = ' . $term_id . ' AND meta_key = "thumbnail_id"');
165
+ $att_id = $aux->meta_value;
166
+
167
+ $url = get_term_meta($term_id, 'fifu_image_url', true);
168
+
169
+ $AUTHOR = 77777;
170
+ if ($att_id && $att_id != null && $att_id != 0)
171
+ $has_fifu_attachment = $wpdb->get_row('SELECT 1 FROM ' . $posts_table . ' WHERE ID = ' . $att_id . ' AND POST_AUTHOR = ' . $AUTHOR) != null;
172
+ else
173
+ $has_fifu_attachment = false;
174
+
175
+ // delete
176
+ if (!$url) {
177
+ if ($has_fifu_attachment) {
178
+ wp_delete_attachment($att_id);
179
+ update_term_meta($term_id, 'thumbnail_id', 0);
180
+ }
181
+ }
182
+ // update
183
+ else {
184
+ $alt = get_term_meta($term_id, 'fifu_image_alt', true);
185
+ if ($has_fifu_attachment) {
186
+ update_post_meta($att_id, '_wp_attached_file', ';' . $url);
187
+ update_post_meta($att_id, '_wp_attachment_image_alt', $alt);
188
+ $wpdb->update($posts_table, $set = array('post_title' => $alt), $where = array('id' => $att_id), null, null);
189
+ $wpdb->update($posts_table, $set = array('guid' => $url), $where = array('id' => $att_id), null, null);
190
+ }
191
+ // insert
192
+ else {
193
+ $filename = ';' . $url;
194
+ $parent_post_id = 0;
195
+ $filetype = wp_check_filetype('fifu.png', null);
196
+ $attachment = array(
197
+ 'guid' => $url,
198
+ 'post_mime_type' => $filetype['type'],
199
+ 'post_author' => $AUTHOR,
200
+ 'post_title' => $alt,
201
+ 'post_excerpt' => '',
202
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
203
+ '(some themes/plugins depend on having an attached file to work). But you are free to use any image you want instead of this file.',
204
+ 'post_status' => 'inherit'
205
+ );
206
+ $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
207
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
208
+ $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
209
+ wp_update_attachment_metadata($attach_id, $attach_data);
210
+ update_term_meta($term_id, 'thumbnail_id', $attach_id);
211
+ update_post_meta($attach_id, '_wp_attachment_image_alt', $alt);
212
+ }
213
+ }
214
  }
215
 
includes/genesis.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_filter('genesis_get_image', 'fifu_genesis_image', 10, 4);
4
+
5
+ function fifu_genesis_image($args, $size, $var2, $src) {
6
+ return $src ? fifu_replace($args, get_the_ID(), $var2, $size) : $args;
7
+ }
8
+
includes/html/css/woo.css CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  img.zoomImg {
2
  display:<?php echo fifu_woo_zoom(); ?> !important;
3
  }
1
+ .woocommerce .products ul, .woocommerce ul.products {
2
+ margin: 0 0 0em;
3
+ }
4
+
5
  img.zoomImg {
6
  display:<?php echo fifu_woo_zoom(); ?> !important;
7
  }
includes/html/js/image.js CHANGED
@@ -1,12 +1,31 @@
1
  jQuery(document).ready(function ($) {
2
  disableClick($);
 
3
  setTimeout(function () {
4
- jQuery('div.flex-viewport').each(function (index) {
5
- jQuery(this).css('height', '');
6
- });
7
- }, 500);
 
 
 
8
  });
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  function disableClick($) {
11
  if ('<?php echo !fifu_woo_lbox(); ?>') {
12
  jQuery('.woocommerce-product-gallery__image').each(function (index) {
1
  jQuery(document).ready(function ($) {
2
  disableClick($);
3
+ //for all images at single product page
4
  setTimeout(function () {
5
+ resizeImg($);
6
+ jQuery('a.woocommerce-product-gallery__trigger').css('visibility', 'visible');
7
+ }, 2000);
8
+ });
9
+
10
+ jQuery(window).on('load', function () {
11
+ jQuery('.flex-viewport').css('height', '100%');
12
  });
13
 
14
+ function resizeImg($) {
15
+ var imgSelector = ".post img, .page img, .widget-content img, .product img, .wp-admin img, .tax-product_cat img, .fifu img";
16
+ var resizeImage = function (sSel) {
17
+ jQuery(sSel).each(function () {
18
+ //original size
19
+ var width = $(this)['0'].naturalWidth;
20
+ var height = $(this)['0'].naturalHeight;
21
+ var ratio = width / height;
22
+ jQuery(this).attr('data-large_image_width', jQuery(window).width() * ratio);
23
+ jQuery(this).attr('data-large_image_height', jQuery(window).width());
24
+ });
25
+ };
26
+ resizeImage(imgSelector);
27
+ }
28
+
29
  function disableClick($) {
30
  if ('<?php echo !fifu_woo_lbox(); ?>') {
31
  jQuery('.woocommerce-product-gallery__image').each(function (index) {
includes/thumbnail-category.php CHANGED
@@ -1,22 +1,22 @@
1
  <?php
2
 
3
- add_filter('woocommerce_before_main_content', 'fifu_cat_show_image', 30);
4
 
5
- function fifu_cat_show_image() {
6
- $url = fifu_cat_get_url();
7
- $alt = fifu_cat_get_alt();
8
 
9
  if ($url)
10
- echo fifu_get_html($url, $alt);
11
  }
12
 
13
- add_filter('wp_head', 'fifu_cat_add_social_tags');
14
 
15
- function fifu_cat_add_social_tags() {
16
- $url = fifu_cat_get_url();
17
  $title = single_cat_title('', false);
18
 
19
- $term_id = fifu_cat_get_term_id();
20
  if ($term_id)
21
  $description = wp_strip_all_tags(category_description($term_id));
22
 
@@ -24,17 +24,17 @@ function fifu_cat_add_social_tags() {
24
  include 'html/social.html';
25
  }
26
 
27
- function fifu_cat_get_url() {
28
- $term_id = fifu_cat_get_term_id();
29
  return get_term_meta($term_id, 'fifu_image_url', true);
30
  }
31
 
32
- function fifu_cat_get_alt() {
33
- $term_id = fifu_cat_get_term_id();
34
  return get_term_meta($term_id, 'fifu_image_alt', true);
35
  }
36
 
37
- function fifu_cat_get_term_id() {
38
  global $wp_query;
39
  return $wp_query->get_queried_object_id();
40
  }
1
  <?php
2
 
3
+ add_filter('woocommerce_before_main_content', 'fifu_ctgr_show_image', 30);
4
 
5
+ function fifu_ctgr_show_image() {
6
+ $url = fifu_ctgr_get_url();
7
+ $alt = fifu_ctgr_get_alt();
8
 
9
  if ($url)
10
+ echo fifu_get_html($url, $alt, null, null);
11
  }
12
 
13
+ add_filter('wp_head', 'fifu_ctgr_add_social_tags');
14
 
15
+ function fifu_ctgr_add_social_tags() {
16
+ $url = fifu_ctgr_get_url();
17
  $title = single_cat_title('', false);
18
 
19
+ $term_id = fifu_ctgr_get_term_id();
20
  if ($term_id)
21
  $description = wp_strip_all_tags(category_description($term_id));
22
 
24
  include 'html/social.html';
25
  }
26
 
27
+ function fifu_ctgr_get_url() {
28
+ $term_id = fifu_ctgr_get_term_id();
29
  return get_term_meta($term_id, 'fifu_image_url', true);
30
  }
31
 
32
+ function fifu_ctgr_get_alt() {
33
+ $term_id = fifu_ctgr_get_term_id();
34
  return get_term_meta($term_id, 'fifu_image_alt', true);
35
  }
36
 
37
+ function fifu_ctgr_get_term_id() {
38
  global $wp_query;
39
  return $wp_query->get_queried_object_id();
40
  }
includes/thumbnail.php CHANGED
@@ -22,7 +22,7 @@ function fifu_add_social_tags() {
22
  }
23
 
24
  function fifu_add_sirv_js() {
25
- include_once(ABSPATH . 'wp-admin/includes/plugin.php');
26
  if (is_plugin_active('sirv/sirv.php')) {
27
  include 'html/sirv.html';
28
  }
@@ -31,6 +31,8 @@ function fifu_add_sirv_js() {
31
  function fifu_apply_css() {
32
  if (fifu_is_off('fifu_wc_lbox'))
33
  echo '<style>[class$="woocommerce-product-gallery__trigger"] {display:none !important;}</style>';
 
 
34
  }
35
 
36
  add_action('the_post', 'fifu_choose');
@@ -45,7 +47,7 @@ function fifu_choose($post) {
45
 
46
  $featured_image = get_post_meta($post_id, '_thumbnail_id', true);
47
 
48
- if ($image_url || get_option('fifu_default_url')) {
49
  if (!$featured_image)
50
  update_post_meta($post_id, '_thumbnail_id', -1);
51
  }
@@ -55,21 +57,39 @@ function fifu_choose($post) {
55
  }
56
  }
57
 
58
- add_filter('post_thumbnail_html', 'fifu_replace', 10, 2);
59
 
60
- function fifu_replace($html, $post_id) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  $url = get_post_meta($post_id, 'fifu_image_url', true);
62
  $alt = get_post_meta($post_id, 'fifu_image_alt', true);
63
 
64
- return !$url || fifu_show_internal_instead_of_external($post_id) ? $html : fifu_get_html($url, $alt);
65
  }
66
 
67
  function is_ajax_call() {
68
  return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') || wp_doing_ajax();
69
  }
70
 
71
- function fifu_get_html($url, $alt) {
72
- include_once(ABSPATH . 'wp-admin/includes/plugin.php');
73
  if (is_plugin_active('sirv/sirv.php') && strpos($url, "sirv.com") !== false)
74
  return sprintf('<!-- Featured Image From URL plugin --> <img class="Sirv" data-src="%s">', $url);
75
 
@@ -79,6 +99,10 @@ function fifu_get_html($url, $alt) {
79
  $css = 'display:none';
80
  }
81
 
 
 
 
 
82
  return sprintf('<!-- Featured Image From URL plugin --> <img %s alt="%s" title="%s" style="%s">', fifu_lazy_url($url), $alt, $alt, $css);
83
  }
84
 
@@ -88,67 +112,37 @@ function fifu_add_to_content($content) {
88
  return is_singular() && has_post_thumbnail() && ((is_singular('post') && fifu_is_on('fifu_content')) or ( is_singular('page') && fifu_is_on('fifu_content_page'))) ? get_the_post_thumbnail() . $content : $content;
89
  }
90
 
91
- add_filter('wp_get_attachment_url', 'fifu_replace_attachment_url', 10, 2);
92
-
93
- function fifu_replace_attachment_url($att_url, $att_id) {
94
- if (fifu_show_internal_instead_of_external(get_the_ID()))
95
- return $att_url;
96
-
97
- if ($att_id == get_post_thumbnail_id(get_the_ID())) {
98
- $url = fifu_main_image_url(get_the_ID());
99
- if ($url)
100
- $att_url = $url;
101
- }
102
- return $att_url;
103
- }
104
-
105
- add_filter('wp_get_attachment_image_src', 'fifu_replace_attachment_image_src', 10, 2);
106
-
107
- function fifu_replace_attachment_image_src($image, $att_id) {
108
- if (fifu_show_internal_instead_of_external(get_the_ID()))
109
- return $image;
110
-
111
- if ($att_id == get_post_thumbnail_id(get_the_ID())) {
112
- $url = fifu_main_image_url(get_the_ID());
113
- if ($url) {
114
- return array(
115
- $url,
116
- 0,
117
- 0,
118
- false
119
- );
120
- }
121
- }
122
- return $image;
123
- }
124
-
125
  function fifu_should_hide() {
126
  return ((is_singular('post') && fifu_is_on('fifu_hide_post')) || (is_singular('page') && fifu_is_on('fifu_hide_page')));
127
  }
128
 
129
- add_filter('genesis_get_image', 'fifu_genesis_image', 10, 4);
130
-
131
- function fifu_genesis_image($args, $var1, $var2, $src) {
132
- return $src ? fifu_replace($args, get_the_ID()) : $args;
133
- }
134
-
135
  function fifu_main_image_url($post_id) {
136
  $url = get_post_meta($post_id, 'fifu_image_url', true);
137
 
138
- if (!$url && fifu_no_internal_image($post_id))
139
  $url = get_option('fifu_default_url');
140
 
141
  return $url;
142
  }
143
 
144
  function fifu_no_internal_image($post_id) {
145
- return get_post_meta($post_id, '_thumbnail_id', true) == -1;
146
  }
147
 
148
  function fifu_lazy_url($url) {
149
- if (!fifu_is_on('fifu_lazy') || is_ajax_call())
150
  return 'src="' . $url . '"';
151
- return (is_home() || (class_exists('WooCommerce') && is_shop()) ? 'data-src="' : 'src="') . $url . '"';
 
 
 
 
 
 
 
 
 
 
152
  }
153
 
154
  function fifu_is_fake_disabled() {
@@ -156,8 +150,8 @@ function fifu_is_fake_disabled() {
156
  }
157
 
158
  function fifu_has_internal_image($post_id) {
159
- $featured_image = get_post_meta($post_id, '_thumbnail_id', true);
160
- return $featured_image && $featured_image != -1 && $featured_image != get_option('fifu_fake_attach_id');
161
  }
162
 
163
  function fifu_show_internal_instead_of_external($post_id) {
@@ -174,3 +168,37 @@ function fifu_internal_priority() {
174
  return fifu_is_on('fifu_priority');
175
  }
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
 
24
  function fifu_add_sirv_js() {
25
+ include_once (ABSPATH . 'wp-admin/includes/plugin.php');
26
  if (is_plugin_active('sirv/sirv.php')) {
27
  include 'html/sirv.html';
28
  }
31
  function fifu_apply_css() {
32
  if (fifu_is_off('fifu_wc_lbox'))
33
  echo '<style>[class$="woocommerce-product-gallery__trigger"] {display:none !important;}</style>';
34
+ else
35
+ echo '<style>[class$="woocommerce-product-gallery__trigger"] {visibility:hidden;}</style>';
36
  }
37
 
38
  add_action('the_post', 'fifu_choose');
47
 
48
  $featured_image = get_post_meta($post_id, '_thumbnail_id', true);
49
 
50
+ if ($image_url || (get_option('fifu_default_url') && fifu_is_on('fifu_enable_default_url'))) {
51
  if (!$featured_image)
52
  update_post_meta($post_id, '_thumbnail_id', -1);
53
  }
57
  }
58
  }
59
 
60
+ add_filter('woocommerce_product_get_image', 'fifu_woo_replace', 10, 5);
61
 
62
+ function fifu_woo_replace($html, $product, $woosize) {
63
+ return fifu_replace($html, get_the_id(), null, null);
64
+ }
65
+
66
+ add_filter('post_thumbnail_html', 'fifu_replace', 10, 4);
67
+
68
+ function fifu_replace($html, $post_id, $post_thumbnail_id, $size) {
69
+ if (fifu_is_off('fifu_data_generation')) {
70
+ $width = fifu_get_attribute('width', $html);
71
+ $height = fifu_get_attribute('height', $html);
72
+
73
+ if (get_post_meta($post_id, 'fifu_image_url', true))
74
+ return $html;
75
+
76
+ $url = get_post_meta($post_id, 'fifu_image_url', true);
77
+ $alt = get_post_meta($post_id, 'fifu_image_alt', true);
78
+
79
+ return !$url ? $html : fifu_get_html($url, $alt, $width, $height);
80
+ }
81
  $url = get_post_meta($post_id, 'fifu_image_url', true);
82
  $alt = get_post_meta($post_id, 'fifu_image_alt', true);
83
 
84
+ return !$url || fifu_show_internal_instead_of_external($post_id) ? $html : fifu_get_html($url, $alt, null, null);
85
  }
86
 
87
  function is_ajax_call() {
88
  return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') || wp_doing_ajax();
89
  }
90
 
91
+ function fifu_get_html($url, $alt, $width, $height) {
92
+ include_once (ABSPATH . 'wp-admin/includes/plugin.php');
93
  if (is_plugin_active('sirv/sirv.php') && strpos($url, "sirv.com") !== false)
94
  return sprintf('<!-- Featured Image From URL plugin --> <img class="Sirv" data-src="%s">', $url);
95
 
99
  $css = 'display:none';
100
  }
101
 
102
+ if (fifu_is_off('fifu_data_generation')) {
103
+ return sprintf('<!-- Powered by Featured Image From URL plugin --> <img %s alt="%s" title="%s" style="%s" data-large_image="%s" data-large_image_width="%s" data-large_image_height="%s" onerror="%s" width="%s" height="%s">', fifu_lazy_url($url), $alt, $alt, $css, $url, "800", "600", "jQuery(this).hide();", $width, $height);
104
+ }
105
+
106
  return sprintf('<!-- Featured Image From URL plugin --> <img %s alt="%s" title="%s" style="%s">', fifu_lazy_url($url), $alt, $alt, $css);
107
  }
108
 
112
  return is_singular() && has_post_thumbnail() && ((is_singular('post') && fifu_is_on('fifu_content')) or ( is_singular('page') && fifu_is_on('fifu_content_page'))) ? get_the_post_thumbnail() . $content : $content;
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  function fifu_should_hide() {
116
  return ((is_singular('post') && fifu_is_on('fifu_hide_post')) || (is_singular('page') && fifu_is_on('fifu_hide_page')));
117
  }
118
 
 
 
 
 
 
 
119
  function fifu_main_image_url($post_id) {
120
  $url = get_post_meta($post_id, 'fifu_image_url', true);
121
 
122
+ if (!$url && fifu_no_internal_image($post_id) && !fifu_is_on('fifu_fake2') && (get_option('fifu_default_url') && fifu_is_on('fifu_enable_default_url')))
123
  $url = get_option('fifu_default_url');
124
 
125
  return $url;
126
  }
127
 
128
  function fifu_no_internal_image($post_id) {
129
+ return get_post_meta($post_id, '_thumbnail_id', true) == -1 || get_post_meta($post_id, '_thumbnail_id', true) == null || get_post_meta($post_id, '_thumbnail_id', true) == get_option('fifu_default_attach_id');
130
  }
131
 
132
  function fifu_lazy_url($url) {
133
+ if (fifu_is_off('fifu_lazy') || is_ajax_call())
134
  return 'src="' . $url . '"';
135
+ return (fifu_is_main_page() ? 'data-src="' : 'src="') . $url . '"';
136
+ }
137
+
138
+ function fifu_lazy_src_type() {
139
+ if (fifu_is_off('fifu_lazy') || is_ajax_call())
140
+ return 'src=';
141
+ return (fifu_is_main_page() ? 'data-src=' : 'src=');
142
+ }
143
+
144
+ function fifu_is_main_page() {
145
+ return is_home() || (class_exists('WooCommerce') && is_shop());
146
  }
147
 
148
  function fifu_is_fake_disabled() {
150
  }
151
 
152
  function fifu_has_internal_image($post_id) {
153
+ $att_id = get_post_meta($post_id, '_thumbnail_id', true);
154
+ return $att_id && $att_id != -1 && $att_id != get_option('fifu_fake_attach_id') && get_post($att_id)->post_author != 77777;
155
  }
156
 
157
  function fifu_show_internal_instead_of_external($post_id) {
168
  return fifu_is_on('fifu_priority');
169
  }
170
 
171
+ function fifu_get_image_sizes() {
172
+ global $_wp_additional_image_sizes;
173
+ $sizes = array();
174
+ foreach (get_intermediate_image_sizes() as $_size) {
175
+ if (in_array($_size, array('thumbnail', 'medium', 'medium_large', 'large'))) {
176
+ $sizes[$_size]['width'] = get_option("{$_size}_size_w");
177
+ $sizes[$_size]['height'] = get_option("{$_size}_size_h");
178
+ $sizes[$_size]['crop'] = (bool) get_option("{$_size}_crop");
179
+ } elseif (isset($_wp_additional_image_sizes[$_size])) {
180
+ $sizes[$_size] = array(
181
+ 'width' => $_wp_additional_image_sizes[$_size]['width'],
182
+ 'height' => $_wp_additional_image_sizes[$_size]['height'],
183
+ 'crop' => $_wp_additional_image_sizes[$_size]['crop'],
184
+ );
185
+ }
186
+ }
187
+ return $sizes;
188
+ }
189
+
190
+ function fifu_get_image_size($size) {
191
+ $sizes = fifu_get_image_sizes();
192
+ if (is_array($size)) {
193
+ $arr_size = array();
194
+ $arr_size['width'] = $size[0];
195
+ $arr_size['height'] = $size[1];
196
+ return $arr_size;
197
+ }
198
+ return isset($sizes[$size]) ? $sizes[$size] : false;
199
+ }
200
+
201
+ function fifu_get_default_url() {
202
+ return wp_get_attachment_url(get_option('fifu_default_attach_id'));
203
+ }
204
+
includes/util.php CHANGED
@@ -1,22 +1,45 @@
1
  <?php
2
 
3
  function fifu_get_img_width_from_html($html) {
 
 
4
  $aux = explode('img width=', $html)[1];
5
  return explode('"', $aux)[1];
6
  }
7
 
8
  function fifu_get_src_from_html($html) {
 
 
9
  $aux = explode('src=', $html)[1];
10
  return explode('"', $aux)[1];
11
  }
12
 
13
  function fifu_get_data_large_from_html($html) {
 
 
14
  $aux = explode('data-large_image=', $html);
15
  $aux = $aux && count($aux) > 1 ? $aux[1] : null;
16
  $url = $aux ? explode('"', $aux)[1] : null;
17
  return $url;
18
  }
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  function fifu_is_on($option) {
21
  return get_option($option) == 'toggleon';
22
  }
1
  <?php
2
 
3
  function fifu_get_img_width_from_html($html) {
4
+ if (strpos($html, 'img width=') === false)
5
+ return $html;
6
  $aux = explode('img width=', $html)[1];
7
  return explode('"', $aux)[1];
8
  }
9
 
10
  function fifu_get_src_from_html($html) {
11
+ if (strpos($html, 'src=') === false)
12
+ return $html;
13
  $aux = explode('src=', $html)[1];
14
  return explode('"', $aux)[1];
15
  }
16
 
17
  function fifu_get_data_large_from_html($html) {
18
+ if (strpos($html, 'data-large_image=') === false)
19
+ return $html;
20
  $aux = explode('data-large_image=', $html);
21
  $aux = $aux && count($aux) > 1 ? $aux[1] : null;
22
  $url = $aux ? explode('"', $aux)[1] : null;
23
  return $url;
24
  }
25
 
26
+ function fifu_get_attribute($attribute, $html) {
27
+ $attribute = $attribute . '=';
28
+ if (strpos($html, $attribute) === false)
29
+ return null;
30
+ $aux = explode($attribute, $html)[1];
31
+ return explode('"', $aux)[1];
32
+ }
33
+
34
+ function fifu_replace_attribute($html, $attribute, $value) {
35
+ $attribute = $attribute . '=';
36
+ if (strpos($html, $attribute) === false)
37
+ return $html;
38
+ $matches = array();
39
+ preg_match('/' . $attribute . '[^ ]+/', $html, $matches);
40
+ return str_replace($matches[0], $attribute . '"' . $value . '"', $html);
41
+ }
42
+
43
  function fifu_is_on($option) {
44
  return get_option($option) == 'toggleon';
45
  }
includes/woo.php CHANGED
@@ -1,5 +1,14 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
3
  function fifu_woo_zoom() {
4
  return fifu_is_on('fifu_wc_zoom') ? 'inline' : 'none';
5
  }
@@ -11,3 +20,8 @@ function fifu_woo_lbox() {
11
  function fifu_woo_theme() {
12
  return file_exists(get_template_directory() . '/woocommerce');
13
  }
 
 
 
 
 
1
  <?php
2
 
3
+ add_filter('wc_get_template', 'fifu_woo_template', 10, 5);
4
+
5
+ function fifu_woo_template($located, $template_name, $args, $template_path, $default_path) {
6
+ if (($file_name = 'single-product/photoswipe.php') == $template_name)
7
+ return fifu_woo_exists($file_name) ? $located : FIFU_PLUGIN_DIR . 'woocommerce/photoswipe.php';
8
+
9
+ return $located;
10
+ }
11
+
12
  function fifu_woo_zoom() {
13
  return fifu_is_on('fifu_wc_zoom') ? 'inline' : 'none';
14
  }
20
  function fifu_woo_theme() {
21
  return file_exists(get_template_directory() . '/woocommerce');
22
  }
23
+
24
+ function fifu_woo_exists($file_name) {
25
+ return file_exists(get_template_directory() . '/woocommerce/' . $file_name);
26
+ }
27
+
readme.txt CHANGED
@@ -161,6 +161,9 @@ Features:
161
 
162
  == Changelog ==
163
 
 
 
 
164
  = 1.9.13 =
165
  * Improvement: clean meta data feature.
166
 
@@ -428,6 +431,9 @@ was removed. To finish, a Premium version is now been presented.
428
 
429
  == Upgrade Notice ==
430
 
 
 
 
431
  = 1.9.13 =
432
  * Improvement: clean meta data feature.
433
 
161
 
162
  == Changelog ==
163
 
164
+ = 2.0.0 =
165
+ * Beta Version (NOT STABLE): a lot of changes were done to overcome some old known issues in FIFU 1, such as problems in image sizes or images that were not shown in some areas, including WooCommerce lightbox and categories. Fake Internal Featured Image and Default External Featured Image features have changed. And Default Width was created.
166
+
167
  = 1.9.13 =
168
  * Improvement: clean meta data feature.
169
 
431
 
432
  == Upgrade Notice ==
433
 
434
+ = 2.0.0 =
435
+ * Beta Version (NOT STABLE): a lot of changes were done to overcome some old known issues in FIFU 1, such as problems in image sizes or images that were not shown in some areas, including WooCommerce lightbox and categories. Fake Internal Featured Image and Default External Featured Image features have changed. And Default Width was created.
436
+
437
  = 1.9.13 =
438
  * Improvement: clean meta data feature.
439
 
woocommerce/photoswipe.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Photoswipe markup
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/woocommerce/single-product/photoswipe.php.
6
+ *
7
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
8
+ * (the theme developer) will need to copy the new files to your theme to
9
+ * maintain compatibility. We try to do this as little as possible, but it does
10
+ * happen. When this occurs the version of the template file will be bumped and
11
+ * the readme will list any important changes.
12
+ *
13
+ * @see https://docs.woocommerce.com/document/template-structure/
14
+ * @author WooThemes
15
+ * @package WooCommerce/Templates
16
+ * @version 3.0.0
17
+ */
18
+
19
+ if ( ! defined( 'ABSPATH' ) ) {
20
+ exit; // Exit if accessed directly.
21
+ }
22
+ ?>
23
+
24
+ <style>.pswp__zoom-wrap:before,.wrapper{display:inline-block;vertical-align:middle}.video-wrapper,.wrapper{position:relative;width:100%}.pswp__zoom-wrap{text-align:center}.pswp__zoom-wrap:before{content:"";height:100%}.wrapper{line-height:0;max-width:78%;margin:0 auto;text-align:left;z-index:1045}.video-wrapper{padding-bottom:56.25%;padding-top:25px;height:0}.video-wrapper iframe{position:absolute;top:0;left:0;width:100%;height:100%}</style>
25
+ <div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
26
+
27
+ <!-- Background of PhotoSwipe. It's a separate element as animating opacity is faster than rgba(). -->
28
+ <div class="pswp__bg"></div>
29
+
30
+ <!-- Slides wrapper with overflow:hidden. -->
31
+ <div class="pswp__scroll-wrap">
32
+
33
+ <!-- Container that holds slides.
34
+ PhotoSwipe keeps only 3 of them in the DOM to save memory.
35
+ Don't modify these 3 pswp__item elements, data is added later on. -->
36
+ <div class="pswp__container">
37
+ <div class="pswp__item"></div>
38
+ <div class="pswp__item"></div>
39
+ <div class="pswp__item"></div>
40
+ </div>
41
+
42
+ <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
43
+ <div class="pswp__ui pswp__ui--hidden">
44
+
45
+ <div class="pswp__top-bar">
46
+
47
+ <!-- Controls are self-explanatory. Order can be changed. -->
48
+
49
+ <div class="pswp__counter"></div>
50
+
51
+ <button class="pswp__button pswp__button--close" aria-label="<?php esc_attr_e( 'Close (Esc)', 'woocommerce' ); ?>"></button>
52
+
53
+ <button class="pswp__button pswp__button--share" aria-label="<?php esc_attr_e( 'Share', 'woocommerce' ); ?>"></button>
54
+
55
+ <button class="pswp__button pswp__button--fs" aria-label="<?php esc_attr_e( 'Toggle fullscreen', 'woocommerce' ); ?>"></button>
56
+
57
+ <button class="pswp__button pswp__button--zoom" aria-label="<?php esc_attr_e( 'Zoom in/out', 'woocommerce' ); ?>"></button>
58
+
59
+ <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
60
+ <!-- element will get class pswp__preloader--active when preloader is running -->
61
+ <div class="pswp__preloader">
62
+ <div class="pswp__preloader__icn">
63
+ <div class="pswp__preloader__cut">
64
+ <div class="pswp__preloader__donut"></div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ </div>
69
+
70
+ <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
71
+ <div class="pswp__share-tooltip"></div>
72
+ </div>
73
+
74
+ <button class="pswp__button pswp__button--arrow--left" aria-label="<?php esc_attr_e( 'Previous (arrow left)', 'woocommerce' ); ?>"></button>
75
+
76
+ <button class="pswp__button pswp__button--arrow--right" aria-label="<?php esc_attr_e( 'Next (arrow right)', 'woocommerce' ); ?>"></button>
77
+
78
+ <div class="pswp__caption">
79
+ <div class="pswp__caption__center"></div>
80
+ </div>
81
+
82
+ </div>
83
+
84
+ </div>
85
+
86
+ </div>