Featured Image From URL - Version 1.6.8

Version Description

  • Image validation and fake internal featured image.

=

Download this release

Release Info

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

Code changes from version 1.6.7 to 1.6.8

admin/html/menu.html CHANGED
@@ -124,6 +124,33 @@
124
  </form>
125
  </div>
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  <div class="box">
128
  <h2>Featured Image Column</h2>
129
  <div class="greybox" style="background:#e3ffe2">
@@ -904,6 +931,20 @@
904
  </div>
905
  </div>
906
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
907
  <div class="box">
908
  <h2>WooCommerce Lightbox</h2>
909
  <div class="greybox" style="background:#ffe2e2">
124
  </form>
125
  </div>
126
 
127
+ <div class="box">
128
+ <h2>Fake Internal Featured Image</h2>
129
+ <div class="greybox" style="background:#e3ffe2">
130
+ 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.
131
+ </div>
132
+ <p/>
133
+ <form
134
+ id="fifu_form_fake"
135
+ action="javascript:void(0)"
136
+ method="post">
137
+ <input
138
+ type="image"
139
+ href="javascript:void(0)"
140
+ id="fifu_toggle_fake"
141
+ onclick="invert('fake')"
142
+ name="fifu_toggle_fake"
143
+ class="<?php echo $enable_fake; ?>"
144
+ value=" "
145
+ style="display:block" >
146
+ <input
147
+ type="hidden"
148
+ id="fifu_input_fake"
149
+ name="fifu_input_fake"
150
+ value="" >
151
+ </form>
152
+ </div>
153
+
154
  <div class="box">
155
  <h2>Featured Image Column</h2>
156
  <div class="greybox" style="background:#e3ffe2">
931
  </div>
932
  </div>
933
 
934
+ <div class="box">
935
+ <h2>Validate Images</h2>
936
+ <div class="greybox" style="background:#ffe2e2">
937
+ <b>Premium feature</b><br><br>
938
+ Allows to check image URLs and, when an image is not found, its URL is not saved. However, the validation can make the saving time too long. It is not integrated with Auto Set Featured Image or WP Rest API features yet.
939
+ </div>
940
+ <br>
941
+ <input
942
+ type="image"
943
+ href="javascript:void(0)"
944
+ class="toggleoff"
945
+ value=" " style="display:block">
946
+ </div>
947
+
948
  <div class="box">
949
  <h2>WooCommerce Lightbox</h2>
950
  <div class="greybox" style="background:#ffe2e2">
admin/html/meta-box.html CHANGED
@@ -50,14 +50,10 @@
50
  <div style="<?php echo $show_news?>">
51
  <br>
52
  <hr>
53
- <p style="font-size: 12px; padding: 5px; border-left: 6px solid #c61fa5; color: black;
54
- background-color: #eee; border-radius: 15px 50px;">New: support to Instagram images (17% <a href="https://goo.gl/forms/TxLdhwXTqsuO5BHg2">votes</a>)</p>
55
- <p style="font-size: 12px; padding: 5px; border-left: 6px solid #66a0fd; color: black;
56
- background-color: #eee; border-radius: 15px 50px;">New: support to Google Drive images</p>
57
- <p style="font-size: 12px; padding: 5px; border-left: 6px solid green; color: black;
58
- background-color: #eee; border-radius: 15px 50px;">New: Lazy Load</p>
59
- <p style="font-size: 12px; padding: 5px; border-left: 6px solid #ff5400; color: black;
60
- background-color: #eee; border-radius: 15px 50px;">New (premium): WP REST API integration</p>
61
  <center>
62
  <table>
63
  <tbody>
50
  <div style="<?php echo $show_news?>">
51
  <br>
52
  <hr>
53
+ <p style="font-size: 12px; padding: 5px; border-left: 6px solid #6f7277; color: black;
54
+ background-color: #eee; border-radius: 15px 50px;">New: fake internal featured image (improves the compatibility with many themes/plugins such as Jetpack, Visual Composer and Customizr). 27% <a href="https://goo.gl/forms/TxLdhwXTqsuO5BHg2">votes</a></p>
55
+ <p style="font-size: 12px; padding: 5px; border-left: 6px solid #62f442; color: black;
56
+ background-color: #eee; border-radius: 15px 50px;">New: image validation (if the image isn't found, the URL isn't saved).</p>
 
 
 
 
57
  <center>
