Featured Image From URL - Version 2.1.6

Version Description

  • Bug fixes: product category; clean meta data; style issues.
Download this release

Release Info

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

Code changes from version 2.1.5 to 2.1.6

admin/category.php CHANGED
@@ -34,6 +34,7 @@ function fifu_ctgr_add_box() {
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 = '';
34
  $width = 'width:100%;';
35
  $height = 'height:200px;';
36
  $align = 'text-align:left;';
37
+ $show_news = 'display:none';
38
  $is_sirv_active = is_plugin_active('sirv/sirv.php');
39
 
40
  $show_button = $show_sirv = $url = $alt = '';
admin/db.php ADDED
@@ -0,0 +1,405 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FifuDb {
4
+
5
+ private $posts;
6
+ private $postmeta;
7
+ private $termmeta;
8
+ private $term_taxonomy;
9
+ private $term_relationships;
10
+ private $query;
11
+ private $wpdb;
12
+ private $author;
13
+
14
+ function __construct() {
15
+ global $wpdb;
16
+ $this->wpdb = $wpdb;
17
+ $this->posts = $wpdb->prefix . 'posts';
18
+ $this->postmeta = $wpdb->prefix . 'postmeta';
19
+ $this->termmeta = $wpdb->prefix . 'termmeta';
20
+ $this->term_taxonomy = $wpdb->prefix . 'term_taxonomy';
21
+ $this->term_relationships = $wpdb->prefix . 'term_relationships';
22
+ $this->author = 77777;
23
+ $this->MAX_INSERT = 100;
24
+ }
25
+
26
+ /* attachment meta data */
27
+
28
+ // insert 1 _wp_attached_file for each attachment
29
+ function insert_attachment_meta_url($ids) {
30
+ $this->wpdb->get_results("
31
+ INSERT INTO " . $this->postmeta . " (post_id, meta_key, meta_value) (
32
+ SELECT p.id, '_wp_attached_file', CONCAT(';', p.guid)
33
+ FROM " . $this->posts . " p
34
+ WHERE p.post_parent IN (" . $ids . ")
35
+ AND p.post_type = 'attachment'
36
+ AND p.post_author = " . $this->author . "
37
+ AND NOT EXISTS (
38
+ SELECT 1
39
+ FROM " . $this->postmeta . "
40
+ WHERE post_id = p.post_parent
41
+ AND meta_key = '_wp_attached_file'
42
+ )
43
+ )"
44
+ );
45
+ }
46
+
47
+ // delete 1 _wp_attached_file or _wp_attachment_image_alt for each attachment
48
+ function delete_attachment_meta($ids) {
49
+ $this->wpdb->get_results("
50
+ DELETE FROM " . $this->postmeta . "
51
+ WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_image_alt')
52
+ AND EXISTS (
53
+ SELECT 1
54
+ FROM " . $this->posts . " p
55
+ WHERE p.id = post_id
56
+ AND p.post_parent IN (" . $ids . ")
57
+ AND p.post_type = 'attachment'
58
+ AND p.post_author = " . $this->author . "
59
+ )"
60
+ );
61
+ }
62
+
63
+ // insert 1 _wp_attachment_image_alt for each attachment
64
+ function insert_attachment_meta_alt($ids) {
65
+ $this->wpdb->get_results("
66
+ INSERT INTO " . $this->postmeta . " (post_id, meta_key, meta_value) (
67
+ SELECT p.id, '_wp_attachment_image_alt', p.post_title
68
+ FROM " . $this->posts . " p
69
+ WHERE p.post_parent IN (" . $ids . ")
70
+ AND p.post_type = 'attachment'
71
+ AND p.post_author = " . $this->author . "
72
+ AND NOT EXISTS (
73
+ SELECT 1
74
+ FROM " . $this->postmeta . "
75
+ WHERE post_id = p.post_parent
76
+ AND meta_key = '_wp_attachment_image_alt'
77
+ )
78
+ )"
79
+ );
80
+ }
81
+
82
+ // insert 1 _thumbnail_id for each attachment (posts)
83
+ function insert_thumbnail_id($ids) {
84
+ $this->wpdb->get_results("
85
+ INSERT INTO " . $this->postmeta . " (post_id, meta_key, meta_value) (
86
+ SELECT p.post_parent, '_thumbnail_id', p.id
87
+ FROM " . $this->posts . " p
88
+ WHERE p.post_parent IN (" . $ids . ")
89
+ AND p.post_type = 'attachment'
90
+ AND p.post_author = " . $this->author . "
91
+ AND NOT EXISTS (
92
+ SELECT 1
93
+ FROM " . $this->postmeta . "
94
+ WHERE post_id = p.post_parent
95
+ AND meta_key = '_thumbnail_id'
96
+ )
97
+ )"
98
+ );
99
+ }
100
+
101
+ // get ids from categories with external media and no thumbnail_id
102
+ function get_categories_without_meta() {
103
+ return $this->wpdb->get_results("
104
+ SELECT DISTINCT term_id
105
+ FROM " . $this->termmeta . " a
106
+ WHERE a.meta_key IN ('fifu_image_url')
107
+ AND a.meta_value IS NOT NULL
108
+ AND a.meta_value <> ''
109
+ AND NOT EXISTS (
110
+ SELECT 1
111
+ FROM " . $this->termmeta . " b
112
+ WHERE a.term_id = b.term_id
113
+ AND b.meta_key = 'thumbnail_id'
114
+ AND b.meta_value <> 0
115
+ )"
116
+ );
117
+ }
118
+
119
+ // get ids from posts with external media and no _thumbnail_id
120
+ function get_posts_without_meta() {
121
+ return $this->wpdb->get_results("
122
+ SELECT DISTINCT post_id
123
+ FROM " . $this->postmeta . " a
124
+ WHERE a.meta_key IN ('fifu_image_url')
125
+ AND a.meta_value IS NOT NULL
126
+ AND a.meta_value <> ''
127
+ AND NOT EXISTS (
128
+ SELECT 1
129
+ FROM " . $this->postmeta . " b
130
+ WHERE a.post_id = b.post_id
131
+ AND b.meta_key = '_thumbnail_id'
132
+ )"
133
+ );
134
+ }
135
+
136
+ // get ids from posts with external url
137
+ function get_posts_with_url() {
138
+ return $this->wpdb->get_results("
139
+ SELECT post_id
140
+ FROM " . $this->postmeta . "
141
+ WHERE meta_key = 'fifu_image_url'"
142
+ );
143
+ }
144
+
145
+ // get ids from terms with external url
146
+ function get_terms_with_url() {
147
+ return $this->wpdb->get_results("
148
+ SELECT term_id
149
+ FROM " . $this->termmeta . "
150
+ WHERE meta_key = 'fifu_image_url'"
151
+ );
152
+ }
153
+
154
+ // get ids from fake attachments
155
+ function get_fake_attachments() {
156
+ return $this->wpdb->get_results("
157
+ SELECT id
158
+ FROM " . $this->posts . "
159
+ WHERE post_type = 'attachment'
160
+ AND post_author = " . $this->author
161
+ );
162
+ }
163
+
164
+ // clean meta data
165
+
166
+ function delete_thumbnail_ids($ids) {
167
+ $this->wpdb->get_results("
168
+ DELETE FROM " . $this->postmeta . "
169
+ WHERE meta_key = '_thumbnail_id'
170
+ AND meta_value IN (" . $ids . ")"
171
+ );
172
+ }
173
+
174
+ function delete_thumbnail_ids_category($ids) {
175
+ $this->wpdb->get_results("
176
+ DELETE FROM " . $this->termmeta . "
177
+ WHERE meta_key = 'thumbnail_id'
178
+ AND term_id IN (" . $ids . ")"
179
+ );
180
+ }
181
+
182
+ function delete_thumbnail_ids_category_without_attachment() {
183
+ $this->wpdb->get_results("
184
+ DELETE FROM " . $this->termmeta . "
185
+ WHERE meta_key = 'thumbnail_id'
186
+ AND NOT EXISTS (
187
+ SELECT 1
188
+ FROM " . $this->posts . " p
189
+ WHERE p.id = meta_value
190
+ )"
191
+ );
192
+ }
193
+
194
+ function delete_invalid_thumbnail_ids($ids) {
195
+ $this->wpdb->get_results("
196
+ DELETE FROM " . $this->postmeta . "
197
+ WHERE meta_key = '_thumbnail_id'
198
+ AND post_id IN (" . $ids . ")
199
+ AND (
200
+ meta_value = -1
201
+ OR meta_value IS NULL
202
+ OR meta_value LIKE 'fifu:%'
203
+ )"
204
+ );
205
+ }
206
+
207
+ function delete_fake_thumbnail_id($ids) {
208
+ $att_id = get_option('fifu_fake_attach_id');
209
+ if ($att_id) {
210
+ $this->wpdb->get_results("
211
+ DELETE FROM " . $this->postmeta . "
212
+ WHERE meta_key = '_thumbnail_id'
213
+ AND post_id IN (" . $ids . ")
214
+ AND meta_value = " . $att_id
215
+ );
216
+ }
217
+ }
218
+
219
+ function delete_attachments($ids) {
220
+ $this->wpdb->get_results("
221
+ DELETE FROM " . $this->posts . "
222
+ WHERE id IN (" . $ids . ")"
223
+ );
224
+ }
225
+
226
+ function delete_attachment_meta_url($ids) {
227
+ $this->wpdb->get_results("
228
+ DELETE FROM " . $this->postmeta . "
229
+ WHERE meta_key = '_wp_attached_file'
230
+ AND post_id IN (" . $ids . ")"
231
+ );
232
+ }
233
+
234
+ function delete_thumbnail_id_without_attachment() {
235
+ $this->wpdb->get_results("
236
+ DELETE FROM " . $this->postmeta . "
237
+ WHERE meta_key = '_thumbnail_id'
238
+ AND NOT EXISTS (
239
+ SELECT 1
240
+ FROM " . $this->posts . " p
241
+ WHERE p.id = meta_value
242
+ )"
243
+ );
244
+ }
245
+
246
+ function delete_attachment_meta_without_attachment() {
247
+ $this->wpdb->get_results("
248
+ DELETE FROM " . $this->postmeta . "
249
+ WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_image_alt')
250
+ AND NOT EXISTS (
251
+ SELECT 1
252
+ FROM " . $this->posts . " p
253
+ WHERE p.id = post_id
254
+ )"
255
+ );
256
+ }
257
+
258
+ function delete_empty_urls_category() {
259
+ $this->wpdb->get_results("
260
+ DELETE FROM " . $this->termmeta . "
261
+ WHERE meta_key = 'fifu_image_url'
262
+ AND (
263
+ meta_value = ''
264
+ OR meta_value is NULL
265
+ )"
266
+ );
267
+ }
268
+
269
+ function delete_empty_urls() {
270
+ $this->wpdb->get_results("
271
+ DELETE FROM " . $this->postmeta . "
272
+ WHERE meta_key = 'fifu_image_url'
273
+ AND (
274
+ meta_value = ''
275
+ OR meta_value is NULL
276
+ )"
277
+ );
278
+ }
279
+
280
+ /* insert attachment */
281
+
282
+ function insert_attachment_by($value) {
283
+ $this->wpdb->get_results("
284
+ INSERT INTO " . $this->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)
285
+ VALUES " . $value);
286
+ }
287
+
288
+ function get_formatted_value($url, $alt, $post_parent) {
289
+ return "(" . $this->author . ", '" . $url . "', '" . $alt . "', 'image/jpeg', 'attachment', 'inherit', '" . $post_parent . "', now(), now(), now(), now(), '', '', '', '', '')";
290
+ }
291
+
292
+ /* insert fake internal featured image */
293
+
294
+ function insert_attachment_category() {
295
+ $ids = null;
296
+ $value = null;
297
+ $i = 0;
298
+ // insert 1 attachment for each selected category
299
+ foreach ($this->get_categories_without_meta() as $res) {
300
+ $ids = ($i++ == 0) ? $res->term_id : ($ids . "," . $res->term_id);
301
+ $url = get_term_meta($res->term_id, 'fifu_image_url', true);
302
+ $value = $this->get_formatted_value($url, get_term_meta($res->term_id, 'fifu_image_alt', true), $res->term_id);
303
+ $this->insert_attachment_by($value);
304
+ $att_id = $this->wpdb->insert_id;
305
+ update_term_meta($res->term_id, 'thumbnail_id', $att_id);
306
+ }
307
+ if ($ids) {
308
+ $this->insert_attachment_meta_url($ids);
309
+ $this->insert_attachment_meta_alt($ids);
310
+ }
311
+ }
312
+
313
+ function insert_attachment() {
314
+ $ids = null;
315
+ $value = null;
316
+ $i = 1;
317
+ $count = 1;
318
+ // insert 1 attachment for each selected post
319
+ $result = $this->get_posts_without_meta();
320
+ foreach ($result as $res) {
321
+ $ids = ($i == 1) ? $res->post_id : ($ids . "," . $res->post_id);
322
+ $aux = $this->get_formatted_value(fifu_main_image_url($res->post_id), get_post_meta($res->post_id, 'fifu_image_alt', true), $res->post_id);
323
+ $value = ($i == 1) ? $aux : ($value . "," . $aux);
324
+ if ($value && (($i % $this->MAX_INSERT == 0) || ($i % $this->MAX_INSERT != 0 && count($result) == $count))) {
325
+ $this->insert_attachment_by($value);
326
+ $this->insert_thumbnail_id($ids);
327
+ $this->insert_attachment_meta_url($ids);
328
+ $this->insert_attachment_meta_alt($ids);
329
+ $ids = null;
330
+ $value = null;
331
+ $i = 1;
332
+ } else
333
+ $i++;
334
+ $count++;
335
+ }
336
+ }
337
+
338
+ /* delete fake internal featured image */
339
+
340
+ function delete_attachment() {
341
+ $ids = null;
342
+ $i = 0;
343
+ // delete fake attachments and _thumbnail_ids
344
+ foreach ($this->get_fake_attachments() as $res)
345
+ $ids = ($i++ == 0) ? $res->id : ($ids . "," . $res->id);
346
+ if ($ids) {
347
+ $this->delete_thumbnail_ids($ids);
348
+ $this->delete_attachments($ids);
349
+ }
350
+
351
+ $ids = null;
352
+ $i = 0;
353
+ // delete attachment data and more _thumbnail_ids
354
+ foreach ($this->get_posts_with_url() as $res)
355
+ $ids = ($i++ == 0) ? $res->post_id : ($ids . "," . $res->post_id);
356
+ if ($ids) {
357
+ $this->delete_invalid_thumbnail_ids($ids);
358
+ $this->delete_fake_thumbnail_id($ids);
359
+ $this->delete_attachment_meta_url($ids);
360
+ }
361
+
362
+ // delete data without attachment
363
+ $this->delete_thumbnail_id_without_attachment();
364
+ $this->delete_attachment_meta_without_attachment();
365
+
366
+ $this->delete_empty_urls();
367
+ }
368
+
369
+ function delete_attachment_category() {
370
+ $ids = null;
371
+ $i = 0;
372
+ foreach ($this->get_terms_with_url() as $res)
373
+ $ids = ($i++ == 0) ? $res->term_id : ($ids . "," . $res->term_id);
374
+ if ($ids) {
375
+ $this->delete_thumbnail_ids_category($ids);
376
+ $this->delete_attachment_meta($ids);
377
+ $this->delete_thumbnail_ids_category_without_attachment();
378
+ }
379
+ $this->delete_empty_urls_category();
380
+ }
381
+
382
+ }
383
+
384
+ /* fake internal featured image */
385
+
386
+ function fifu_db_insert_attachment_category() {
387
+ $db = new FifuDb();
388
+ $db->insert_attachment_category();
389
+ }
390
+
391
+ function fifu_db_insert_attachment() {
392
+ $db = new FifuDb();
393
+ $db->insert_attachment();
394
+ }
395
+
396
+ function fifu_db_delete_attachment_category() {
397
+ $db = new FifuDb();
398
+ $db->delete_attachment_category();
399
+ }
400
+
401
+ function fifu_db_delete_attachment() {
402
+ $db = new FifuDb();
403
+ $db->delete_attachment();
404
+ }
405
+
admin/html/css/editor.css CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  .components-responsive-wrapper__content {
2
  position:relative !important;
3
  }
1
+ .components-responsive-wrapper > div {
2
+ padding-bottom: 0px !important;
3
+ }
4
+
5
  .components-responsive-wrapper__content {
6
  position:relative !important;
7
  }
admin/html/menu.html CHANGED
@@ -727,6 +727,7 @@
727
  <table style="text-align:left">
728
  <tr>
729
  <th>
 
730
  <th>
731
  Key
732
  </th>
@@ -756,11 +757,11 @@
756
  <table style="text-align:left">
757
  <tr>
758
  <th>
 
759
  <th>
760
  Key(s)
761
  </th>
762
  </tr>
763
- <tr>
764
  <tr>
765
  <th>
766
  Image
@@ -776,13 +777,14 @@
776
  <th>
777
  fifu_image_alt
778
  </th>
779
- </tr>
780
- <th>
781
- Image Gallery
782
- </th>
783
- <th>
784
- fifu_image_url_0, fifu_image_url_1, fifu_image_url_2 ...
785
- </th>
 
786
  </tr>
787
  <tr>
788
  <th>
@@ -1709,7 +1711,7 @@
1709
  <div id="tabs-2">
1710
  <table style="text-align:left">
1711
  <tr>
1712
- <th>
1713
  <th>
1714
  Key(s)
1715
  </th>
727
  <table style="text-align:left">
728
  <tr>
729
  <th>
730
+ </th>
731
  <th>
732
  Key
733
  </th>
757
  <table style="text-align:left">
758
  <tr>
759
  <th>
760
+ </th>
761
  <th>
762
  Key(s)
763
  </th>
764
  </tr>
 
765
  <tr>
766
  <th>
767
  Image
777
  <th>
778
  fifu_image_alt
779
  </th>
780
+ </tr>
781
+ <tr>
782
+ <th>
783
+ Image Gallery
784
+ </th>
785
+ <th>
786
+ fifu_image_url_0, fifu_image_url_1, fifu_image_url_2 ...
787
+ </th>
788
  </tr>
789
  <tr>
790
  <th>
1711
  <div id="tabs-2">
1712
  <table style="text-align:left">
1713
  <tr>
1714
+ <th></th>
1715
  <th>
1716
  Key(s)
1717
  </th>
admin/menu.php CHANGED
@@ -168,174 +168,17 @@ function fifu_enable_fake2() {
168
  return;
169
  update_option('fifu_fake_created', true);
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
229
- FROM " . $table_termmeta . " a
230
- WHERE a.meta_key IN ('fifu_image_url', 'fifu_video_url', 'fifu_slider_image_url_0', 'fifu_shortcode')
231
- AND a.meta_value IS NOT NULL
232
- AND a.meta_value <> ''
233
- AND NOT EXISTS (
234
- SELECT 1
235
- FROM " . $table_termmeta . " c
236
- WHERE a.term_id = c.term_id
237
- AND c.meta_key = 'thumbnail_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() {
@@ -462,6 +305,9 @@ function fifu_enable_clean() {
462
  $where = array('meta_key' => '_wp_attached_file', 'meta_value' => 'fifu.png');
463
  $wpdb->delete($table, $where);
464
 
 
 
 
465
  wp_delete_attachment(get_option('fifu_fake_attach_id'));
466
  wp_delete_attachment(get_option('fifu_default_attach_id'));
467
  delete_option('fifu_fake_attach_id');
168
  return;
169
  update_option('fifu_fake_created', true);
170
 
171
+ fifu_db_insert_attachment();
172
+ fifu_db_insert_attachment_category();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  }
174
 
175
  function fifu_disable_fake2() {
 
176
  if (!get_option('fifu_fake_created') && get_option('fifu_fake_created') != null)
177
  return;
178
  update_option('fifu_fake_created', false);
179
 
180
+ fifu_db_delete_attachment();
181
+ fifu_db_delete_attachment_category();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
 
184
  function fifu_enable_fake() {
305
  $where = array('meta_key' => '_wp_attached_file', 'meta_value' => 'fifu.png');
306
  $wpdb->delete($table, $where);
307
 
308
+ $where = array('guid' => 'http://fifu.png');
309
+ $wpdb->delete($table_posts, $where);
310
+
311
  wp_delete_attachment(get_option('fifu_fake_attach_id'));
312
  wp_delete_attachment(get_option('fifu_default_attach_id'));
313
  delete_option('fifu_fake_attach_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.5
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
@@ -26,5 +26,6 @@ if (is_admin()) {
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
 
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.6
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
26
  require_once( FIFU_ADMIN_DIR . '/column.php' );
27
  require_once( FIFU_ADMIN_DIR . '/menu.php' );
28
  }
29
+ require_once (FIFU_ADMIN_DIR . '/db.php');
30
  require_once( FIFU_ADMIN_DIR . '/meta-box.php' );
31
 
includes/external-post.php CHANGED
@@ -161,7 +161,7 @@ function fifu_ctgr_update_fake_attach_id($term_id) {
161
  $postmeta_table = $wpdb->prefix . 'postmeta';
162
  $termmeta_table = $wpdb->prefix . 'termmeta';
163
  $aux = $wpdb->get_row('SELECT meta_value FROM ' . $termmeta_table . ' WHERE term_id = ' . $term_id . ' AND meta_key = "thumbnail_id"');
164
- $att_id = $aux->meta_value;
165
 
166
  $url = get_term_meta($term_id, 'fifu_image_url', true);
167
 
161
  $postmeta_table = $wpdb->prefix . 'postmeta';
162
  $termmeta_table = $wpdb->prefix . 'termmeta';
163
  $aux = $wpdb->get_row('SELECT meta_value FROM ' . $termmeta_table . ' WHERE term_id = ' . $term_id . ' AND meta_key = "thumbnail_id"');
164
+ $att_id = $aux ? $aux->meta_value : null;
165
 
166
  $url = get_term_meta($term_id, 'fifu_image_url', true);
167
 
readme.txt CHANGED
@@ -161,6 +161,9 @@ Features:
161
 
162
  == Changelog ==
163
 
 
 
 
164
  = 2.1.5 =
165
  * Bug fix: parse error on menu.html; Style issue: Gutemberg + Meta Box; Improvement (Premium): integration with Product Variation + WooCommerce Rest API + Product Image Gallery.
166
 
@@ -476,6 +479,9 @@ was removed. To finish, a Premium version is now been presented.
476
 
477
  == Upgrade Notice ==
478
 
 
 
 
479
  = 2.1.5 =
480
  * Bug fix: parse error on menu.html; Style issue: Gutemberg + Meta Box; Improvement (Premium): integration with Product Variation + WooCommerce Rest API + Product Image Gallery.
481
 
161
 
162
  == Changelog ==
163
 
164
+ = 2.1.6 =
165
+ * Bug fixes: product category; clean meta data; style issues.
166
+
167
  = 2.1.5 =
168
  * Bug fix: parse error on menu.html; Style issue: Gutemberg + Meta Box; Improvement (Premium): integration with Product Variation + WooCommerce Rest API + Product Image Gallery.
169
 
479
 
480
  == Upgrade Notice ==
481
 
482
+ = 2.1.6 =
483
+ * Bug fixes: product category; clean meta data; style issues.
484
+
485
  = 2.1.5 =
486
  * Bug fix: parse error on menu.html; Style issue: Gutemberg + Meta Box; Improvement (Premium): integration with Product Variation + WooCommerce Rest API + Product Image Gallery.
487