Featured Image From URL - Version 2.1.4

Version Description

  • Improvement: now FIFU can generate/remove all the fake internal featured images in a few seconds, even if you have thousands of products/posts.
Download this release

Release Info

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

Code changes from version 2.1.3 to 2.1.4

admin/html/js/menu.js CHANGED
@@ -55,11 +55,3 @@ jQuery(function () {
55
  jQuery("#dialog").dialog("open");
56
  });
57
  });
58
-
59
- jQuery(document).ready(function () {
60
- jQuery("#select_fake2").val("<?php echo $enable_fake2; ?>");
61
- jQuery("#select_fake2").change(function () {
62
- jQuery("#fifu_input_fake2").val(jQuery("#select_fake2").val());
63
- jQuery("#fifu_form_fake2").submit();
64
- });
65
- });
55
  jQuery("#dialog").dialog("open");
56
  });
57
  });
 
 
 
 
 
 
 
 
admin/html/menu.html CHANGED
@@ -332,10 +332,10 @@
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>
@@ -345,19 +345,20 @@
345
  action="javascript:void(0)"
346
  method="post">
347
  <td>
348
-
349
- <select id="select_fake2" style="width:90%">
350
- <option value="toggleon">ON</option>
351
- <option value="toggleoff">OFF</option>
352
- <option value=null>STOP</option>
353
- </select>
354
-
 
 
355
  <input
356
  type="hidden"
357
  id="fifu_input_fake2"
358
  name="fifu_input_fake2"
359
- value="<?php echo $enable_fake2; ?>" >
360
-
361
  </td>
362
  <td>
363
  create a different fake image for each URL
@@ -366,7 +367,7 @@
366
  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.
367
  </td>
368
  <td>
369
- 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>.
370
  </td>
371
  </form>
372
  </tr></table>
332
  create one fake image for all URLs
333
  </td>
334
  <td>
335
+ you can keep your real internal featured image.
336
  </td>
337
  <td>
338
+ the site may have some problems to show the external images in some areas or in determined sizes.
339
  </td>
340
  </form>
341
  </tr>
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
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.
371
  </td>
372
  </form>
373
  </tr></table>
admin/html/meta-box.html CHANGED
@@ -52,7 +52,7 @@
52
  <br>
53
  <hr>
54
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid rgb(0, 115, 170); color: black;
55
- background-color: #eee; border-radius: 25px 5px;">FIFU 2 was released this week with a lot of internal changes to overcome some old known issues</p>
56
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid red; color: black;
57
  background-color: #eee; border-radius: 25px 5px;">Please report any problem to <a href="mailto:marcel@featuredimagefromurl.com">marcel@featuredimagefromurl.com</a></p>
58
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
52
  <br>
53
  <hr>
54
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid rgb(0, 115, 170); color: black;
55
+ background-color: #eee; border-radius: 25px 5px;">FIFU 2 was released this month with a lot of internal changes to overcome some old known issues</p>
56
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid red; color: black;
57
  background-color: #eee; border-radius: 25px 5px;">Please report any problem to <a href="mailto:marcel@featuredimagefromurl.com">marcel@featuredimagefromurl.com</a></p>
58
  <p style="font-size: 12px; padding: 5px; border-left: 6px solid orange; color: black;
