Featured Image From URL - Version 1.3.2

Version Description

  • Bug fixes.

=

Download this release

Release Info

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

Code changes from version 1.2.5 to 1.3.2

admin/images/fifu-text.jpg ADDED
Binary file
admin/meta-box.php CHANGED
@@ -105,25 +105,37 @@ 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 (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
-
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))
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))
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
  }
 
 
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.2.5
7
  * Author: Marcel Jacques Machado
8
  * Author URI: https://marceljm.com/wordpress/featured-image-from-url-premium/
9
  */
@@ -27,4 +27,73 @@ 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
  }
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.2
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
+ 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
  }
includes/thumbnail-category.php CHANGED
@@ -1,24 +1,22 @@
1
  <?php
2
 
3
- add_filter( 'woocommerce_before_main_content', 'fifu_category_show_image', 30);
4
 
5
- function fifu_category_show_image() {
6
- $image_url = fifu_get_image_url();
7
- $image_alt = fifu_get_image_alt();
8
 
9
- if ($image_url)
10
- $html = fifu_category_get_html($image_url, $image_alt);
11
-
12
- echo $html;
13
  }
14
 
15
  add_filter('wp_head', 'fifu_cat_add_social_tags');
16
 
17
  function fifu_cat_add_social_tags() {
18
- $url = fifu_get_image_url();
19
  $title = single_cat_title('', false);
20
 
21
- $term_id = fifu_get_term_id();
22
  if ($term_id)
23
  $description = wp_strip_all_tags(category_description($term_id));
24
 
@@ -26,25 +24,17 @@ function fifu_cat_add_social_tags() {
26
  include 'html/social.html';
27
  }
28
 
29
- function fifu_get_image_url () {
30
- $term_id = fifu_get_term_id();
31
  return get_term_meta($term_id, 'fifu_image_url', true);
32
  }
33
 
34
- function fifu_get_image_alt() {
35
- $term_id = fifu_get_term_id();
36
  return get_term_meta($term_id, 'fifu_image_alt', true);
37
  }
38
 
39
- function fifu_get_term_id() {
40
  global $wp_query;
41
-
42
- if ($wp_query->queried_object)
43
- return $wp_query->queried_object->term_id;
44
- else
45
- return null;
46
- }
47
-
48
- function fifu_category_get_html($image_url, $image_alt) {
49
- return sprintf('<!-- Featured Image From URL plugin --> <img src="%s" alt="%s"></img>', $image_url, $image_alt);
50
  }
1
  <?php
2
 
3
+ add_filter('woocommerce_before_main_content', 'fifu_cat_show_image', 30);
4
 
5
+ function fifu_cat_show_image() {
6
+ $url = fifu_cat_get_url();
7
+ $alt = fifu_cat_get_alt();
8
 
9
+ if ($url)
10
+ echo fifu_get_html($url, $alt);
 
 
11
  }
12
 
13
  add_filter('wp_head', 'fifu_cat_add_social_tags');
14
 
15
  function fifu_cat_add_social_tags() {
16
+ $url = fifu_cat_get_url();
17
  $title = single_cat_title('', false);
18
 
19
+ $term_id = fifu_cat_get_term_id();
20
  if ($term_id)
21
  $description = wp_strip_all_tags(category_description($term_id));
22
 
24
  include 'html/social.html';
25
  }
26
 
27
+ function fifu_cat_get_url() {
28
+ $term_id = fifu_cat_get_term_id();
29
  return get_term_meta($term_id, 'fifu_image_url', true);
30
  }
31
 
32
+ function fifu_cat_get_alt() {
33
+ $term_id = fifu_cat_get_term_id();
34
  return get_term_meta($term_id, 'fifu_image_alt', true);
35
  }
36
 
37
+ function fifu_cat_get_term_id() {
38
  global $wp_query;
39
+ return $wp_query->get_queried_object_id();
 
 
 
 
 
 
 
 
40
  }
includes/thumbnail.php CHANGED
@@ -9,26 +9,7 @@ function fifu_add_social_tags() {
9
  $description = wp_strip_all_tags(get_post_field('post_content', $post_id));
10
 
11
  if ($url)
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);
@@ -37,7 +18,7 @@ function fifu_replace($html, $post_id) {
37
  $image_url = get_post_meta($post_id, 'fifu_image_url', true);
38
  $image_alt = get_post_meta($post_id, 'fifu_image_alt', true);
39
 
40
- if ($image_url)
41
  $html = fifu_get_html($image_url, $image_alt);
42
 
43
  return $html;
@@ -50,8 +31,23 @@ function fifu_get_html($image_url, $image_alt) {
50
  add_filter('the_content', 'fifu_add_to_content');
51
 
52
  function fifu_add_to_content($content) {
53
- if (is_singular() && has_post_thumbnail() && get_option('fifu_content') == 'toggleon')
54
  return get_the_post_thumbnail() . $content;
55
  else
56
  return $content;
57
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  $description = wp_strip_all_tags(get_post_field('post_content', $post_id));
10
 
11
  if ($url)
12
+ include 'html/social.html';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
14
 
15
  add_filter('post_thumbnail_html', 'fifu_replace', 10, 2);
18
  $image_url = get_post_meta($post_id, 'fifu_image_url', true);
19
  $image_alt = get_post_meta($post_id, 'fifu_image_alt', true);
20
 
21
+ if ($image_url)
22
  $html = fifu_get_html($image_url, $image_alt);
23
 
24
  return $html;
31
  add_filter('the_content', 'fifu_add_to_content');
32
 
33
  function fifu_add_to_content($content) {
34
+ if (is_singular() && has_post_thumbnail() && get_option('fifu_content') == 'toggleon')
35
  return get_the_post_thumbnail() . $content;
36
  else
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
+ }
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.4.2
7
- Stable tag: 4.4.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -193,6 +193,15 @@ 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
  == Upgrade Notice ==
197
 
198
  = 1.0 =
@@ -241,3 +250,11 @@ was removed. To finish, a Premium version is now been presented.
241
  = 1.2.5 =
242
  * All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.
243
 
 
 
 
 
 
 
 
 
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
 
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
+ = 1.3.1 =
200
+ * Bug fixes.
201
+
202
+ = 1.3.2 =
203
+ * Bug fixes.
204
+
205
  == Upgrade Notice ==
206
 
207
  = 1.0 =
250
  = 1.2.5 =
251
  * All the "PHP Notices" shown on "debug.log" file were resolved. So the log will be completely clean.
252
 
253
+ = 1.3 =
254
+ * The plugin should be compatible with any theme now.
255
+
256
+ = 1.3.1 =
257
+ * Bug fixes.
258
+
259
+ = 1.3.2 =
260
+ * Bug fixes.
scripts/disableWoocommerce.sh CHANGED
@@ -5,13 +5,13 @@ themeDir=`cat ../wp-content/plugins/featured-image-from-url/scripts/tmp.txt`
5
 
6
  restoreProductImage()
7
  {
8
- file=$dir'product-image.php'
9
  overwrite
10
  }
11
 
12
  restoreProductThumbnails()
13
  {
14
- file=$dir'product-thumbnails.php'
15
  overwrite
16
  }
17
 
@@ -28,8 +28,10 @@ overwrite()
28
 
29
  restore()
30
  {
31
- restoreProductImage
32
- restoreProductThumbnails
 
 
33
  restoreCategory
34
  }
35
 
5
 
6
  restoreProductImage()
7
  {
8
+ file=$1
9
  overwrite
10
  }
11
 
12
  restoreProductThumbnails()
13
  {
14
+ file=$1
15
  overwrite
16
  }
17
 
28
 
29
  restore()
30
  {
31
+ restoreProductImage $dir'product-image.php'
32
+ restoreProductImage `find $themeDir . -iname product-thumbnails.php`
33
+ restoreProductThumbnails $dir'product-thumbnails.php'
34
+ restoreProductThumbnails `find $themeDir . -iname product-thumbnails.php`
35
  restoreCategory
36
  }
37
 
scripts/enableWoocommerce.sh CHANGED
@@ -15,7 +15,7 @@ featured_image()
15
 
16
  gallery()
17
  {
18
- file=$dir'product-thumbnails.php'
19
  old='if.*$attachment_ids.*{'
20
  new='if(true){'
21
  replace
@@ -42,7 +42,7 @@ category()
42
  {
43
  file=$themeDir'/woocommerce.php'
44
  old='woocommerce_content()'
45
- new='fifu_category_show_image();woocommerce_content()'
46
  replace
47
  }
48
 
@@ -63,6 +63,7 @@ backup()
63
 
64
  featured_image
65
 
66
- gallery
 
67
 
68
  category
15
 
16
  gallery()
17
  {
18
+ file=$1
19
  old='if.*$attachment_ids.*{'
20
  new='if(true){'
21
  replace
42
  {
43
  file=$themeDir'/woocommerce.php'
44
  old='woocommerce_content()'
45
+ new='fifu_cat_show_image();woocommerce_content()'
46
  replace
47
  }
48
 
63
 
64
  featured_image
65
 
66
+ gallery $dir'product-thumbnails.php'
67
+ gallery `find $themeDir . -iname product-thumbnails.php`
68
 
69
  category