Version Description
- Small readme.txt update.
Download this release
Release Info
Developer | janw.oostendorp |
Plugin | ![]() |
Version | 1.6.1 |
Comparing to | |
See all releases |
Code changes from version 1.6 to 1.6.1
- readme.txt +139 -136
- set-default-featured-image.js +5 -6
- set-default-featured-image.php +11 -8
readme.txt
CHANGED
@@ -1,136 +1,139 @@
|
|
1 |
-
=== Plugin Name ===
|
2 |
-
Contributors: janwoostendorp
|
3 |
-
Tags: media, image
|
4 |
-
Requires at least: 3.5
|
5 |
-
Tested up to: 4.8
|
6 |
-
Stable tag: 1.6
|
7 |
-
License: GPLv2 or later
|
8 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
-
|
10 |
-
Add a default featured image to the media settings page
|
11 |
-
|
12 |
-
== Description ==
|
13 |
-
|
14 |
-
Add a default featured image to the media settings page. This featured image will show up if no featured image is set. Simple as that.
|
15 |
-
|
16 |
-
For exceptions and to see which functions to use see the [FAQ](http://wordpress.org/extend/plugins/default-featured-image/faq/).
|
17 |
-
|
18 |
-
= Suggestions are welcome =
|
19 |
-
* Found a bug?
|
20 |
-
* Want to help to translate it in your language?
|
21 |
-
* Something to be improved?
|
22 |
-
|
23 |
-
[Contact me](http://wordpress.org/support/plugin/default-featured-image)
|
24 |
-
|
25 |
-
== Installation ==
|
26 |
-
|
27 |
-
1. Unzip the folder to the `/wp-content/plugins/` directory
|
28 |
-
2. Activate the plugin through the 'Plugins' menu in WordPress
|
29 |
-
3. Go to the settings->media page and select an image.
|
30 |
-
|
31 |
-
== Frequently Asked Questions ==
|
32 |
-
|
33 |
-
= My chosen featured image doesn't show, why isn't it working? =
|
34 |
-
|
35 |
-
This plugin can't guarantee that it works. That depends on the themes. Still I want to know if it fails, so [contact me](http://wordpress.org/support/plugin/default-featured-image)
|
36 |
-
|
37 |
-
= Which functions can I use to display the featured image? =
|
38 |
-
The plugin uses the default WordPress functions `the_post_thumbnail` or `get_the_post_thumbnail`. `has_post_thumbnail` will always return true. `get_post_thumbnail_id` will return the ID set on the post or the DFI you set.
|
39 |
-
|
40 |
-
= Can I exclude a page or give it a different image? =
|
41 |
-
Yes you can by using the
|
42 |
-
|
43 |
-
**Don't use a featured image on page 23**
|
44 |
-
|
45 |
-
function dfi_skip_page ( $dfi_id, $post_id ) {
|
46 |
-
if ( $post_id == 23 ) {
|
47 |
-
return 0; // invalid id
|
48 |
-
}
|
49 |
-
return $dfi_id; // the original featured image id
|
50 |
-
}
|
51 |
-
add_filter( 'dfi_thumbnail_id', 'dfi_skip_page', 10 , 2 );
|
52 |
-
|
53 |
-
**Use a different image for some categories**
|
54 |
-
|
55 |
-
The example below only works if the post has 'animals' as a category.
|
56 |
-
To do that just don't nest the `if`
|
57 |
-
|
58 |
-
function dfi_category ( $dfi_id, $post_id ) {
|
59 |
-
// all which have 'animals' as a category
|
60 |
-
if ( has_category( 'animals', $post_id ) ) {
|
61 |
-
|
62 |
-
//sub category
|
63 |
-
if ( has_category( 'cats', $post_id ) ) {
|
64 |
-
return 7; // cats img
|
65 |
-
} else if has_category( 'dogs', $post_id ) {
|
66 |
-
return 8; // dogs img
|
67 |
-
}
|
68 |
-
|
69 |
-
return 6; // default animals picture
|
70 |
-
}
|
71 |
-
return $dfi_id; // the original featured image id
|
72 |
-
}
|
73 |
-
add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
|
74 |
-
|
75 |
-
**Different image for the
|
76 |
-
|
77 |
-
function dfi_posttype_book ( $dfi_id, $post_id ) {
|
78 |
-
$post = get_post($post_id);
|
79 |
-
if ( 'wiki' === $post->post_type ) {
|
80 |
-
return 31; // the image id
|
81 |
-
}
|
82 |
-
return $dfi_id; // the original featured image id
|
83 |
-
}
|
84 |
-
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );
|
85 |
-
|
86 |
-
= Can I change the HTML of the image returned? =
|
87 |
-
yes you can with the filter `dfi_thumbnail_html`.
|
88 |
-
|
89 |
-
function dfi_add_class($html, $post_id, $default_thumbnail_id, $size, $attr) {
|
90 |
-
// add a class to the existing class list
|
91 |
-
$attr['class'] .= ' my-class';
|
92 |
-
|
93 |
-
return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
|
94 |
-
}
|
95 |
-
add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );
|
96 |
-
|
97 |
-
== Screenshots ==
|
98 |
-
|
99 |
-
1. The setting on the media page
|
100 |
-
2. The media manager will start with the current selected image
|
101 |
-
|
102 |
-
== Changelog ==
|
103 |
-
|
104 |
-
=
|
105 |
-
*
|
106 |
-
|
107 |
-
= 1.
|
108 |
-
*
|
109 |
-
|
110 |
-
|
111 |
-
*
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
*
|
129 |
-
|
130 |
-
|
131 |
-
*
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: janwoostendorp
|
3 |
+
Tags: media, image
|
4 |
+
Requires at least: 3.5
|
5 |
+
Tested up to: 4.8
|
6 |
+
Stable tag: 1.6.1
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
Add a default featured image to the media settings page
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
Add a default featured image to the media settings page. This featured image will show up if no featured image is set. Simple as that.
|
15 |
+
|
16 |
+
For exceptions and to see which functions to use see the [FAQ](http://wordpress.org/extend/plugins/default-featured-image/faq/).
|
17 |
+
|
18 |
+
= Suggestions are welcome =
|
19 |
+
* Found a bug?
|
20 |
+
* Want to help to translate it in your language?
|
21 |
+
* Something to be improved?
|
22 |
+
|
23 |
+
[Contact me](http://wordpress.org/support/plugin/default-featured-image)
|
24 |
+
|
25 |
+
== Installation ==
|
26 |
+
|
27 |
+
1. Unzip the folder to the `/wp-content/plugins/` directory
|
28 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
29 |
+
3. Go to the settings->media page and select an image.
|
30 |
+
|
31 |
+
== Frequently Asked Questions ==
|
32 |
+
|
33 |
+
= My chosen featured image doesn't show, why isn't it working? =
|
34 |
+
|
35 |
+
This plugin can't guarantee that it works. That depends on the themes. Still I want to know if it fails, so [contact me](http://wordpress.org/support/plugin/default-featured-image)
|
36 |
+
|
37 |
+
= Which functions can I use to display the featured image? =
|
38 |
+
The plugin uses the default WordPress functions `the_post_thumbnail` or `get_the_post_thumbnail`. `has_post_thumbnail` will always return true. `get_post_thumbnail_id` will return the ID set on the post or the DFI you set.
|
39 |
+
|
40 |
+
= Can I exclude a page or give it a different image? =
|
41 |
+
Yes you can by using the builtin `dfi_thumbnail_id` filter. It will give you the post id which you can use to check against.
|
42 |
+
|
43 |
+
**Don't use a featured image on page 23**
|
44 |
+
|
45 |
+
function dfi_skip_page ( $dfi_id, $post_id ) {
|
46 |
+
if ( $post_id == 23 ) {
|
47 |
+
return 0; // invalid id
|
48 |
+
}
|
49 |
+
return $dfi_id; // the original featured image id
|
50 |
+
}
|
51 |
+
add_filter( 'dfi_thumbnail_id', 'dfi_skip_page', 10 , 2 );
|
52 |
+
|
53 |
+
**Use a different image for some categories**
|
54 |
+
|
55 |
+
The example below only works if the post has 'animals' as a category. Assigning just 'cats' won't work
|
56 |
+
To do that just don't nest the `if`
|
57 |
+
|
58 |
+
function dfi_category ( $dfi_id, $post_id ) {
|
59 |
+
// all which have 'animals' as a category
|
60 |
+
if ( has_category( 'animals', $post_id ) ) {
|
61 |
+
|
62 |
+
//sub category
|
63 |
+
if ( has_category( 'cats', $post_id ) ) {
|
64 |
+
return 7; // cats img
|
65 |
+
} else if has_category( 'dogs', $post_id ) {
|
66 |
+
return 8; // dogs img
|
67 |
+
}
|
68 |
+
|
69 |
+
return 6; // default animals picture
|
70 |
+
}
|
71 |
+
return $dfi_id; // the original featured image id
|
72 |
+
}
|
73 |
+
add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
|
74 |
+
|
75 |
+
**Different image for the post_type 'wiki'**
|
76 |
+
|
77 |
+
function dfi_posttype_book ( $dfi_id, $post_id ) {
|
78 |
+
$post = get_post($post_id);
|
79 |
+
if ( 'wiki' === $post->post_type ) {
|
80 |
+
return 31; // the image id
|
81 |
+
}
|
82 |
+
return $dfi_id; // the original featured image id
|
83 |
+
}
|
84 |
+
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );
|
85 |
+
|
86 |
+
= Can I change the HTML of the image returned? =
|
87 |
+
yes you can with the filter `dfi_thumbnail_html`.
|
88 |
+
|
89 |
+
function dfi_add_class($html, $post_id, $default_thumbnail_id, $size, $attr) {
|
90 |
+
// add a class to the existing class list
|
91 |
+
$attr['class'] .= ' my-class';
|
92 |
+
|
93 |
+
return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
|
94 |
+
}
|
95 |
+
add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );
|
96 |
+
|
97 |
+
== Screenshots ==
|
98 |
+
|
99 |
+
1. The setting on the media page
|
100 |
+
2. The media manager will start with the current selected image
|
101 |
+
|
102 |
+
== Changelog ==
|
103 |
+
|
104 |
+
= 1.6.1 =
|
105 |
+
* Small readme.txt update.
|
106 |
+
|
107 |
+
= 1.6 =
|
108 |
+
* On of the last fixes didn't account for all situations.
|
109 |
+
|
110 |
+
= 1.5 =
|
111 |
+
* Fixed two small (and rare) warnings
|
112 |
+
* Added translation domain
|
113 |
+
|
114 |
+
= 1.4 =
|
115 |
+
* Added plugin images both the plugin header as the thumbnail. Based on the boat WP.org uses in it's theme previews
|
116 |
+
* Fixed a bug where the ajax calls didn't return the DFI [forum thread](https://wordpress.org/support/topic/dfi-woocommerce-facetwp?replies=10)
|
117 |
+
|
118 |
+
= 1.3 =
|
119 |
+
* Filter `dfi_thumbnail_id` now also returns the post ID of the post (or any postype) that is being called. See the FAQ for new examples
|
120 |
+
|
121 |
+
= 1.2 =
|
122 |
+
* Filter `dfi_thumbnail_id` is now called in an earlier stage.
|
123 |
+
|
124 |
+
= 1.1 =
|
125 |
+
* Fixed inheriting classes of the image
|
126 |
+
|
127 |
+
= 1.0 =
|
128 |
+
* Plugin will now remove it's setting on plugin removal
|
129 |
+
* added a default class to the `<img>` tag, if it shows a default featured image
|
130 |
+
* The default featured image will now also return with `get_post_thumbnail_id`, making the chance that it fail far far smaller.
|
131 |
+
* The image given in the media page is now validated
|
132 |
+
|
133 |
+
= 0.9 =
|
134 |
+
* Launch
|
135 |
+
|
136 |
+
== Upgrade Notice ==
|
137 |
+
|
138 |
+
= 1.0 =
|
139 |
+
Update makes sure that the set image will show. Everywhere.
|
set-default-featured-image.js
CHANGED
@@ -24,8 +24,7 @@ jQuery(document).ready(function ($) {
|
|
24 |
* @return html string with the image
|
25 |
*/
|
26 |
function set_preview_image(image_id) {
|
27 |
-
var
|
28 |
-
data = {
|
29 |
action: 'dfi_change_preview',
|
30 |
image_id: image_id
|
31 |
};
|
@@ -34,11 +33,11 @@ jQuery(document).ready(function ($) {
|
|
34 |
set_preview_html(response);
|
35 |
});
|
36 |
|
37 |
-
return responseText;
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
-
* set a loading image
|
42 |
*/
|
43 |
function set_loading_image() {
|
44 |
var $cur_preview = $td.find('#preview-image'),
|
@@ -99,9 +98,9 @@ jQuery(document).ready(function ($) {
|
|
99 |
selection.add(attachment ? [ attachment ] : []);
|
100 |
});
|
101 |
|
102 |
-
//
|
103 |
frame.open();
|
104 |
});
|
105 |
|
106 |
|
107 |
-
}); // doc rdy
|
24 |
* @return html string with the image
|
25 |
*/
|
26 |
function set_preview_image(image_id) {
|
27 |
+
var data = {
|
|
|
28 |
action: 'dfi_change_preview',
|
29 |
image_id: image_id
|
30 |
};
|
33 |
set_preview_html(response);
|
34 |
});
|
35 |
|
36 |
+
// return responseText;
|
37 |
}
|
38 |
|
39 |
/**
|
40 |
+
* set a loading image until the ajax is ready
|
41 |
*/
|
42 |
function set_loading_image() {
|
43 |
var $cur_preview = $td.find('#preview-image'),
|
98 |
selection.add(attachment ? [ attachment ] : []);
|
99 |
});
|
100 |
|
101 |
+
// everything is set open the media manager
|
102 |
frame.open();
|
103 |
});
|
104 |
|
105 |
|
106 |
+
}); // doc rdy
|
set-default-featured-image.php
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
-
<?php
|
|
|
2 |
/**
|
3 |
* plugin name: Default featured image
|
4 |
* Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/
|
5 |
-
* Description: Allows users to select a default
|
6 |
-
* Version: 1.6
|
|
|
7 |
* Author: Jan Willem Oostendorp
|
8 |
* License: GPLv2 or later
|
9 |
* Text Domain: default-featured-image
|
@@ -21,9 +23,9 @@ class default_featured_image
|
|
21 |
add_action( 'admin_init', array( &$this, 'media_setting' ) );
|
22 |
// enqueue the js
|
23 |
add_action( 'admin_print_scripts-options-media.php', array( &$this, 'admin_scripts' ) );
|
24 |
-
// get the preview image
|
25 |
add_action( 'wp_ajax_dfi_change_preview', array( &$this, 'ajax_wrapper' ) );
|
26 |
-
// set dfi meta key on every
|
27 |
add_filter( 'get_post_metadata', array(&$this, 'set_dfi_meta_key'), 10, 4 );
|
28 |
// display a default featured image
|
29 |
add_filter( 'post_thumbnail_html', array( &$this, 'show_dfi' ), 20, 5 );
|
@@ -45,7 +47,7 @@ class default_featured_image
|
|
45 |
}
|
46 |
|
47 |
/**
|
48 |
-
* Mostly the same as `get_metadata()` makes sure any
|
49 |
* the deepest level possible.
|
50 |
*
|
51 |
* @see /wp-includes/meta.php get_metadata()
|
@@ -183,7 +185,8 @@ class default_featured_image
|
|
183 |
function add_settings_link( $links, $file ) {
|
184 |
|
185 |
if ( $file == plugin_basename( __FILE__ ) ) {
|
186 |
-
|
|
|
187 |
array_unshift( $links, $settings_link );
|
188 |
}
|
189 |
return $links;
|
@@ -191,7 +194,7 @@ class default_featured_image
|
|
191 |
|
192 |
/**
|
193 |
* Set a default featured image if it is missing
|
194 |
-
* @param
|
195 |
* @param int $post_id
|
196 |
* @param int $post_thumbnail_id
|
197 |
* @param string $size
|
1 |
+
<?php /** @noinspection PhpUndefinedClassInspection */
|
2 |
+
|
3 |
/**
|
4 |
* plugin name: Default featured image
|
5 |
* Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/
|
6 |
+
* Description: Allows users to select a default featured image in the media settings
|
7 |
+
* Version: 1.6.1
|
8 |
+
* Requires PHP: 5.5
|
9 |
* Author: Jan Willem Oostendorp
|
10 |
* License: GPLv2 or later
|
11 |
* Text Domain: default-featured-image
|
23 |
add_action( 'admin_init', array( &$this, 'media_setting' ) );
|
24 |
// enqueue the js
|
25 |
add_action( 'admin_print_scripts-options-media.php', array( &$this, 'admin_scripts' ) );
|
26 |
+
// get the preview image ajax call
|
27 |
add_action( 'wp_ajax_dfi_change_preview', array( &$this, 'ajax_wrapper' ) );
|
28 |
+
// set dfi meta key on every occasion
|
29 |
add_filter( 'get_post_metadata', array(&$this, 'set_dfi_meta_key'), 10, 4 );
|
30 |
// display a default featured image
|
31 |
add_filter( 'post_thumbnail_html', array( &$this, 'show_dfi' ), 20, 5 );
|
47 |
}
|
48 |
|
49 |
/**
|
50 |
+
* Mostly the same as `get_metadata()` makes sure any post thumbnail function gets checked at
|
51 |
* the deepest level possible.
|
52 |
*
|
53 |
* @see /wp-includes/meta.php get_metadata()
|
185 |
function add_settings_link( $links, $file ) {
|
186 |
|
187 |
if ( $file == plugin_basename( __FILE__ ) ) {
|
188 |
+
$href = admin_url('options-media.php#dfi-set-dfi');
|
189 |
+
$settings_link = '<a href="' . $href . '">' . __( 'Settings' )/*get this from WP core*/ . '</a>';
|
190 |
array_unshift( $links, $settings_link );
|
191 |
}
|
192 |
return $links;
|
194 |
|
195 |
/**
|
196 |
* Set a default featured image if it is missing
|
197 |
+
* @param string $html
|
198 |
* @param int $post_id
|
199 |
* @param int $post_thumbnail_id
|
200 |
* @param string $size
|