admin/menu.php CHANGED
@@ -170,57 +170,59 @@ function fifu_enable_fake2() {
170
 
171
  global $wpdb;
172
 
173
- $table = $wpdb->prefix . 'postmeta';
 
174
  $query = "
175
- SELECT DISTINCT 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
- AND NOT EXISTS (
181
- SELECT 1
182
- FROM " . $table . " c
183
- WHERE a.post_id = c.post_id
184
- AND c.meta_key = '_thumbnail_id'
185
  )";
186
  $result = $wpdb->get_results($query);
187
-
188
- $query = "SELECT option_value FROM " . $wpdb->prefix . 'options' . " WHERE option_name = 'fifu_fake2'";
 
189
  foreach ($result as $i) {
190
- if ($wpdb->get_results($query)[0]->option_value != 'toggleon')
191
- return;
192
  $alt = get_post_meta($i->post_id, 'fifu_image_alt', true);
193
- // create attachment
194
  $filename = ';' . fifu_main_image_url($i->post_id);
195
  $parent_post_id = $i->post_id;
196
- $filetype = wp_check_filetype('fifu.png', null);
197
- $attachment = array(
198
- 'guid' => fifu_main_image_url($i->post_id),
199
- 'post_mime_type' => $filetype['type'],
200
- 'post_author' => 77777,
201
- 'post_title' => $alt,
202
- 'post_excerpt' => '',
203
- 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
204
- '(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.',
205
- 'post_status' => 'inherit'
206
- );
207
- $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
208
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
209
- $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
210
- wp_update_attachment_metadata($attach_id, $attach_data);
211
-
212
- // create _thumbnail_id
213
- $data = array('post_id' => $i->post_id, 'meta_key' => '_thumbnail_id', 'meta_value' => $attach_id);
214
- $wpdb->insert($table, $data);
215
 
216
- update_post_meta($attach_id, '_wp_attachment_image_alt', $alt);
 
 
 
 
 
 
 
 
 
 
217
  }
 
 
 
 
 
 
 
 
 
 
218
  fifu_enable_fake_ctgr();
219
  }
220
 
221
  function fifu_enable_fake_ctgr() {
222
  global $wpdb;
223
 
 
 
224
  $table_termmeta = $wpdb->prefix . 'termmeta';
225
  $query = "
226
  SELECT DISTINCT term_id
@@ -236,144 +238,104 @@ function fifu_enable_fake_ctgr() {
236
  AND c.meta_value <> 0
237
  )";
238
  $result = $wpdb->get_results($query);
 
 
 
239
  foreach ($result as $i) {
240
  $alt = get_term_meta($i->term_id, 'fifu_image_alt', true);
241
  $url = get_term_meta($i->term_id, 'fifu_image_url', true);
242
- // create attachment
243
  $filename = ';' . $url;
244
- $parent_post_id = 0;
245
- $filetype = wp_check_filetype('fifu.png', null);
246
- $attachment = array(
247
- 'guid' => $url,
248
- 'post_mime_type' => $filetype['type'],
249
- 'post_author' => 77777,
250
- 'post_title' => $alt,
251
- 'post_excerpt' => '',
252
- 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
253
- '(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.',
254
- 'post_status' => 'inherit'
255
- );
256
- $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
257
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
258
- $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
259
- wp_update_attachment_metadata($attach_id, $attach_data);
260
-
261
- // create thumbnail_id
262
- update_term_meta($i->term_id, 'thumbnail_id', $attach_id);
263
-
264
- update_post_meta($attach_id, '_wp_attachment_image_alt', $alt);
265
  }
 
 
 
 
 
 
 
 
 
266
  }
267
 
268
  function fifu_disable_fake2() {
 
269
  if (!get_option('fifu_fake_created') && get_option('fifu_fake_created') != null)
270
  return;
271
  update_option('fifu_fake_created', false);
272
 
 
273
  global $wpdb;
274
-
275
- $table = $wpdb->prefix . 'postmeta';
276
  $table_posts = $wpdb->prefix . 'posts';
277
  $table_termmeta = $wpdb->prefix . 'termmeta';
278
 
279
- // delete attachment created by fifu
280
- $query = "SELECT id FROM " . $table_posts . " WHERE post_type = 'attachment' AND post_content LIKE 'Please don%'";
281
- $result = $wpdb->get_results($query);
282
-
283
- $query = "SELECT option_value FROM " . $wpdb->prefix . 'options' . " WHERE option_name = 'fifu_fake2'";
284
- foreach ($result as $i) {
285
- if ($wpdb->get_results($query)[0]->option_value != 'toggleoff')
286
- return;
287
- $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $i->id);
288
- $wpdb->delete($table, $where);
289
-
290
- $where = array('meta_key' => 'thumbnail_id', 'meta_value' => $i->id);
291
- $wpdb->delete($table_termmeta, $where);
292
-
293
- wp_delete_attachment($i->id);
294
  }
