Featured Image From URL - Version 1.2.5

Version Description

  • All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.

=

Download this release

Release Info

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

Code changes from version 1.3 to 1.2.5

admin/images/fifu-text.jpg DELETED
Binary file
admin/meta-box.php CHANGED
@@ -112,28 +112,18 @@ function fifu_save_image_properties($post_id) {
112
  update_post_meta($post_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
113
 
114
  if (get_post_type(get_the_ID() == 'product')) {
115
- $count = 10;
116
  for ($i = 0; $i < 10; $i++) {
117
  if (isset($_POST['fifu_input_url_' . $i]) && isset($_POST['fifu_input_alt_' . $i])) {
118
  if ($_POST['fifu_input_url_' . $i] != '' && $_POST['fifu_input_alt_' . $i] != '') {
119
  update_post_meta($post_id, 'fifu_image_url_' . $i, esc_url($_POST['fifu_input_url_' . $i]));
120
  update_post_meta($post_id, 'fifu_image_alt_' . $i, wp_strip_all_tags($_POST['fifu_input_alt_' . $i]));
121
- if (!get_post_thumbnail_id($post_id))
122
- set_post_thumbnail($post_id, get_option('fifu_attachment_id'));
123
- $count--;
124
  } else {
125
  delete_post_meta($post_id, 'fifu_image_url_' . $i);
126
  delete_post_meta($post_id, 'fifu_image_alt_' . $i);
127
  }
128
  }
129
  }
130
- if ($count == 0 && get_post_thumbnail_id($post_id) == get_option('fifu_attachment_id'))
131
- delete_post_thumbnail($post_id);
132
  }
 
133
 
134
- if (esc_url($_POST['fifu_input_url']) && !get_post_thumbnail_id($post_id))
135
- set_post_thumbnail($post_id, get_option('fifu_attachment_id'));
136
 
137
- if (!esc_url($_POST['fifu_input_url']) && get_post_thumbnail_id($post_id) == get_option('fifu_attachment_id'))
138
- delete_post_thumbnail($post_id);
139
- }
112
  update_post_meta($post_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
113
 
114
  if (get_post_type(get_the_ID() == 'product')) {
 
115
  for ($i = 0; $i < 10; $i++) {
116
  if (isset($_POST['fifu_input_url_' . $i]) && isset($_POST['fifu_input_alt_' . $i])) {
117
  if ($_POST['fifu_input_url_' . $i] != '' && $_POST['fifu_input_alt_' . $i] != '') {
118
  update_post_meta($post_id, 'fifu_image_url_' . $i, esc_url($_POST['fifu_input_url_' . $i]));
119
  update_post_meta($post_id, 'fifu_image_alt_' . $i, wp_strip_all_tags($_POST['fifu_input_alt_' . $i]));
 
 
 
120
  } else {
121
  delete_post_meta($post_id, 'fifu_image_url_' . $i);
122
  delete_post_meta($post_id, 'fifu_image_alt_' . $i);
123
  }
124
  }
125
  }
 
 
126
  }
127
+ }
128
 
 
 
129
 
 
 
 
featured-image-from-url.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  * Plugin Name: Featured Image From URL
5
  * Description: Allows to use an external image as Featured Image of your post, page or Custom Post Type, such as WooCommerce Product (supports Product Gallery also).
6
- * Version: 1.3
7
  * Author: Marcel Jacques Machado
8
  * Author URI: https://marceljm.com/wordpress/featured-image-from-url-premium/
9
  */
@@ -27,73 +27,4 @@ register_deactivation_hook( __FILE__, 'fifu_desactivate' );
27
  function fifu_desactivate() {
28
  update_option('fifu_woocommerce', 'toggleoff');
29
  shell_exec('sh ../wp-content/plugins/featured-image-from-url/scripts/disableWoocommerce.sh');
30
- wp_delete_attachment(get_option('fifu_attachment_id'));
31
- }
32
-
33
- register_activation_hook(__FILE__, 'fifu_activate');
34
-
35
- function fifu_activate() {
36
- global $wpdb;
37
- $old_attach_id = get_option('fifu_attachment_id');
38
-
39
- /* create attachment */
40
- $filename = 'Featured Image From URL';
41
- $parent_post_id = null;
42
- $filetype = wp_check_filetype('anything.jpg', null);
43
- $attachment = array(
44
- 'guid' => basename($filename),
45
- 'post_mime_type' => $filetype['type'],
46
- 'post_title' => '',
47
- 'post_excerpt' => '',
48
- 'post_content' => 'Please don\'t remove that. It\'s just a symbolic file that keeps the field filled. Some themes depend on having an attached file to work. But you are free to use any image you want instead of this file.',
49
- 'post_status' => 'inherit'
50
- );
51
- $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
52
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
53
- $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
54
- wp_update_attachment_metadata($attach_id, $attach_data);
55
- update_option('fifu_attachment_id', $attach_id);
56
-
57
- /* insert _thumbnail_id */
58
- $table = $wpdb->prefix . 'postmeta';
59
- $query = "
60
- SELECT DISTINCT post_id
61
- FROM " . $table . " a
62
- WHERE a.post_id in (
63
- SELECT post_id
64
- FROM " . $table . " b
65
- WHERE b.meta_key = 'fifu_image_url'
66
- AND b.meta_value IS NOT NULL
67
- AND b.meta_value <> ''
68
- )
69
- AND NOT EXISTS (
70
- SELECT 1
71
- FROM " . $table . " c
72
- WHERE a.post_id = c.post_id
73
- AND c.meta_key = '_thumbnail_id'
74
- )";
75
- $result = $wpdb->get_results($query);
76
- foreach ($result as $i) {
77
- $data = array('post_id' => $i->post_id, 'meta_key' => '_thumbnail_id', 'meta_value' => $attach_id);
78
- $wpdb->insert($table, $data);
79
- }
80
-
81
- /* update _thumbnail_id */
82
- $data = array('meta_value' => $attach_id);
83
- $where = array('meta_key' => '_thumbnail_id', 'meta_value' => $old_attach_id);
84
- $wpdb->update($table, $data, $where, null, null);
85
-
86
- /* update _thumbnail_id (to support old versions) */
87
- $query = "
88
- SELECT post_id
89
- FROM " . $table . " a
90
- WHERE a.meta_key = 'fifu_image_url'
91
- AND a.meta_value IS NOT NULL
92
- AND a.meta_value <> ''";
93
- $result = $wpdb->get_results($query);
94
- foreach ($result as $i) {
95
- $data = array('meta_value' => $attach_id);
96
- $where = array('post_id' => $i->post_id, 'meta_key' => '_thumbnail_id', 'meta_value' => -1);
97
- $wpdb->update($table, $data, $where, null, null);
98
- }
99
  }
3
  /*
4
  * Plugin Name: Featured Image From URL
5
  * Description: Allows to use an external image as Featured Image of your post, page or Custom Post Type, such as WooCommerce Product (supports Product Gallery also).
6
+ * Version: 1.2.5
7
  * Author: Marcel Jacques Machado
8
  * Author URI: https://marceljm.com/wordpress/featured-image-from-url-premium/
9
  */
27
  function fifu_desactivate() {
28
  update_option('fifu_woocommerce', 'toggleoff');
29
  shell_exec('sh ../wp-content/plugins/featured-image-from-url/scripts/disableWoocommerce.sh');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
includes/thumbnail.php CHANGED
@@ -12,6 +12,25 @@ function fifu_add_social_tags() {
12
  include 'html/social.html';
13
  }
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  add_filter('post_thumbnail_html', 'fifu_replace', 10, 2);
16
 
17
  function fifu_replace($html, $post_id) {
@@ -28,18 +47,6 @@ function fifu_get_html($image_url, $image_alt) {
28
  return sprintf('<!-- Featured Image From URL plugin --> <img src="%s" alt="%s"></img>', $image_url, $image_alt);
29
  }
30
 
31
- add_filter('wp_get_attachment_url', 'fifu_replace_attachment_url', 10, 2);
32
-
33
- function fifu_replace_attachment_url($att_url, $att_id) {
34
- if (get_option('fifu_attachment_id') == $att_id) {
35
- if (is_admin())
36
- $att_url = '/wp-content/plugins/featured-image-from-url/admin/images/fifu-text.jpg';
37
- else
38
- $att_url = get_post_meta(get_the_ID(), 'fifu_image_url', true);
39
- }
40
- return $att_url;
41
- }
42
-
43
  add_filter('the_content', 'fifu_add_to_content');
44
 
45
  function fifu_add_to_content($content) {
12
  include 'html/social.html';
13
  }
14
 
15
+ add_action('the_post', 'fifu_choose');
16
+
17
+ function fifu_choose($post) {
18
+ $post_id = $post->ID;
19
+
20
+ $image_url = get_post_meta($post_id, 'fifu_image_url', true);
21
+
22
+ $featured_image = get_post_meta($post_id, '_thumbnail_id', true);
23
+
24
+ if ($image_url) {
25
+ if (!$featured_image)
26
+ update_post_meta($post_id, '_thumbnail_id', -1);
27
+ }
28
+ else {
29
+ if ($featured_image == -1)
30
+ delete_post_meta($post_id, '_thumbnail_id');
31
+ }
32
+ }
33
+
34
  add_filter('post_thumbnail_html', 'fifu_replace', 10, 2);
35
 
36
  function fifu_replace($html, $post_id) {
47
  return sprintf('<!-- Featured Image From URL plugin --> <img src="%s" alt="%s"></img>', $image_url, $image_alt);
48
  }
49
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  add_filter('the_content', 'fifu_add_to_content');
51
 
52
  function fifu_add_to_content($content) {
readme.txt CHANGED
@@ -193,9 +193,6 @@ was removed. To finish, a Premium version is now been presented.
193
  = 1.2.5 =
194
  * All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.
195
 
196
- = 1.3 =
197
- * The plugin should be compatible with any theme now.
198
-
199
  == Upgrade Notice ==
200
 
201
  = 1.0 =
@@ -244,5 +241,3 @@ was removed. To finish, a Premium version is now been presented.
244
  = 1.2.5 =
245
  * All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.
246
 
247
- = 1.3 =
248
- * The plugin should be compatible with any theme now.
193
  = 1.2.5 =
194
  * All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.
195
 
 
 
 
196
  == Upgrade Notice ==
197
 
198
  = 1.0 =
241
  = 1.2.5 =
242
  * All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.
243
 
 
 
scripts/enableWoocommerce.sh CHANGED
@@ -15,7 +15,7 @@ featured_image()
15
 
16
  gallery()
17
  {
18
- file=$1
19
  old='if.*$attachment_ids.*{'
20
  new='if(true){'
21
  replace
@@ -63,7 +63,6 @@ backup()
63
 
64
  featured_image
65
 
66
- gallery $dir'product-thumbnails.php'
67
- gallery `find $themeDir . -iname product-thumbnails.php`
68
 
69
  category
15
 
16
  gallery()
17
  {
18
+ file=$dir'product-thumbnails.php'
19
  old='if.*$attachment_ids.*{'
20
  new='if(true){'
21
  replace
63
 
64
  featured_image
65
 
66
+ gallery
 
67
 
68
  category