58
  <table>
59
  <tbody>
admin/menu.php CHANGED
@@ -17,6 +17,7 @@ function fifu_get_menu_html() {
17
  $enable_social = get_option('fifu_social');
18
  $enable_lazy = get_option('fifu_lazy');
19
  $enable_content = get_option('fifu_content');
 
20
  $enable_hide_page = get_option('fifu_hide_page');
21
  $enable_hide_post = get_option('fifu_hide_post');
22
  $enable_get_first = get_option('fifu_get_first');
@@ -33,6 +34,11 @@ function fifu_get_menu_html() {
33
  fifu_update_menu_options();
34
 
35
  fifu_script_woocommerce();
 
 
 
 
 
36
  }
37
 
38
  function fifu_get_menu_settings() {
@@ -40,6 +46,7 @@ function fifu_get_menu_settings() {
40
  fifu_get_setting('fifu_social');
41
  fifu_get_setting('fifu_lazy');
42
  fifu_get_setting('fifu_content');
 
43
  fifu_get_setting('fifu_hide_page');
44
  fifu_get_setting('fifu_hide_post');
45
  fifu_get_setting('fifu_get_first');
@@ -69,6 +76,7 @@ function fifu_update_menu_options() {
69
  fifu_update_option('fifu_input_social', 'fifu_social');
70
  fifu_update_option('fifu_input_lazy', 'fifu_lazy');
71
  fifu_update_option('fifu_input_content', 'fifu_content');
 
72
  fifu_update_option('fifu_input_hide_page', 'fifu_hide_page');
73
  fifu_update_option('fifu_input_hide_post', 'fifu_hide_post');
74
  fifu_update_option('fifu_input_get_first', 'fifu_get_first');
@@ -106,3 +114,83 @@ function fifu_script_woocommerce() {
106
  function show_woocommerce_box() {
107
  return function_exists('WC') && WC()->version < 2.6 ? 'display:inline' : 'display:none';
108
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  $enable_social = get_option('fifu_social');
18
  $enable_lazy = get_option('fifu_lazy');
19
  $enable_content = get_option('fifu_content');
20
+ $enable_fake = get_option('fifu_fake');
21
  $enable_hide_page = get_option('fifu_hide_page');
22
  $enable_hide_post = get_option('fifu_hide_post');
23
  $enable_get_first = get_option('fifu_get_first');
34
  fifu_update_menu_options();
35
 
36
  fifu_script_woocommerce();
37
+
38
+ if (get_option('fifu_fake') == 'toggleon')
39
+ fifu_enable_fake();
40
+ else
41
+ fifu_disable_fake();
42
  }
43
 
44
  function fifu_get_menu_settings() {
46
  fifu_get_setting('fifu_social');
47
  fifu_get_setting('fifu_lazy');
48
  fifu_get_setting('fifu_content');
49
+ fifu_get_setting('fifu_fake');
50
  fifu_get_setting('fifu_hide_page');
51
  fifu_get_setting('fifu_hide_post');
52
  fifu_get_setting('fifu_get_first');
76
  fifu_update_option('fifu_input_social', 'fifu_social');
77
  fifu_update_option('fifu_input_lazy', 'fifu_lazy');
78
  fifu_update_option('fifu_input_content', 'fifu_content');
79
+ fifu_update_option('fifu_input_fake', 'fifu_fake');
80
  fifu_update_option('fifu_input_hide_page', 'fifu_hide_page');
81
  fifu_update_option('fifu_input_hide_post', 'fifu_hide_post');
82
  fifu_update_option('fifu_input_get_first', 'fifu_get_first');
114
  function show_woocommerce_box() {
115
  return function_exists('WC') && WC()->version < 2.6 ? 'display:inline' : 'display:none';
116
  }
117
+
118
+ function fifu_enable_fake() {
119
+ if (get_option('fifu_fake_attach_id'))
120
+ return;
121
+
122
+ global $wpdb;
123
+ $old_attach_id = get_option('fifu_fake_attach_id');
124
+
125
+ // create attachment
126
+ $filename = 'Featured Image from URL';
127
+ $parent_post_id = null;
128
+ $filetype = wp_check_filetype('fifu.png', null);
129
+ $attachment = array(
130
+ 'guid' => basename($filename),
131
+ 'post_mime_type' => $filetype['type'],
132
+ 'post_title' => '',
133
+ 'post_excerpt' => '',
134
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
135
+ '(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.',
136
+ 'post_status' => 'inherit'
137
+ );
138
+ $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
139
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
140
+ $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
141
+ wp_update_attachment_metadata($attach_id, $attach_data);
142
+ update_option('fifu_fake_attach_id', $attach_id);
143
+
144
+ // insert _thumbnail_id
145
+ $table = $wpdb->prefix . 'postmeta';
146
+ $query = "
147
+ SELECT DISTINCT post_id
148
+ FROM " . $table . " a
149
+ WHERE a.post_id in (
150
+ SELECT post_id
151
+ FROM " . $table . " b
152
+ WHERE b.meta_key IN ('fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
153
+ AND b.meta_value IS NOT NULL
154
+ AND b.meta_value <> ''
155
+ )
156
+ AND NOT EXISTS (
157
+ SELECT 1
158
+ FROM " . $table . " c
159
+ WHERE a.post_id = c.post_id
160
+ AND c.meta_key = '_thumbnail_id'
161
+ )";
162
+ $result = $wpdb->get_results($query);
163
+ foreach ($result as $i) {
164
+ $data = array('post_id' => $i->post_id, 'meta_key' => '_thumbnail_id', 'meta_value' => $attach_id);
165
+ $wpdb->insert($table, $data);
166
+ }
167
+
168
+ // update _thumbnail_id
169
+ $data = array('meta_value' => $attach_id);
170
+ $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $old_attach_id);
171
+ $wpdb->update($table, $data, $where, null, null);
172
+
173
+ // update _thumbnail_id
174
+ $query = "
175
+ SELECT post_id
176
+ FROM " . $table . " a
177
+ WHERE a.meta_key IN ('fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
178
+ AND a.meta_value IS NOT NULL
179
+ AND a.meta_value <> ''";
180
+ $result = $wpdb->get_results($query);
181
+ foreach ($result as $i) {
182
+ $data = array('meta_value' => $attach_id);
183
+ $where = array('post_id' => $i->post_id, 'meta_key' => '_thumbnail_id', 'meta_value' => -1);
184
+ $wpdb->update($table, $data, $where, null, null);
185
+ }
186
+ }
187
+
188
+ function fifu_disable_fake() {
189
+ global $wpdb;
190
+ $table = $wpdb->prefix . 'postmeta';
191
+ $where = array('meta_key' => '_thumbnail_id', 'meta_value' => get_option('fifu_fake_attach_id'));
192
+ $wpdb->delete($table, $where);
193
+
194
+ wp_delete_attachment(get_option('fifu_fake_attach_id'));
195
+ delete_option('fifu_fake_attach_id');
196
+ }
admin/meta-box.php CHANGED
@@ -122,8 +122,9 @@ function fifu_save_properties($post_id) {
122
  }
123
 
124
  function fifu_update_or_delete($post_id, $field, $url) {
125
- if ($url)
126
  update_post_meta($post_id, $field, fifu_convert($url));
127
- else
 
128
  delete_post_meta($post_id, $field, $url);
129
  }
122
  }
123
 
124
  function fifu_update_or_delete($post_id, $field, $url) {
125
+ if ($url) {
126
  update_post_meta($post_id, $field, fifu_convert($url));
127
+ fifu_update_fake_attach_id($post_id);
128
+ } else
129
  delete_post_meta($post_id, $field, $url);
130
  }
featured-image-from-url.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  * Plugin Name: Featured Image From URL
5
  * 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.
6
- * Version: 1.6.7
7
  * Author: Marcel Jacques Machado
8
  * Author URI: http://featuredimagefromurl.com/
9
  */
3
  /*
4
  * Plugin Name: Featured Image From URL
5
  * 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.
6
+ * Version: 1.6.8
7
  * Author: Marcel Jacques Machado
8
  * Author URI: http://featuredimagefromurl.com/
9
  */
includes/external-post.php CHANGED
@@ -31,8 +31,10 @@ function fifu_save_properties_ext($post_id) {
31
 
32
  $url = fifu_first_url_in_content($post_id);
33
 
34
- if ($url && get_option('fifu_get_first') == 'toggleon')
35
  update_post_meta($post_id, 'fifu_image_url', fifu_convert($url));
 
 
36
  }
37
 
38
  function fifu_first_img_in_content($content) {
@@ -72,3 +74,8 @@ function fifu_first_url_in_content($post_id) {
72
  $aux2 = explode('"', $aux1[1]);
73
  return $matches && $matches[0] ? $aux2[0] : null;
74
  }
 
 
 
 
 
31
 
32
  $url = fifu_first_url_in_content($post_id);
33
 
34
+ if ($url && get_option('fifu_get_first') == 'toggleon') {
35
  update_post_meta($post_id, 'fifu_image_url', fifu_convert($url));
36
+ fifu_update_fake_attach_id($post_id);
37
+ }
38
  }
39
 
40
  function fifu_first_img_in_content($content) {
74
  $aux2 = explode('"', $aux1[1]);
75
  return $matches && $matches[0] ? $aux2[0] : null;
76
  }
77
+
78
+ function fifu_update_fake_attach_id($post_id) {
79
+ if (get_option('fifu_fake_attach_id') && !get_post_thumbnail_id($post_id))
80
+ set_post_thumbnail($post_id, get_option('fifu_fake_attach_id'));
81
+ }
readme.txt CHANGED
@@ -1,7 +1,7 @@
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, s3, picasa, woocommerce, product image, product gallery, product, gallery, column, list, page, post, all, content, custom, type, custom post type, category, video, external video, youtube, vimeo, featured video, hover, effects, hover effects, sirv, wp all import, css, style, slider, thumbnail, social, network, auto, publish, hide, first image, content, lightbox, size, grid, auto post thumbnail, link, uri, affiliate, wp, rest, api, wp rest api, lazy, load, google, drive, instagram
5
  Requires at least: 4.0
6
  Tested up to: 4.8
7
  Stable tag: 4.8
@@ -302,7 +302,10 @@ was removed. To finish, a Premium version is now been presented.
302
  * Support to Google Drive images.
303
 
304
  = 1.6.7 =
305
- * Support to Instagram images
 
 
 
306
 
307
  == Upgrade Notice ==
308
 
@@ -462,3 +465,6 @@ was removed. To finish, a Premium version is now been presented.
462
 
463
  = 1.6.7 =
464
  * Support to Instagram images
 
 
 
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, s3, picasa, woocommerce, product image, product gallery, product, gallery, column, list, page, post, all, content, custom, type, custom post type, category, video, external video, youtube, vimeo, featured video, hover, effects, hover effects, sirv, wp all import, css, style, slider, thumbnail, social, network, auto, publish, hide, first image, content, lightbox, size, grid, auto post thumbnail, link, uri, affiliate, wp, rest, api, wp rest api, lazy, load, google, drive, instagram, validation, jetpack, visual composer
5
  Requires at least: 4.0
6
  Tested up to: 4.8
7
  Stable tag: 4.8
302
  * Support to Google Drive images.
303
 
304
  = 1.6.7 =
305
+ * Support to Instagram images.
306
+
307
+ = 1.6.8 =
308
+ * Image validation and fake internal featured image.
309
 
310
  == Upgrade Notice ==
311
 
465
 
466
  = 1.6.7 =
467
  * Support to Instagram images
468
+
469
+ = 1.6.8 =
470
+ * Image validation and fake internal featured image.