295
 
296
  // delete meta values
297
- $query = "SELECT post_id FROM " . $table . " WHERE meta_key = 'fifu_image_url'";
298
- $result = $wpdb->get_results($query);
299
- foreach ($result as $i) {
300
- $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => -1);
301
- $wpdb->delete($table, $where);
302
-
303
- $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => null);
304
- $wpdb->delete($table, $where);
305
-
306
- $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => 'fifu:' . $i->post_id);
307
- $wpdb->delete($table, $where);
308
-
309
- $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id, 'meta_value' => get_option('fifu_fake_attach_id'));
310
- $wpdb->delete($table, $where);
311
-
312
- $where = array('meta_key' => '_wp_attached_file', 'post_id' => $i->post_id, 'meta_value' => 'Featured Image from URL');
313
- $wpdb->delete($table, $where);
314
-
315
- // delete _thumbnail_id withouth attachment
316
- $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)";
317
- $result = $wpdb->get_results($query);
318
- foreach ($result as $x) {
319
- $where = array('meta_key' => '_thumbnail_id', 'post_id' => $i->post_id);
320
- $wpdb->delete($table, $where);
321
- }
322
  }
 
 
323
 
324
- // delete attachments
325
- $query = "SELECT post_id FROM " . $table . " WHERE meta_key = '_wp_attached_file' AND meta_value = 'Featured Image from URL'";
326
- $result = $wpdb->get_results($query);
327
- foreach ($result as $i) {
328
- $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $i->post_id);
329
- $wpdb->delete($table, $where);
330
- wp_delete_attachment($i->post_id);
331
- }
332
  fifu_disable_fake_ctgr();
