Version Description
- The plugin should be compatible with any theme now.
=
Download this release
Release Info
Developer | marceljm |
Plugin | Featured Image From URL |
Version | 1.3 |
Comparing to | |
See all releases |
Code changes from version 1.2.4 to 1.3
- admin/category.php +5 -2
- admin/images/fifu-text.jpg +0 -0
- admin/meta-box.php +21 -5
- featured-image-from-url.php +70 -1
- includes/thumbnail.php +12 -19
- readme.txt +12 -0
- scripts/enableWoocommerce.sh +3 -2
admin/category.php
CHANGED
@@ -12,10 +12,13 @@ function fifu_show_category_box($term) {
|
|
12 |
$url = get_term_meta($term->term_id, 'fifu_image_url', true);
|
13 |
$alt = get_term_meta($term->term_id, 'fifu_image_alt', true);
|
14 |
|
15 |
-
if ($url)
|
16 |
$show_url = $show_button = 'display:none;';
|
17 |
-
|
|
|
18 |
$show_alt = $show_image = $show_link = 'display:none;';
|
|
|
|
|
19 |
|
20 |
include 'html/category.html';
|
21 |
include 'html/category-advertisement.html';
|
12 |
$url = get_term_meta($term->term_id, 'fifu_image_url', true);
|
13 |
$alt = get_term_meta($term->term_id, 'fifu_image_alt', true);
|
14 |
|
15 |
+
if ($url) {
|
16 |
$show_url = $show_button = 'display:none;';
|
17 |
+
$show_alt = $show_image = $show_link = '';
|
18 |
+
} else {
|
19 |
$show_alt = $show_image = $show_link = 'display:none;';
|
20 |
+
$show_url = $show_button = '';
|
21 |
+
}
|
22 |
|
23 |
include 'html/category.html';
|
24 |
include 'html/category-advertisement.html';
|
admin/images/fifu-text.jpg
ADDED
Binary file
|
admin/meta-box.php
CHANGED
@@ -59,10 +59,13 @@ function fifu_show_elements($post) {
|
|
59 |
$url = get_post_meta($post->ID, 'fifu_image_url', true);
|
60 |
$alt = get_post_meta($post->ID, 'fifu_image_alt', true);
|
61 |
|
62 |
-
if ($url)
|
63 |
$show_url = $show_button = 'display:none;';
|
64 |
-
|
|
|
65 |
$show_alt = $show_image = $show_link = 'display:none;';
|
|
|
|
|
66 |
|
67 |
include 'html/meta-box.html';
|
68 |
}
|
@@ -87,10 +90,13 @@ function fifu_wc_show_elements($post) {
|
|
87 |
$url[$i] = get_post_meta($post->ID, 'fifu_image_url_' . $i, true);
|
88 |
$alt[$i] = get_post_meta($post->ID, 'fifu_image_alt_' . $i, true);
|
89 |
|
90 |
-
if ($url[$i])
|
91 |
$show_url[$i] = $show_button[$i] = 'display:none;';
|
92 |
-
|
|
|
93 |
$show_alt[$i] = $show_image[$i] = $show_link[$i] = 'display:none;';
|
|
|
|
|
94 |
|
95 |
include 'html/wc-meta-box.html';
|
96 |
}
|
@@ -106,18 +112,28 @@ function fifu_save_image_properties($post_id) {
|
|
106 |
update_post_meta($post_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
|
107 |
|
108 |
if (get_post_type(get_the_ID() == 'product')) {
|
|
|
109 |
for ($i = 0; $i < 10; $i++) {
|
110 |
if (isset($_POST['fifu_input_url_' . $i]) && isset($_POST['fifu_input_alt_' . $i])) {
|
111 |
if ($_POST['fifu_input_url_' . $i] != '' && $_POST['fifu_input_alt_' . $i] != '') {
|
112 |
update_post_meta($post_id, 'fifu_image_url_' . $i, esc_url($_POST['fifu_input_url_' . $i]));
|
113 |
update_post_meta($post_id, 'fifu_image_alt_' . $i, wp_strip_all_tags($_POST['fifu_input_alt_' . $i]));
|
|
|
|
|
|
|
114 |
} else {
|
115 |
delete_post_meta($post_id, 'fifu_image_url_' . $i);
|
116 |
delete_post_meta($post_id, 'fifu_image_alt_' . $i);
|
117 |
}
|
118 |
}
|
119 |
}
|
|
|
|
|
120 |
}
|
121 |
-
}
|
122 |
|
|
|
|
|
123 |
|
|
|
|
|
|
59 |
$url = get_post_meta($post->ID, 'fifu_image_url', true);
|
60 |
$alt = get_post_meta($post->ID, 'fifu_image_alt', true);
|
61 |
|
62 |
+
if ($url) {
|
63 |
$show_url = $show_button = 'display:none;';
|
64 |
+
$show_alt = $show_image = $show_link = '';
|
65 |
+
} else {
|
66 |
$show_alt = $show_image = $show_link = 'display:none;';
|
67 |
+
$show_url = $show_button = '';
|
68 |
+
}
|
69 |
|
70 |
include 'html/meta-box.html';
|
71 |
}
|
90 |
$url[$i] = get_post_meta($post->ID, 'fifu_image_url_' . $i, true);
|
91 |
$alt[$i] = get_post_meta($post->ID, 'fifu_image_alt_' . $i, true);
|
92 |
|
93 |
+
if ($url[$i]) {
|
94 |
$show_url[$i] = $show_button[$i] = 'display:none;';
|
95 |
+
$show_alt[$i] = $show_image[$i] = $show_link[$i] = '';
|
96 |
+
} else {
|
97 |
$show_alt[$i] = $show_image[$i] = $show_link[$i] = 'display:none;';
|
98 |
+
$show_url[$i] = $show_button[$i] = '';
|
99 |
+
}
|
100 |
|
101 |
include 'html/wc-meta-box.html';
|
102 |
}
|
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 |
+
}
|
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.
|
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
|
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.php
CHANGED
@@ -12,25 +12,6 @@ function fifu_add_social_tags() {
|
|
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,6 +28,18 @@ function fifu_get_html($image_url, $image_alt) {
|
|
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) {
|
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 |
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) {
|
readme.txt
CHANGED
@@ -190,6 +190,12 @@ was removed. To finish, a Premium version is now been presented.
|
|
190 |
= 1.2.4 =
|
191 |
* It's possible to hide the plugin meta boxes now.
|
192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
== Upgrade Notice ==
|
194 |
|
195 |
= 1.0 =
|
@@ -234,3 +240,9 @@ was removed. To finish, a Premium version is now been presented.
|
|
234 |
|
235 |
= 1.2.4 =
|
236 |
* It's possible to hide the plugin meta boxes now.
|
|
|
|
|
|
|
|
|
|
|
|
190 |
= 1.2.4 =
|
191 |
* It's possible to hide the plugin meta boxes now.
|
192 |
|
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 =
|
240 |
|
241 |
= 1.2.4 =
|
242 |
* It's possible to hide the plugin meta boxes now.
|
243 |
+
|
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.
|
scripts/enableWoocommerce.sh
CHANGED
@@ -15,7 +15,7 @@ featured_image()
|
|
15 |
|
16 |
gallery()
|
17 |
{
|
18 |
-
file=$
|
19 |
old='if.*$attachment_ids.*{'
|
20 |
new='if(true){'
|
21 |
replace
|
@@ -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
|
63 |
|
64 |
featured_image
|
65 |
|
66 |
+
gallery $dir'product-thumbnails.php'
|
67 |
+
gallery `find $themeDir . -iname product-thumbnails.php`
|
68 |
|
69 |
category
|