Featured Image From URL - Version 1.3.4

Version Description

  • Bug fixes.

=

Download this release

Release Info

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

Code changes from version 1.3.3 to 1.3.4

admin/meta-box.php CHANGED
@@ -105,37 +105,25 @@ function fifu_wc_show_elements($post) {
105
  add_action('save_post', 'fifu_save_image_properties');
106
 
107
  function fifu_save_image_properties($post_id) {
108
- if (isset($_POST['fifu_input_url'])) {
109
  update_post_meta($post_id, 'fifu_image_url', esc_url($_POST['fifu_input_url']));
110
 
111
- if (!get_post_thumbnail_id($post_id) && esc_url($_POST['fifu_input_url']))
112
- set_post_thumbnail($post_id, get_option('fifu_attachment_id'));
113
- }
114
-
115
  if (isset($_POST['fifu_input_alt']))
116
  update_post_meta($post_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
117
 
118
  if (get_post_type(get_the_ID() == 'product')) {
119
- $count = 10;
120
  for ($i = 0; $i < 10; $i++) {
121
  if (isset($_POST['fifu_input_url_' . $i]) && isset($_POST['fifu_input_alt_' . $i])) {
122
  if ($_POST['fifu_input_url_' . $i] != '' && $_POST['fifu_input_alt_' . $i] != '') {
123
  update_post_meta($post_id, 'fifu_image_url_' . $i, esc_url($_POST['fifu_input_url_' . $i]));
124
  update_post_meta($post_id, 'fifu_image_alt_' . $i, wp_strip_all_tags($_POST['fifu_input_alt_' . $i]));
125
- if (!get_post_thumbnail_id($post_id) && esc_url($_POST['fifu_input_url_' . $i]))
126
- set_post_thumbnail($post_id, get_option('fifu_attachment_id'));
127
  } else {
128
  delete_post_meta($post_id, 'fifu_image_url_' . $i);
129
  delete_post_meta($post_id, 'fifu_image_alt_' . $i);
130
- $count--;
131
  }
132
  }
133
  }
134
- if ($count == 0 && !esc_url($_POST['fifu_input_url']) && get_post_thumbnail_id($post_id) == get_option('fifu_attachment_id'))
135
- delete_post_thumbnail($post_id);
136
- }
137
- else {
138
- if (!esc_url($_POST['fifu_input_url']) && get_post_thumbnail_id($post_id) == get_option('fifu_attachment_id'))
139
- delete_post_thumbnail($post_id);
140
  }
141
  }
 
 
105
  add_action('save_post', 'fifu_save_image_properties');
106
 
107
  function fifu_save_image_properties($post_id) {
108
+ if (isset($_POST['fifu_input_url']))
109
  update_post_meta($post_id, 'fifu_image_url', esc_url($_POST['fifu_input_url']));
110
 
 
 
 
 
111
  if (isset($_POST['fifu_input_alt']))
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.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.3.4
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) {
@@ -37,17 +56,3 @@ function fifu_add_to_content($content) {
37
  return $content;
38
  }
39
 
40
- add_filter('wp_get_attachment_url', 'fifu_replace_attachment_url', 10, 2);
41
-
42
- function fifu_replace_attachment_url($att_url, $att_id) {
43
- if (get_option('fifu_attachment_id') == $att_id) {
44
- if (is_admin())
45
- $att_url = '/wp-content/plugins/featured-image-from-url/admin/images/fifu-text.jpg';
46
- else {
47
- $url = get_post_meta(get_the_ID(), 'fifu_image_url', true);
48
- if ($url)
49
- $att_url = $url;
50
- }
51
- }
52
- return $att_url;
53
- }
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) {
56
  return $content;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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, featured video
5
  Requires at least: 4.0
6
- Tested up to: 4.5
7
- Stable tag: 4.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -205,6 +205,9 @@ was removed. To finish, a Premium version is now been presented.
205
  = 1.3.3 =
206
  * Bug fixes.
207
 
 
 
 
208
  == Upgrade Notice ==
209
 
210
  = 1.0 =
@@ -264,3 +267,6 @@ was removed. To finish, a Premium version is now been presented.
264
 
265
  = 1.3.3 =
266
  * Bug fixes.
 
 
 
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, featured video
5
  Requires at least: 4.0
6
+ Tested up to: 4.5.1
7
+ Stable tag: 4.5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
205
  = 1.3.3 =
206
  * Bug fixes.
207
 
208
+ = 1.3.4 =
209
+ * Bug fixes.
210
+
211
  == Upgrade Notice ==
212
 
213
  = 1.0 =
267
 
268
  = 1.3.3 =
269
  * Bug fixes.
270
+
271
+ = 1.3.4 =
272
+ * Bug fixes.