333
- delete_option('fifu_fake_attach_id');
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() {
@@ -392,8 +354,7 @@ function fifu_enable_fake() {
392
  'post_mime_type' => $filetype['type'],
393
  'post_title' => '',
394
  'post_excerpt' => '',
395
- 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file that keeps the field filled ' .
396
- '(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.',
397
  'post_status' => 'inherit'
398
  );
399
  $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
170
 
171
  global $wpdb;
172
 
173
+ $table_postmeta = $wpdb->prefix . 'postmeta';
174
+ $table_posts = $wpdb->prefix . 'posts';
175
  $query = "
176
+ SELECT DISTINCT post_id
177
+ FROM " . $table_postmeta . " a
178
+ WHERE a.meta_key IN ('fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
179
+ AND a.meta_value IS NOT NULL
180
+ AND a.meta_value <> ''
181
+ AND NOT EXISTS (
182
+ SELECT 1
183
+ FROM " . $table_postmeta . " c
184
+ WHERE a.post_id = c.post_id
185
+ AND c.meta_key = '_thumbnail_id'
186
  )";
187
  $result = $wpdb->get_results($query);
188
+ $value = null;
189
+ $count = 1;
190
+ $insert = "INSERT INTO " . $table_posts . " (post_author, guid, post_title, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_excerpt, to_ping, pinged, post_content_filtered) VALUES ";
191
  foreach ($result as $i) {
 
 
192
  $alt = get_post_meta($i->post_id, 'fifu_image_alt', true);
 
193
  $filename = ';' . fifu_main_image_url($i->post_id);
194
  $parent_post_id = $i->post_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
+ $aux = "(77777, '" . fifu_main_image_url($i->post_id) . "', '" . $alt . "', 'image/jpeg', 'attachment', 'inherit', '" . $parent_post_id . "', now(), now(), now(), now(), '', '', '', '', '')";
197
+ $value = ($count == 1) ? $aux : ($value . "," . $aux);
198
+
199
+ if ($count % 100 == 0 && $value) {
200
+ // create attachment
201
+ $wpdb->get_results($insert . " " . $value);
202
+ $value = null;
203
+ $count = 1;
204
+ } else {
205
+ $count++;
206
+ }
207
  }
208
+ if ($count != 100 && $value)
209
+ $wpdb->get_results($insert . " " . $value);
210
+
211
+ // create _thumbnail_id
212
+ $wpdb->get_results("INSERT INTO " . $table_postmeta . " (post_id, meta_key, meta_value) (SELECT post_parent AS post_id, '_thumbnail_id' AS meta_key, id AS meta_value FROM " . $table_posts . " WHERE post_author = 77777)");
213
+ // create _wp_attached_file
214
+ $wpdb->get_results("INSERT INTO " . $table_postmeta . " (post_id, meta_key, meta_value) (SELECT id AS post_id, '_wp_attached_file' AS meta_key, CONCAT(';', guid) AS meta_value FROM " . $table_posts . " WHERE post_author = 77777)");
215
+ // create _wp_attachment_image_alt
216
+ $wpdb->get_results("INSERT INTO " . $table_postmeta . " (post_id, meta_key, meta_value) (SELECT id AS post_id, '_wp_attachment_image_alt' AS meta_key, post_title AS meta_value FROM " . $table_posts . " WHERE post_author = 77777)");
217
+
218
  fifu_enable_fake_ctgr();
219
  }
220
 
221
  function fifu_enable_fake_ctgr() {
222
  global $wpdb;
223
 
224
+ $table_postmeta = $wpdb->prefix . 'postmeta';
225
+ $table_posts = $wpdb->prefix . 'posts';
226
  $table_termmeta = $wpdb->prefix . 'termmeta';
227
  $query = "
228
  SELECT DISTINCT term_id
238
  AND c.meta_value <> 0
239
  )";
240
  $result = $wpdb->get_results($query);
241
+ $value = null;
242
+ $count = 1;
243
+ $insert = "INSERT INTO " . $table_posts . " (post_author, guid, post_title, post_mime_type, post_type, post_status, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_excerpt, to_ping, pinged, post_content_filtered) VALUES ";
244
  foreach ($result as $i) {
245
  $alt = get_term_meta($i->term_id, 'fifu_image_alt', true);
246
  $url = get_term_meta($i->term_id, 'fifu_image_url', true);
 
247
  $filename = ';' . $url;
248
+ $parent_post_id = $i->term_id;
249
+
250
+ $aux = "(77777, '" . $url . "', '" . $alt . "', 'image/jpeg', 'attachment', 'inherit', '" . $parent_post_id . "', now(), now(), now(), now(), '', '', '', '', '')";
251
+ $value = ($count == 1) ? $aux : ($value . "," . $aux);
252
+
253
+ if ($count % 100 == 0 && $value) {
254
+ // create attachment
255
+ $wpdb->get_results($insert . " " . $value);
256
+ $value = null;
257
+ $count = 1;
258
+ } else {
259
+ $count++;
260
+ }
 
 
 
 
 
 
 
 
261
  }
262
+ if ($count != 100 && $value)
263
+ $wpdb->get_results($insert . " " . $value);
264
+
265
+ // create thumbnail_id
266
+ $wpdb->get_results("INSERT INTO " . $table_termmeta . " (term_id, meta_key, meta_value) (SELECT post_parent AS term_id, 'thumbnail_id' AS meta_key, id AS meta_value FROM " . $table_posts . " WHERE post_author = 77777)");
267
+ // create _wp_attached_file
268
+ $wpdb->get_results("INSERT INTO " . $table_postmeta . " (post_id, meta_key, meta_value) (SELECT id AS post_id, '_wp_attached_file' AS meta_key, CONCAT(';', guid) AS meta_value FROM " . $table_posts . " p1 WHERE post_author = 77777 AND NOT EXISTS (SELECT 1 FROM " . $table_postmeta . " p2 WHERE p1.id = p2.post_id AND p2.meta_key = '_wp_attached_file'))");
269
+ // create _wp_attachment_image_alt
270
+ $wpdb->get_results("INSERT INTO " . $table_postmeta . " (post_id, meta_key, meta_value) (SELECT id AS post_id, '_wp_attachment_image_alt' AS meta_key, post_title AS meta_value FROM " . $table_posts . " p1 WHERE post_author = 77777 AND NOT EXISTS (SELECT 1 FROM " . $table_postmeta . " p2 WHERE p1.id = p2.post_id AND p2.meta_key = '_wp_attachment_image_alt'))");
271
  }
