Default featured image - Version 1.1

Version Description

  • Fixed inheriting classes of the image

=

Download this release

Release Info

Developer janw.oostendorp
Plugin Icon 128x128 Default featured image
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

languages/default-featured-image-nl_NL_1.mo ADDED
Binary file
languages/default-featured-image-nl_NL_1.po ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Default featured Image\n"
4
+ "POT-Creation-Date: 2012-12-24 16:42+0100\n"
5
+ "PO-Revision-Date: 2012-12-24 16:42+0100\n"
6
+ "Last-Translator: Jan Willem Oostendorp <janw.oostendorp@gmail.com>\n"
7
+ "Language-Team: Jan Willem Oostendorp <janw.oostendorp@gmail.com>\n"
8
+ "Language: nl_NL\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.5.3\n"
13
+ "X-Poedit-KeywordsList: __;_e\n"
14
+ "X-Poedit-Basepath: ../\n"
15
+ "X-Poedit-SearchPath-0: .\n"
16
+
17
+ #: set-default-featured-image.php:44
18
+ msgid "Default featured image"
19
+ msgstr "Standaard uitgelichte afbeelding"
20
+
21
+ #: set-default-featured-image.php:65 set-default-featured-image.php:67
22
+ #: set-default-featured-image.php:90
23
+ msgid "Select default featured image"
24
+ msgstr "Selecteer een standaard uitgelichte afbeelding"
25
+
26
+ #: set-default-featured-image.php:70 set-default-featured-image.php:71
27
+ msgid "Don't use a default featured image"
28
+ msgstr "Geen standaard uitgelichte afbeelding"
29
+
30
+ #: set-default-featured-image.php:91
31
+ msgid "Set default featured image"
32
+ msgstr "Zet standaard uitgelichte afbeelding"
33
+
34
+ #: set-default-featured-image.php:126
35
+ msgid "Settings"
36
+ msgstr "Instellingen"
37
+
38
+ #~ msgid "Select a default featured image"
39
+ #~ msgstr "Selecteer een standaard uitgelichte afbeelding"
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: janwoostendorp
3
  Tags: media, image
4
  Requires at least: 3.5
5
- Tested up to: 3.5.1
6
- Stable tag: 1.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -43,26 +43,43 @@ yes. you can exclude all kinds of things with the [conditional tags](http://code
43
 
44
  **Dont use a featured image on page 5**
45
 
46
- add_action('template_redirect', function () {
47
  if ( is_single( 5 ) || get_the_ID() == 5 ) {
48
- add_filter('dfi_thumbnail_id', function () { return 0; } );
49
  }
50
- });
 
 
51
 
52
- **use a different image on the "book" posttype, it's id is 12**
53
 
54
- add_action('template_redirect', function () {
55
- if ( is_singular( 'book' ) || get_post_type() == 'book') {
56
- add_filter('dfi_thumbnail_id', function () { return 12; } );
 
 
57
  }
58
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  = Can I change the HTML of the image returned? =
61
  yes you can with the filter `dfi_thumbnail_html`.
62
 
63
  function dfi_add_class($html, $post_id, $default_thumbnail_id, $size, $attr) {
64
  // add a class to the existing class list
65
- $attr['class'] = 'my-class '.$attr['class'];
66
 
67
  return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
68
  }
@@ -84,6 +101,9 @@ yes you can with the filter `dfi_thumbnail_html`.
84
  * The default featured image will now also return with `get_post_thumbnail_id`, making the chance that it fail far far smaller.
85
  * The image given in the media page is now validated
86
 
 
 
 
87
  == Upgrade Notice ==
88
 
89
  = 1.0 =
2
  Contributors: janwoostendorp
3
  Tags: media, image
4
  Requires at least: 3.5
5
+ Tested up to: 3.8.1
6
+ Stable tag: 1.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
43
 
44
  **Dont use a featured image on page 5**
45
 
46
+ function dfi_skip_page( $dfi_id ) {
47
  if ( is_single( 5 ) || get_the_ID() == 5 ) {
48
+ return 0; // invalid id
49
  }
50
+ return $dfi_id; // the original featured image id
51
+ }
52
+ add_filter('dfi_thumbnail_id', 'dfi_skip_page' );
53
 
 
54
 
55
+ **Use a different image on the "book" posttype. The ID of the image is 12**
56
+
57
+ function dfi_posttype_book( $dfi_id ) {
58
+ if ( is_singular( 'book' ) || get_post_type() == 'book' ) {
59
+ return 12; // the image id
60
  }
61
+ return $dfi_id; // the original featured image id
62
+ }
63
+ add_filter('dfi_thumbnail_id', 'dfi_posttype_book' );
64
+
65
+ **Use a different image on certain categories**
66
+
67
+ function dfi_category( $dfi_id ) {
68
+ if ( has_category( 'category-slug' ) ) {
69
+ return 13; // the image id
70
+ } else if ( has_category( 'other_category' ) ) {
71
+ return 14; // the image id
72
+ }
73
+ return $dfi_id; // the original featured image id
74
+ }
75
+ add_filter('dfi_thumbnail_id', 'dfi_category' );
76
 
77
  = Can I change the HTML of the image returned? =
78
  yes you can with the filter `dfi_thumbnail_html`.
79
 
80
  function dfi_add_class($html, $post_id, $default_thumbnail_id, $size, $attr) {
81
  // add a class to the existing class list
82
+ $attr['class'] .= ' my-class';
83
 
84
  return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
85
  }
101
  * The default featured image will now also return with `get_post_thumbnail_id`, making the chance that it fail far far smaller.
102
  * The image given in the media page is now validated
103
 
104
+ = 1.1 =
105
+ * Fixed inheriting classes of the image
106
+
107
  == Upgrade Notice ==
108
 
109
  = 1.0 =
set-default-featured-image.php CHANGED
@@ -196,7 +196,12 @@ class default_featured_image
196
  // allow to set an other ID see the readme.txt for details
197
  $default_thumbnail_id = apply_filters( 'dfi_thumbnail_id', $default_thumbnail_id );
198
 
199
- $attr['class'] = "attachment-{$size} default-featured-img";
 
 
 
 
 
200
 
201
  $html = wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
202
  $html = apply_filters( 'dfi_thumbnail_html', $html, $post_id, $default_thumbnail_id, $size, $attr );
196
  // allow to set an other ID see the readme.txt for details
197
  $default_thumbnail_id = apply_filters( 'dfi_thumbnail_id', $default_thumbnail_id );
198
 
199
+ if (isset($attr['class']) ) {
200
+ $attr['class'] .= " default-featured-img";
201
+ } else {
202
+ //attachment-$size is a default class `wp_get_attachment_image` would otherwise add. It won't add it if there are classes already there
203
+ $attr['class'] = "attachment-{$size} default-featured-img";
204
+ }
205
 
206
  $html = wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
207
  $html = apply_filters( 'dfi_thumbnail_html', $html, $post_id, $default_thumbnail_id, $size, $attr );