Version Description
- Launch
Download this release
Release Info
Developer | janw.oostendorp |
Plugin | Default featured image |
Version | 0.9 |
Comparing to | |
See all releases |
Version 0.9
- languages/default-featured-image-nl_NL.mo +0 -0
- languages/default-featured-image-nl_NL.po +39 -0
- readme.txt +77 -0
- set-default-featured-image.js +107 -0
- set-default-featured-image.php +165 -0
languages/default-featured-image-nl_NL.mo
ADDED
Binary file
|
languages/default-featured-image-nl_NL.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
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: janwoostendorp
|
3 |
+
Tags: media, image
|
4 |
+
Requires at least: 3.5
|
5 |
+
Tested up to: 3.5
|
6 |
+
Stable tag: 0.9
|
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 |
+
If you want to use a different image on certain occasions use the `dfi_thumbnail_id` filter like:
|
17 |
+
|
18 |
+
<?php //this will work in your themes functions.php
|
19 |
+
// Don't use a featured image on page 5
|
20 |
+
add_action('template_redirect', function () {
|
21 |
+
if ( is_single() ) {
|
22 |
+
add_filter('dfi_thumbnail_id', function () { return 0; } );
|
23 |
+
}
|
24 |
+
});
|
25 |
+
|
26 |
+
// use a different image on the "book" posttype, it's id is 12
|
27 |
+
add_action('template_redirect', function () {
|
28 |
+
if ( is_single() ) {
|
29 |
+
add_filter('dfi_thumbnail_id', function () { return 12; } );
|
30 |
+
}
|
31 |
+
});
|
32 |
+
?>
|
33 |
+
= Suggestions are welcome =
|
34 |
+
* Found a bug?
|
35 |
+
* Want to help to translate it in your language?
|
36 |
+
* Something to be improved?
|
37 |
+
|
38 |
+
[Contact me](http://wordpress.org/support/plugin/default-featured-image)
|
39 |
+
|
40 |
+
== Installation ==
|
41 |
+
|
42 |
+
1. Unzip the folder to the `/wp-content/plugins/` directory
|
43 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
44 |
+
3. Go to the settigns->media page and select an image.
|
45 |
+
|
46 |
+
|
47 |
+
== Frequently Asked Questions ==
|
48 |
+
|
49 |
+
= can I exclude a page or give it a different image? =
|
50 |
+
|
51 |
+
yes. you can exclude all kinds of things with the [conditional tags](http://codex.wordpress.org/Conditional_Tags).
|
52 |
+
|
53 |
+
<?php //this will work in your themes functions.php
|
54 |
+
// Dont use a featured image on page 5
|
55 |
+
add_action('template_redirect', function () {
|
56 |
+
if ( is_single() ) {
|
57 |
+
add_filter('dfi_thumbnail_id', function () { return 0; } );
|
58 |
+
}
|
59 |
+
});
|
60 |
+
|
61 |
+
// use a different image on the "book" posttype, it's id is 12
|
62 |
+
add_action('template_redirect', function () {
|
63 |
+
if ( is_single() ) {
|
64 |
+
add_filter('dfi_thumbnail_id', function () { return 12; } );
|
65 |
+
}
|
66 |
+
});
|
67 |
+
?>
|
68 |
+
|
69 |
+
== Screenshots ==
|
70 |
+
|
71 |
+
1. The button and preview as it appears on the settings page
|
72 |
+
2. The media manager will start with the current selected image
|
73 |
+
|
74 |
+
== Changelog ==
|
75 |
+
|
76 |
+
= 0.9 =
|
77 |
+
* Launch
|
set-default-featured-image.js
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(document).ready(function ($) {
|
2 |
+
'use strict';
|
3 |
+
|
4 |
+
var $set_button = $('#dfi-set-dfi'),
|
5 |
+
$td = $set_button.parent(),
|
6 |
+
$hidden_input = $td.find('#dfi_id'),
|
7 |
+
$del_button = $td.find('#dfi-no-fdi');
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @param html the preview html
|
11 |
+
*/
|
12 |
+
function set_preview_html(html) {
|
13 |
+
var $cur_preview = $td.find('#preview-image');
|
14 |
+
// remove old
|
15 |
+
$cur_preview.remove();
|
16 |
+
// prepend new
|
17 |
+
$td.prepend(html);
|
18 |
+
//disable button
|
19 |
+
$del_button.removeClass('button-disabled');
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @param image_id int
|
24 |
+
* @return html string with the image
|
25 |
+
*/
|
26 |
+
function set_preview_image(image_id) {
|
27 |
+
var responseText,
|
28 |
+
data = {
|
29 |
+
action: 'dfi_change_preview',
|
30 |
+
image_id: image_id
|
31 |
+
};
|
32 |
+
|
33 |
+
$.post(ajaxurl, data, function (response) {
|
34 |
+
set_preview_html(response);
|
35 |
+
});
|
36 |
+
|
37 |
+
return responseText;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* set a loading image untill the ajax is ready
|
42 |
+
*/
|
43 |
+
function set_loading_image() {
|
44 |
+
var $cur_preview = $td.find('#preview-image'),
|
45 |
+
html = '<div id="preview-image" style="float:left; padding: 0 5px 0 0; height: 60px;"><img src="images/loading.gif"/></div>';
|
46 |
+
|
47 |
+
$cur_preview.remove();
|
48 |
+
$td.prepend(html);
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @param selected_id the selected image id
|
53 |
+
*/
|
54 |
+
function set_dfi(selected_id) {
|
55 |
+
$hidden_input.val(selected_id);
|
56 |
+
// set preview
|
57 |
+
set_loading_image();
|
58 |
+
set_preview_image(selected_id);
|
59 |
+
}
|
60 |
+
|
61 |
+
// remove featured image
|
62 |
+
$del_button.click(function (e) {
|
63 |
+
e.preventDefault();
|
64 |
+
var $cur_preview = $td.find('#preview-image');
|
65 |
+
$cur_preview.remove();
|
66 |
+
$hidden_input.val('');
|
67 |
+
$(this).addClass('button-disabled');
|
68 |
+
});
|
69 |
+
|
70 |
+
/**
|
71 |
+
* open the media manager
|
72 |
+
*/
|
73 |
+
$set_button.click(function (e) {
|
74 |
+
e.preventDefault();
|
75 |
+
var frame = wp.media({
|
76 |
+
title : dfi_L10n.manager_title,
|
77 |
+
multiple : false,
|
78 |
+
library : { type : 'image' },
|
79 |
+
button : { text : dfi_L10n.manager_button }
|
80 |
+
});
|
81 |
+
// close event media manager
|
82 |
+
frame.on('close', function () {
|
83 |
+
var images = frame.state().get('selection');
|
84 |
+
// set the images
|
85 |
+
images.each(function (image) {
|
86 |
+
set_dfi(image.id);
|
87 |
+
});
|
88 |
+
});
|
89 |
+
|
90 |
+
// open event media manager
|
91 |
+
frame.on('open', function () {
|
92 |
+
var attachment,
|
93 |
+
selection = frame.state().get('selection'),
|
94 |
+
id = $hidden_input.val();
|
95 |
+
|
96 |
+
attachment = wp.media.attachment(id);
|
97 |
+
attachment.fetch();
|
98 |
+
|
99 |
+
selection.add(attachment ? [ attachment ] : []);
|
100 |
+
});
|
101 |
+
|
102 |
+
// everthing is set open the media manager
|
103 |
+
frame.open();
|
104 |
+
});
|
105 |
+
|
106 |
+
|
107 |
+
}); // doc rdy
|
set-default-featured-image.php
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 feartured image in the media settings
|
6 |
+
Version: 0.9
|
7 |
+
Author: Jan Willem Oostendorp
|
8 |
+
License: GPLv2 or later
|
9 |
+
*/
|
10 |
+
|
11 |
+
class default_featured_image
|
12 |
+
{
|
13 |
+
const L10n = 'default-featured-image';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Hook everything
|
17 |
+
*/
|
18 |
+
function __construct() {
|
19 |
+
// add the settings field to the media page
|
20 |
+
add_action( 'admin_init', array( &$this, 'media_setting' ) );
|
21 |
+
// enqueue the js
|
22 |
+
add_action( 'admin_print_scripts-options-media.php', array( &$this, 'admin_scripts' ) );
|
23 |
+
// get the preview image ajaxs call
|
24 |
+
add_action( 'wp_ajax_dfi_change_preview', array( &$this, 'ajax_wrapper' ) );
|
25 |
+
// display a default featured image
|
26 |
+
add_filter( 'post_thumbnail_html', array( &$this, 'show_dfi' ), 10, 5 );
|
27 |
+
// add a link on the plugin page to the setting
|
28 |
+
add_filter('plugin_action_links', array(&$this, 'add_settings_link'), 10, 2 );
|
29 |
+
// add L10n
|
30 |
+
add_action( 'init', array(&$this, 'L10n') );
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
+
function L10n() {
|
35 |
+
load_plugin_textdomain(self::L10n, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* register the setting on the media settings page
|
40 |
+
*/
|
41 |
+
function media_setting() {
|
42 |
+
register_setting(
|
43 |
+
'media', // settings page
|
44 |
+
'dfi_image_id', // option name
|
45 |
+
array( &$this, 'input_validation' ) // validation callback
|
46 |
+
);
|
47 |
+
add_settings_field(
|
48 |
+
'dfi', // id
|
49 |
+
__( 'Default featured image', self::L10n ), // setting title
|
50 |
+
array( &$this, 'settings_html' ), // display callback
|
51 |
+
'media', // settings page
|
52 |
+
'default' // settings section
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* display the buttons and a preview
|
58 |
+
*/
|
59 |
+
function settings_html() {
|
60 |
+
$value = get_option( 'dfi_image_id' );
|
61 |
+
|
62 |
+
$rm_btn_class = 'button button-disabled';
|
63 |
+
if ( !empty( $value ) ) {
|
64 |
+
echo $this->preview_image( $value );
|
65 |
+
$rm_btn_class = 'button';
|
66 |
+
}
|
67 |
+
?>
|
68 |
+
<input id="dfi_id" type="hidden" value="<?php echo esc_attr( $value ); ?>" name="dfi_image_id"/>
|
69 |
+
|
70 |
+
<a id="dfi-set-dfi" class="button" title="<?php _e( 'Select default featured image', self::L10n ) ?>" href="#">
|
71 |
+
<span class="icon16 icon-media"></span>
|
72 |
+
<?php _e( 'Select default featured image', self::L10n ) ?>
|
73 |
+
</a>
|
74 |
+
<div style="margin-top:5px;">
|
75 |
+
<a id="dfi-no-fdi" class="<?php echo $rm_btn_class ?>" title="<?php _e( 'Don\'t use a default featured image', self::L10n ) ?>" href="#">
|
76 |
+
<?php _e( 'Don\'t use a default featured image', self::L10n ) ?>
|
77 |
+
</a>
|
78 |
+
</div>
|
79 |
+
<?php
|
80 |
+
}
|
81 |
+
|
82 |
+
// Validate user input
|
83 |
+
function input_validation( $input ) {
|
84 |
+
//@todo Validation
|
85 |
+
return $input;
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Register the javascript
|
90 |
+
*/
|
91 |
+
function admin_scripts() {
|
92 |
+
wp_enqueue_media(); // scripts used for uploader
|
93 |
+
wp_enqueue_script( 'dfi-script', plugin_dir_url( __FILE__ ) . 'set-default-featured-image.js' );
|
94 |
+
wp_localize_script('dfi-script', 'dfi_L10n', array(
|
95 |
+
'manager_title' => __('Select default featured image', self::L10n),
|
96 |
+
'manager_button' => __('Set default featured image', self::L10n),
|
97 |
+
));
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* get an image and wrap it in a div
|
102 |
+
* @param int $image_id
|
103 |
+
* @return string
|
104 |
+
*/
|
105 |
+
function preview_image( $image_id ) {
|
106 |
+
$output = '<div id="preview-image" style="float:left; padding: 0 5px 0 0;">';
|
107 |
+
$output .= wp_get_attachment_image( $image_id, array( 80, 60 ), true );
|
108 |
+
$output .= '</div>';
|
109 |
+
return $output;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* The callback for the ajax call when the DFI changes
|
114 |
+
*/
|
115 |
+
function ajax_wrapper() {
|
116 |
+
if ( isset( $_POST['image_id'] ) ) {
|
117 |
+
echo $this->preview_image( $_POST['image_id'] );
|
118 |
+
}
|
119 |
+
die(); // ajax call
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* add a settings link to the the plugin on the plugin page
|
124 |
+
* @param array $links
|
125 |
+
* @param string $file
|
126 |
+
* @return array
|
127 |
+
*/
|
128 |
+
function add_settings_link( $links, $file ) {
|
129 |
+
|
130 |
+
if ( $file == plugin_basename( __FILE__ ) ) {
|
131 |
+
$settings_link = '<a href="options-media.php#dfi-set-dfi">' . __( 'Settings' )/*get this from WP core*/ . '</a>';
|
132 |
+
array_unshift( $links, $settings_link );
|
133 |
+
}
|
134 |
+
return $links;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Set a default featured image if it is missing
|
139 |
+
* @param sting $html
|
140 |
+
* @param int $post_id
|
141 |
+
* @param int $post_thumbnail_id
|
142 |
+
* @param string $size
|
143 |
+
* @param array $attr
|
144 |
+
* @return string
|
145 |
+
*/
|
146 |
+
function show_dfi( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
|
147 |
+
// if an image is set return the image
|
148 |
+
if ( !empty( $html ) ) {
|
149 |
+
return $html;
|
150 |
+
}
|
151 |
+
|
152 |
+
$default_thumbnail_id = get_option( 'default_featured_image' ); //select the default thumb
|
153 |
+
$default_thumbnail_id = apply_filters( 'dfi_thumbnail_id', $default_thumbnail_id );
|
154 |
+
|
155 |
+
//set title to post
|
156 |
+
$attr['title'] = get_the_title(); //@todo still usefull?
|
157 |
+
|
158 |
+
$html = wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
|
159 |
+
$html = apply_filters( 'dfi_thumbnail_html', $html, $post_id, $default_thumbnail_id, $size, $attr );
|
160 |
+
|
161 |
+
return $html;
|
162 |
+
}
|
163 |
+
}
|
164 |
+
//run the plugin class
|
165 |
+
new default_featured_image();
|