272
 
273
  function fifu_disable_fake2() {
274
+ // check toggle
275
  if (!get_option('fifu_fake_created') && get_option('fifu_fake_created') != null)
276
  return;
277
  update_option('fifu_fake_created', false);
278
 
279
+ // tables
280
  global $wpdb;
281
+ $table_postmeta = $wpdb->prefix . 'postmeta';
 
282
  $table_posts = $wpdb->prefix . 'posts';
283
  $table_termmeta = $wpdb->prefix . 'termmeta';
284
 
285
+ $result = $wpdb->get_results("SELECT id FROM " . $table_posts . " WHERE post_type = 'attachment' AND post_author = '77777'");
286
+ $value = null;
287
+ $count = 1;
288
+ foreach ($result as $i)
289
+ $value = ($count++ == 1) ? $i->id : ($value . "," . $i->id);
290
+ if ($value) {
291
+ // delete _thumbnail_id
292
+ $wpdb->get_results("DELETE FROM " . $table_postmeta . " WHERE meta_key = '_thumbnail_id' AND meta_value IN (" . $value . ")");
293
+ // delete attachments
294
+ $wpdb->get_results("DELETE FROM " . $table_posts . " WHERE id IN (" . $value . ")");
 
 
 
 
 
295
  }
296
 
297
  // delete meta values
298
+ $result = $wpdb->get_results("SELECT post_id FROM " . $table_postmeta . " WHERE meta_key = 'fifu_image_url'");
299
+ $value = null;
300
+ $count = 1;
301
+ foreach ($result as $i)
302
+ $value = ($count++ == 1) ? $i->post_id : ($value . "," . $i->post_id);
303
+ if ($value) {
304
+ // delete _thumbnail_id
305
+ $wpdb->get_results("DELETE FROM " . $table_postmeta . " WHERE meta_key = '_thumbnail_id' AND post_id IN (" . $value . ") AND (meta_value = -1 OR meta_value IS NULL OR meta_value LIKE 'fifu:%')");
306
+ if (get_option('fifu_fake_attach_id'))
307
+ $wpdb->get_results("DELETE FROM " . $table_postmeta . " WHERE meta_key = '_thumbnail_id' AND post_id IN (" . $value . ") AND meta_value = " . get_option('fifu_fake_attach_id'));
308
+ // delete fake _wp_attached_file
309
+ $wpdb->get_results("DELETE FROM " . $table_postmeta . " WHERE meta_key = '_wp_attached_file' AND post_id IN (" . $value . ")");
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  }
311
+ // delete _thumbnail_id withouth attachment
312
+ $wpdb->get_results("DELETE FROM " . $table_postmeta . " WHERE meta_key = '_thumbnail_id' AND NOT EXISTS (SELECT 1 FROM " . $table_posts . " p WHERE p.id = meta_value)");
313
 
 
 
 
 
 
 
 
 
314
  fifu_disable_fake_ctgr();
 
315
  }
316
 
317
  function fifu_disable_fake_ctgr() {
318
  global $wpdb;
319
+ $table_postmeta = $wpdb->prefix . 'postmeta';
 
320
  $table_posts = $wpdb->prefix . 'posts';
321
  $table_termmeta = $wpdb->prefix . 'termmeta';
322
 
323
  // delete meta values
324
+ $result = $wpdb->get_results("SELECT term_id FROM " . $table_termmeta . " WHERE meta_key = 'fifu_image_url'");
325
+ $value = null;
326
+ $count = 1;
327
+ foreach ($result as $i)
328
+ $value = ($count++ == 1) ? $i->term_id : ($value . "," . $i->term_id);
329
+ if ($value) {
330
+ // delete _thumbnail_id
331
+ $wpdb->get_results("DELETE FROM " . $table_termmeta . " WHERE meta_key = 'thumbnail_id' AND term_id IN (" . $value . ") AND (meta_value IN (0, -1) OR meta_value IS NULL OR meta_value LIKE 'fifu:%')");
332
+ if (get_option('fifu_fake_attach_id'))
333
+ $wpdb->get_results("DELETE FROM " . $table_termmeta . " WHERE meta_key = 'thumbnail_id' AND term_id IN (" . $value . ") AND meta_value = " . get_option('fifu_fake_attach_id'));
334
+ // delete fake _wp_attached_file
335
+ $wpdb->get_results("DELETE FROM " . $table_postmeta . " WHERE meta_key = '_wp_attached_file' AND post_id IN (" . $value . ")");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  }
337
+ // delete _thumbnail_id withouth attachment
338
+ $wpdb->get_results("DELETE FROM " . $table_termmeta . " WHERE meta_key = 'thumbnail_id' AND NOT EXISTS (SELECT 1 FROM " . $table_posts . " p WHERE p.id = meta_value)");
339
  }
340
 
341
  function fifu_enable_fake() {
354
  'post_mime_type' => $filetype['type'],
355
  'post_title' => '',
356
  'post_excerpt' => '',
357
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file',
 
358
  'post_status' => 'inherit'
359
  );
360
  $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
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: 2.1.3
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
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.1.4
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
includes/external-post.php CHANGED
@@ -139,8 +139,7 @@ function fifu_update_fake_attach_id($post_id) {
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);
@@ -199,8 +198,7 @@ function fifu_ctgr_update_fake_attach_id($term_id) {
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);
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',
 
143
  'post_status' => 'inherit'
144
  );
145
  $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
198
  'post_author' => $AUTHOR,
199
  'post_title' => $alt,
200
  'post_excerpt' => '',
201
+ 'post_content' => 'Please don\'t remove that. It\'s just an empty symbolic file',
 
202
  'post_status' => 'inherit'
203
  );
204
  $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
readme.txt CHANGED
@@ -161,6 +161,9 @@ Features:
161
 
162
  == Changelog ==
163
 
 
 
 
164
  = 2.1.3 =
165
  * Bug fixes: parse error, featured image not shown on WooCommerce column.
166
 
@@ -470,6 +473,9 @@ was removed. To finish, a Premium version is now been presented.
470
 
471
  == Upgrade Notice ==
472
 
 
 
 
473
  = 2.1.3 =
474
  * Bug fixes: parse error, featured image not shown on WooCommerce column.
475
 
161
 
162
  == Changelog ==
163
 
164
+ = 2.1.4 =
165
+ * Improvement: now FIFU can generate/remove all the fake internal featured images in a few seconds, even if you have thousands of products/posts.
166
+
167
  = 2.1.3 =
168
  * Bug fixes: parse error, featured image not shown on WooCommerce column.
169
 
473
 
474
  == Upgrade Notice ==
475
 
476
+ = 2.1.4 =
477
+ * Improvement: now FIFU can generate/remove all the fake internal featured images in a few seconds, even if you have thousands of products/posts.
478
+
479
  = 2.1.3 =
480
  * Bug fixes: parse error, featured image not shown on WooCommerce column.
481