Unique Headers - Version 1.3.7

Version Description

Download this release

Release Info

Developer ryanhellyer
Plugin Icon wp plugin Unique Headers
Version 1.3.7
Comparing to
See all releases

Code changes from version 1.2.1 to 1.3.7

assets/admin.css ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ .custom-meta-image-container img {
2
+ width: 100%;
3
+ height: auto;
4
+ }
5
+ .custom-meta-image-info {
6
+ display: none;
7
+ }
assets/admin.js ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /**
3
+ * Callback function for the 'click' event of the 'Set Footer Image'
4
+ * anchor in its meta box.
5
+ *
6
+ * Displays the media uploader for selecting an image.
7
+ *
8
+ * @param object $ A reference to the jQuery object
9
+ * @since 0.1.0
10
+ */
11
+ function renderMediaUploader( $ ) {
12
+ 'use strict';
13
+
14
+ var file_frame, image_data, json;
15
+
16
+ /**
17
+ * If an instance of file_frame already exists, then we can open it
18
+ * rather than creating a new instance.
19
+ */
20
+ if ( undefined !== file_frame ) {
21
+
22
+ file_frame.open();
23
+ return;
24
+
25
+ }
26
+
27
+ /**
28
+ * If we're this far, then an instance does not exist, so we need to
29
+ * create our own.
30
+ *
31
+ * Here, use the wp.media library to define the settings of the Media
32
+ * Uploader. We're opting to use the 'post' frame which is a template
33
+ * defined in WordPress core and are initializing the file frame
34
+ * with the 'insert' state.
35
+ *
36
+ * We're also not allowing the user to select more than one image.
37
+ */
38
+ file_frame = wp.media.frames.file_frame = wp.media({
39
+ frame: 'post',
40
+ state: 'insert',
41
+ multiple: false
42
+ });
43
+
44
+ /**
45
+ * Setup an event handler for what to do when an image has been
46
+ * selected.
47
+ *
48
+ * Since we're using the 'view' state when initializing
49
+ * the file_frame, we need to make sure that the handler is attached
50
+ * to the insert event.
51
+ */
52
+ file_frame.on( 'insert', function() {
53
+
54
+ // Read the JSON data returned from the Media Uploader
55
+ json = file_frame.state().get( 'selection' ).first().toJSON();
56
+
57
+ // First, make sure that we have the URL of an image to display
58
+ if ( 0 > $.trim( json.url.length ) ) {
59
+ return;
60
+ }
61
+
62
+ // After that, set the properties of the image and display it
63
+ $( '#'+custom_meta_image_name+'-container' )
64
+ .children( 'img' )
65
+ .attr( 'src', json.url )
66
+ .attr( 'alt', json.caption )
67
+ .attr( 'title', json.title )
68
+ .show()
69
+ .parent()
70
+ .removeClass( 'hidden' );
71
+
72
+ // Next, hide the anchor responsible for allowing the user to select an image
73
+ $( '#'+custom_meta_image_name+'-container' )
74
+ .prev()
75
+ .hide();
76
+
77
+ // Display the anchor for the removing the featured image
78
+ $( '#'+custom_meta_image_name+'-container' )
79
+ .next()
80
+ .show();
81
+
82
+ // Store the image's information into the meta data fields
83
+ $( '#'+custom_meta_image_name+'-id' ).val( json.id );
84
+
85
+ });
86
+
87
+ // Now display the actual file_frame
88
+ file_frame.open();
89
+
90
+ }
91
+
92
+ /**
93
+ * Callback function for the 'click' event of the 'Remove Footer Image'
94
+ * anchor in its meta box.
95
+ *
96
+ * Resets the meta box by hiding the image and by hiding the 'Remove
97
+ * Footer Image' container.
98
+ *
99
+ * @param object $ A reference to the jQuery object
100
+ * @since 0.2.0
101
+ */
102
+ function resetUploadForm( $ ) {
103
+ 'use strict';
104
+
105
+ // First, we'll hide the image
106
+ $( '#'+custom_meta_image_name+'-container' )
107
+ .children( 'img' )
108
+ .hide();
109
+
110
+ // Then display the previous container
111
+ $( '#'+custom_meta_image_name+'-container' )
112
+ .prev()
113
+ .show();
114
+
115
+ // We add the 'hidden' class back to this anchor's parent
116
+ $( '#'+custom_meta_image_name+'-container' )
117
+ .next()
118
+ .hide()
119
+ .addClass( 'hidden' );
120
+
121
+ // Finally, we reset the meta data input fields
122
+ $( '#'+custom_meta_image_name+'-info' )
123
+ .children()
124
+ .val( '' );
125
+
126
+ }
127
+
128
+ /**
129
+ * Checks to see if the input field for the thumbnail source has a value.
130
+ * If so, then the image and the 'Remove featured image' anchor are displayed.
131
+ *
132
+ * Otherwise, the standard anchor is rendered.
133
+ *
134
+ * @param object $ A reference to the jQuery object
135
+ * @since 1.0.0
136
+ */
137
+ function renderFeaturedImage( $ ) {
138
+
139
+ /* If a thumbnail URL has been associated with this image
140
+ * Then we need to display the image and the reset link.
141
+ */
142
+ if ( '' !== $.trim ( $( '#'+custom_meta_image_name+'-id' ).val() ) ) {
143
+
144
+ $( '#'+custom_meta_image_name+'-container' ).removeClass( 'hidden' );
145
+
146
+ $( '#set-'+custom_meta_image_name+'-thumbnail' )
147
+ .parent()
148
+ .hide();
149
+
150
+ $( '#remove-'+custom_meta_image_name+'-thumbnail' )
151
+ .parent()
152
+ .removeClass( 'hidden' );
153
+
154
+ }
155
+
156
+ }
157
+
158
+ (function( $ ) {
159
+ 'use strict';
160
+
161
+ $(function() {
162
+
163
+ renderFeaturedImage( $ );
164
+
165
+ $( '#set-'+custom_meta_image_name+'-thumbnail' ).on( 'click', function( evt ) {
166
+
167
+ // Stop the anchor's default behavior
168
+ evt.preventDefault();
169
+
170
+ // Display the media uploader
171
+ renderMediaUploader( $ );
172
+
173
+ });
174
+
175
+ $( '#remove-'+custom_meta_image_name+'-thumbnail' ).on( 'click', function( evt ) {
176
+
177
+ // Stop the anchor's default behavior
178
+ evt.preventDefault();
179
+
180
+ // Remove the image, toggle the anchors
181
+ resetUploadForm( $ );
182
+
183
+ });
184
+
185
+ });
186
+
187
+ })( jQuery );
inc/class-custom-image-meta-box.php ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Add a custom image meta box
5
+ *
6
+ * @copyright Copyright (c), Ryan Hellyer
7
+ * @license http://www.gnu.org/licenses/gpl.html GPL
8
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
9
+ * @since 1.3
10
+ */
11
+ class Custom_Image_Meta_Box {
12
+
13
+ /**
14
+ * The name of the image meta
15
+ *
16
+ * @since 1.3
17
+ * @access private
18
+ * @var string $name
19
+ */
20
+ private $name;
21
+
22
+ /**
23
+ * The name of the image meta, with forced underscores instead of dashes
24
+ * This is to ensure that meta keys and filters do not use dashes.
25
+ *
26
+ * @since 1.3
27
+ * @access private
28
+ * @var string $name_underscores
29
+ */
30
+ private $name_underscores;
31
+
32
+ /**
33
+ * The directory URI, for accessing JS and CSS files
34
+ *
35
+ * @since 1.3
36
+ * @access private
37
+ * @var string $dir_uri
38
+ */
39
+ private $dir_uri;
40
+
41
+ /**
42
+ * The title of the meta box
43
+ *
44
+ * @since 1.3
45
+ * @access private
46
+ * @var string $title
47
+ */
48
+ private $title;
49
+
50
+ /**
51
+ * The set custom image text
52
+ *
53
+ * @since 1.3
54
+ * @access private
55
+ * @var string $set_custom_image
56
+ */
57
+ private $set_custom_image;
58
+
59
+ /**
60
+ * The remove custom image text
61
+ *
62
+ * @since 1.3
63
+ * @access private
64
+ * @var string $remove_custom_image
65
+ */
66
+ private $remove_custom_image;
67
+
68
+ /**
69
+ * The current version of the class
70
+ *
71
+ * @since 1.3
72
+ * @access private
73
+ * @var string $version
74
+ */
75
+ private $version = '1.3';
76
+
77
+ /**
78
+ * The post types to add meta boxes to
79
+ *
80
+ * @since 1.3
81
+ * @access private
82
+ * @var string $post_types
83
+ */
84
+ private $post_types;
85
+
86
+ /**
87
+ * Class constructor
88
+ * Adds methods to appropriate hooks
89
+ *
90
+ * @since 1.3
91
+ */
92
+ public function __construct( $args ) {
93
+
94
+ $this->name = $args['name'];
95
+ $this->name_underscores = str_replace( '-', '_', $args['name'] );
96
+ $this->dir_uri = $args['dir_uri'];
97
+ $this->title = $args['title'];
98
+ $this->set_custom_image = $args['set_custom_image'];
99
+ $this->remove_custom_image = $args['remove_custom_image'];
100
+ $this->post_types = $args['post_types'];
101
+
102
+ // Add meta box
103
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
104
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
105
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
106
+ add_action( 'save_post', array( $this, 'save_post' ) );
107
+
108
+ }
109
+
110
+ /*
111
+ * Get the attachment ID from the post ID
112
+ *
113
+ * @since 1.3
114
+ * @access static This method is static so that front-end scripts can access the attachment ID
115
+ * @param int $post_id The post ID
116
+ * @return int $attachment_id The attachment ID
117
+ */
118
+ static function get_attachment_id( $post_id, $name ) {
119
+
120
+ $attachment_id = get_post_meta( $post_id, '_' . $name . '_id', true );
121
+
122
+ // Check for fallback images
123
+ if ( '' == $attachment_id ) {
124
+ $attachment_id = apply_filters( $name . '_fallback_images', $post_id );
125
+ }
126
+
127
+ return $attachment_id;
128
+ }
129
+
130
+ /*
131
+ * Get the attachment URL from the attachment ID
132
+ *
133
+ * @since 1.3
134
+ * @access static This method is static so that front-end scripts can access the attachments SRC
135
+ * @param int $attachment_id The attachment ID
136
+ * @return string
137
+ */
138
+ static function get_attachment_src( $attachment_id ) {
139
+
140
+ // Grab URL from WordPress
141
+ $url = wp_get_attachment_image_src( $attachment_id, 'full' );
142
+ $url = $url[0];
143
+
144
+ return $url;
145
+ }
146
+
147
+ /**
148
+ * Registers the JavaScript for handling the media uploader.
149
+ *
150
+ * @since 1.3
151
+ * @access static This method is static so that front-end scripts can access the attachments title
152
+ * @param int $attachment_id The attachment ID
153
+ * @return string $title The attachment title
154
+ */
155
+ static function get_attachment_title( $attachment_id ) {
156
+
157
+ // Get title (trip and strip_tags method was adapted from WordPress core)
158
+ $title = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
159
+
160
+ return $title;
161
+ }
162
+
163
+ /**
164
+ * Renders the meta box on the post and pages.
165
+ *
166
+ * @since 1.3
167
+ */
168
+ public function add_meta_box() {
169
+
170
+ foreach ( $this->post_types as $screen ) {
171
+
172
+ add_meta_box(
173
+ $this->name,
174
+ $this->title,
175
+ array( $this, 'display_custom_meta_image' ),
176
+ $screen,
177
+ 'side'
178
+ );
179
+
180
+ }
181
+
182
+ }
183
+
184
+ /**
185
+ * Registers the JavaScript for handling the media uploader.
186
+ *
187
+ * @since 1.3
188
+ */
189
+ public function enqueue_scripts() {
190
+
191
+ wp_enqueue_media();
192
+
193
+ wp_enqueue_script(
194
+ $this->name,
195
+ $this->dir_uri . '/admin.js',
196
+ array( 'jquery' ),
197
+ $this->version,
198
+ 'all'
199
+ );
200
+
201
+ wp_localize_script( $this->name, 'custom_meta_image_name', $this->name );
202
+
203
+ }
204
+
205
+ /**
206
+ * Registers the stylesheets for handling the meta box
207
+ *
208
+ * @since 1.3
209
+ */
210
+ public function enqueue_styles() {
211
+
212
+ wp_enqueue_style(
213
+ $this->name,
214
+ $this->dir_uri . '/admin.css',
215
+ array()
216
+ );
217
+
218
+ }
219
+
220
+ /**
221
+ * Sanitized and saves the post featured footer image meta data specific with this post.
222
+ *
223
+ * @since 1.3
224
+ * @param int $post_id The ID of the post with which we're currently working.
225
+ * @return int $post_id The ID of the post with which we're currently working.
226
+ */
227
+ public function save_post( $post_id ) {
228
+
229
+ // Bail out now if POST vars not set
230
+ if ( ! isset( $_POST[$this->name . '-nonce'] ) || ! isset( $_POST[$this->name . '-id'] ) ) {
231
+ return $post_id;
232
+ }
233
+
234
+ // Bail out now if nonce doesn't verify
235
+ if ( ! wp_verify_nonce( $_POST[$this->name . '-nonce'], $this->name ) ) {
236
+ return $post_id;
237
+ }
238
+
239
+ // Sanitize the attachment ID
240
+ $attachment_id = sanitize_text_field( $_POST[$this->name . '-id'] );
241
+
242
+ // Save the attachment ID in the database
243
+ update_post_meta( $post_id, '_' . $this->name_underscores . '_id', $attachment_id );
244
+
245
+ // Return the post ID
246
+ return $post_id;
247
+ }
248
+
249
+ /**
250
+ * Renders the view that displays the contents for the meta box that for triggering
251
+ * the meta box.
252
+ *
253
+ * @param WP_Post $post The post object
254
+ * @since 1.3
255
+ */
256
+ public function display_custom_meta_image( $post ) {
257
+
258
+ // Get required values
259
+ $attachment_id = $this->get_attachment_id( $post->ID, $this->name_underscores );
260
+ $url = $this->get_attachment_src( $attachment_id );
261
+ $title = $this->get_attachment_title( $attachment_id );
262
+
263
+ wp_nonce_field( $this->name, $this->name . '-nonce' );
264
+ ?>
265
+
266
+ <p class="hide-if-no-js">
267
+ <a title="<?php echo esc_attr( $this->set_custom_image ); ?>" href="javascript:;" id="<?php echo esc_attr( 'set-' . $this->name . '-thumbnail' ); ?>" class="set-custom-meta-image-thumbnail"><?php echo esc_html( $this->set_custom_image ); ?></a>
268
+ </p>
269
+
270
+ <div id="<?php echo esc_attr( $this->name . '-container' ); ?>" class="custom-meta-image-container hidden">
271
+ <img src="<?php echo esc_url( $url ); ?>" alt="<?php echo esc_attr( $title ); ?>" title="<?php echo esc_attr( $title ); ?>" />
272
+ </div><!-- #<?php esc_attr( $this->name . '-image-container' ); ?> -->
273
+
274
+ <p class="hide-if-no-js hidden">
275
+ <a title="<?php echo esc_attr( $this->remove_custom_image ); ?>" href="javascript:;" id="<?php echo esc_attr( 'remove-' . $this->name . '-thumbnail' ); ?>" class="remove-custom-meta-image-thumbnail"><?php echo esc_html( $this->remove_custom_image ); ?></a>
276
+ </p><!-- .hide-if-no-js -->
277
+
278
+ <p id="<?php echo esc_attr( $this->name . '-info' ); ?>" class="custom-meta-image-info">
279
+ <input type="hidden" id="<?php echo esc_attr( $this->name . '-id' ); ?>" class="custom-meta-image-id" name="<?php echo esc_attr( $this->name . '-id' ); ?>" value="<?php echo esc_attr( $attachment_id ); ?>" />
280
+ </p><!-- #<?php echo esc_attr( $this->name . '-image-info' ); ?> --><?php
281
+
282
+ return $post;
283
+ }
284
+
285
+ }
inc/class-kd-multiple-featured-images.php DELETED
@@ -1,373 +0,0 @@
1
- <?php
2
-
3
- /*
4
- Copied from the Multiple Featured Images plugin version 0.3.
5
- Changes made:
6
- Changed "$this->nonce = 'mfi-'.$this->args['id'].$this->args['post_type'];" to "$this->nonce = 'mfi-'.$args['id'].$args['post_type'];" to remove a PHP error
7
- Changed URL to JS file
8
- Converted spaces to tabs
9
- Removed trailing ?>
10
-
11
-
12
- Copyright 2012 Marcus Kober (m.kober@koeln-dialog.de)
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License, version 2, as
16
- published by the Free Software Foundation.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
- */
27
-
28
- if( !class_exists( 'kdMultipleFeaturedImages' ) ) {
29
-
30
- class kdMultipleFeaturedImages {
31
-
32
- private $id = '';
33
- private $post_type = '';
34
- private $labels = array();
35
-
36
- private $metabox_id = '';
37
-
38
- private $post_meta_key = '';
39
-
40
- private $nonce = '';
41
-
42
- private $default_labels = array(
43
- 'name' => 'Featured Image 2',
44
- 'set' => 'Set featured image 2',
45
- 'remove' => 'Remove featured image 2',
46
- 'use' => 'Use as featured image 2',
47
- );
48
-
49
- private $default_args = array(
50
- 'id' => 'featured-image-2',
51
- 'post_type' => 'page',
52
- );
53
-
54
- /**
55
- * Initialize the plugin
56
- *
57
- * @param array $args
58
- * @return void
59
- */
60
- public function __construct( $args ) {
61
- $this->labels = wp_parse_args( $args['labels'], $this->default_labels );
62
- unset( $args['labels'] );
63
- $args = wp_parse_args( $args, $this->default_args );
64
- $this->id = $args['id'];
65
- $this->post_type = $args['post_type'];
66
-
67
- $this->metabox_id = $this->id.'_'.$this->post_type;
68
-
69
- $this->post_meta_key= 'kd_'.$this->id.'_'.$this->post_type.'_id';
70
-
71
- $this->nonce = 'mfi-'.$args['id'].$args['post_type'];
72
-
73
- if( !current_theme_supports( 'post-thumbnails' ) ) {
74
- add_theme_support( 'post-thumbnails' );
75
- }
76
-
77
- add_action( 'admin_init', array( &$this, 'kd_admin_init' ) );
78
- add_action( 'add_meta_boxes', array( &$this, 'kd_add_meta_box' ) );
79
- add_filter( 'attachment_fields_to_edit', array( &$this, 'kd_add_attachment_field' ), 11, 2 );
80
-
81
- add_action( 'wp_ajax_set-MuFeaImg-'.$this->id.'-'.$this->post_type, array( &$this, 'kd_ajax_set_image' ) );
82
-
83
- add_action( 'delete_attachment', array( &$this, 'kd_delete_attachment' ) );
84
-
85
- }
86
-
87
- /**
88
- * Add admin-Javascript
89
- *
90
- * @return void
91
- */
92
- public function kd_admin_init() {
93
- wp_enqueue_script(
94
- 'kd-multiple-featured-images',
95
- UNIQUEHEADERS_URL . '/js/kd-admin.js',
96
- 'jquery'
97
- );
98
- }
99
-
100
- /**
101
- * Add admin metabox for choosing additional featured images
102
- *
103
- * @return void
104
- */
105
- public function kd_add_meta_box() {
106
- add_meta_box(
107
- $this->metabox_id,
108
- $this->labels['name'],
109
- array( $this, 'kd_meta_box_content' ),
110
- $this->post_type,
111
- 'side',
112
- 'low'
113
- );
114
- }
115
-
116
- /**
117
- * Output the metabox content
118
- *
119
- * @global object $post
120
- * @return void
121
- */
122
- public function kd_meta_box_content() {
123
- global $post;
124
-
125
- $image_id = get_post_meta(
126
- $post->ID,
127
- $this->post_meta_key,
128
- true
129
- );
130
-
131
- echo $this->kd_meta_box_output( $image_id );
132
- }
133
-
134
- /**
135
- * Generate the metabox content
136
- *
137
- * @global int $post_ID
138
- * @param int $image_id
139
- * @return string
140
- */
141
- public function kd_meta_box_output( $image_id = NULL ) {
142
- global $post_ID;
143
-
144
- $output = '';
145
-
146
- $setImageLink = sprintf(
147
- '<p class="hide-if-no-js"><a title="%2$s" href="%1$s" id="kd_%3$s" class="thickbox">%%s</a></p>',
148
- get_upload_iframe_src( 'image' ),
149
- $this->labels['set'],
150
- $this->id
151
- );
152
-
153
- if( $image_id && get_post( $image_id ) ) {
154
- $nonce_field = wp_create_nonce( $this->nonce.$post_ID );
155
-
156
- $thumbnail = wp_get_attachment_image( $image_id, array( 266, 266 ) );
157
- $output.= sprintf( $setImageLink, $thumbnail );
158
- $output.= '<p class="hide-if-no-js">';
159
- $output.= sprintf(
160
- '<a href="#" id="remove-%1$s-image" onclick="kdMuFeaImgRemove( \'%1$s\', \'%2$s\', \'%3$s\' ); return false;">',
161
- $this->id,
162
- $this->post_type,
163
- $nonce_field
164
- );
165
- $output.= $this->labels['remove'];
166
- $output.= '</a>';
167
- $output.= '</p>';
168
-
169
- return $output;
170
- }
171
- else {
172
- return sprintf( $setImageLink, $this->labels['set'] );
173
- }
174
-
175
- }
176
-
177
- /**
178
- * Create a new field in the image upload form
179
- *
180
- * @param string $form_fields
181
- * @param object $post
182
- * @return string
183
- */
184
- public function kd_add_attachment_field( $form_fields, $post ) {
185
- $calling_id = 0;
186
- if( isset( $_GET['post_id'] ) ) {
187
- $calling_id = absint( $_GET['post_id'] );
188
- }
189
- elseif( isset( $_POST ) && count( $_POST ) ) {
190
- $calling_id = $post->post_parent;
191
- }
192
-
193
- $calling_post = get_post( $calling_id );
194
-
195
- if( is_null( $calling_post ) || $calling_post->post_type != $this->post_type ) {
196
- return $form_fields;
197
- }
198
-
199
- $nonce_field = wp_create_nonce( $this->nonce.$calling_id );
200
-
201
- $output = sprintf(
202
- '<a href="#" id="%1$s-featuredimage" onclick="kdMuFeaImgSet( %3$s, \'%1$s\', \'%2$s\', \'%6$s\' ); return false;">%5$s</a>',
203
- $this->id,
204
- $this->post_type,
205
- $post->ID,
206
- $this->labels['name'],
207
- $this->labels['use'],
208
- $nonce_field
209
- );
210
-
211
- $form_fields['MuFeaImg-'.$this->id.'-'.$this->post_type] = array(
212
- 'label' => $this->labels['name'],
213
- 'input' => 'html',
214
- 'html' => $output
215
- );
216
-
217
- return $form_fields;
218
- }
219
-
220
- /**
221
- * Ajax function: set and delete featured image
222
- *
223
- * @global int $post_ID
224
- * @return void
225
- */
226
- public function kd_ajax_set_image() {
227
- global $post_ID;
228
-
229
- $post_ID = intval( $_POST['post_id'] );
230
-
231
- if( !current_user_can( 'edit_post', $post_ID ) ) {
232
- die( '-1' );
233
- }
234
-
235
- $thumb_id = intval( $_POST['thumbnail_id'] );
236
-
237
- check_ajax_referer( $this->nonce.$post_ID );
238
-
239
- if( $thumb_id == '-1' ) {
240
- delete_post_meta( $post_ID, $this->post_meta_key );
241
-
242
- die( $this->kd_meta_box_output( NULL ) );
243
- }
244
-
245
- if( $thumb_id && get_post( $thumb_id) ) {
246
- $thumb_html = wp_get_attachment_image( $thumb_id, 'thumbnail' );
247
-
248
- if( !empty( $thumb_html ) ) {
249
- update_post_meta( $post_ID, $this->post_meta_key, $thumb_id );
250
-
251
- die( $this->kd_meta_box_output( $thumb_id ) );
252
- }
253
- }
254
-
255
- die( '0' );
256
-
257
- }
258
-
259
- /**
260
- * Delete custom featured image if attachmet is deleted
261
- *
262
- * @global object $wpdb
263
- * @param int $post_id
264
- * @return void
265
- */
266
- public function kd_delete_attachment( $post_id ) {
267
- global $wpdb;
268
-
269
- $wpdb->query(
270
- $wpdb->prepare(
271
- "DELETE FROM $wpdb->postmeta WHERE meta_key = '%s' AND meta_value = %d",
272
- $this->post_meta_key,
273
- $post_id
274
- )
275
- );
276
- }
277
-
278
- /**
279
- * Retrieve the id of the featured image
280
- *
281
- * @global object $post
282
- * @param string $image_id
283
- * @param string $post_type
284
- * @param int $post_id
285
- * @return int
286
- */
287
- public static function get_featured_image_id( $image_id, $post_type, $post_id = NULL) {
288
- global $post;
289
-
290
- if( is_null( $post_id ) ) {
291
- $post_id = get_the_ID();
292
- }
293
-
294
- return get_post_meta( $post_id, "kd_{$image_id}_{$post_type}_id", true);
295
- }
296
-
297
- /**
298
- * Return the featured image url
299
- *
300
- * @param string $image_id
301
- * @param string $post_type
302
- * @param int $post_id
303
- * @return string
304
- */
305
- public static function get_featured_image_url( $image_id, $post_type, $size = 'full', $post_id = NULL ) {
306
- $id = self::get_featured_image_id( $image_id, $post_type, $post_id);
307
-
308
- if( $size != 'full' ) {
309
- $url = wp_get_attachment_image_src( $id, $size );
310
- $url = $url[0];
311
- }
312
- else {
313
- $url = wp_get_attachment_url( $id );
314
- }
315
-
316
- return $url;
317
- }
318
-
319
- /**
320
- * Return the featured image html output
321
- *
322
- * @param string $image_id
323
- * @param string $post_type
324
- * @param string $size
325
- * @param int $post_id
326
- * @return string
327
- */
328
- public static function get_the_featured_image( $image_id, $post_type, $size = 'full', $post_id = NULL ) {
329
- $id = self::get_featured_image_id( $image_id, $post_type, $post_id);
330
-
331
- $output = '';
332
-
333
- if( $id ) {
334
- $output = wp_get_attachment_image(
335
- $id,
336
- $size,
337
- false
338
- );
339
- }
340
-
341
- return $output;
342
- }
343
-
344
- /**
345
- * Output the featured image html output
346
- *
347
- * @param string $image_id
348
- * @param string $post_type
349
- * @param string $size
350
- * @param int $post_id
351
- * @return void
352
- */
353
- public static function the_featured_image( $image_id, $post_type, $size = 'full', $post_id = NULL ) {
354
- echo self::get_the_featured_image( $image_id, $post_type, $size, $post_id );
355
- }
356
- }
357
- }
358
-
359
- function kd_mfi_get_featured_image_id( $image_id, $post_type, $post_id = NULL ) {
360
- return kdMultipleFeaturedImages::get_featured_image_id( $image_id, $post_type, $post_id );
361
- }
362
-
363
- function kd_mfi_get_featured_image_url( $image_id, $post_type, $size = 'full', $post_id = NULL ) {
364
- return kdMultipleFeaturedImages::get_featured_image_url( $image_id, $post_type, $size, $post_id );
365
- }
366
-
367
- function kd_mfi_get_the_featured_image( $image_id, $post_type, $size = 'full', $post_id = NULL ) {
368
- return kdMultipleFeaturedImages::get_the_featured_image( $image_id, $post_type, $size, $post_id );
369
- }
370
-
371
- function kd_mfi_the_featured_image( $image_id, $post_type, $size = 'full', $post_id = NULL ) {
372
- return kdMultipleFeaturedImages::the_featured_image( $image_id, $post_type, $size, $post_id );
373
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/class-uh-post-header-images.php DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Add post specific header images
5
- *
6
- * @copyright Copyright (c), Ryan Hellyer
7
- * @license http://www.gnu.org/licenses/gpl.html GPL
8
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
9
- * @since 1.0
10
- */
11
- class UH_Post_Header_Images {
12
-
13
- /**
14
- * Class constructor
15
- *
16
- * Adds methods to appropriate hooks
17
- *
18
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
19
- * @since 1.0
20
- */
21
- public function __construct() {
22
-
23
- // Add filter for post header image (uses increased priority to ensure that single post thumbnails aren't overridden by category images)
24
- add_filter( 'theme_mod_header_image', array( $this, 'header_image_filter' ), 20 );
25
-
26
- }
27
-
28
- /*
29
- * Filter for modifying the output of get_header()
30
- *
31
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
32
- * @since 1.0
33
- * @param string $url The header image URL
34
- * @global $post Used for accessing the current post/page ID
35
- * @return string
36
- */
37
- public function header_image_filter( $url ) {
38
-
39
- // Bail out now if not in post or page
40
- if ( ! is_single() && ! is_page() )
41
- return $url;
42
-
43
- // Pick post type
44
- if ( is_single() ) {
45
- $slug = 'post';
46
- } else {
47
- $slug = 'page';
48
- }
49
-
50
- // Grab the post thumbnail ID
51
- $attachment_id = get_post_meta( get_the_ID(), 'kd_custom-header_' . $slug . '_id', true );
52
-
53
- if ( '' == $attachment_id ) {
54
-
55
- // If not set, then hunt for a legacy value (from when we used the Multiple Post Thumbnails plugins class)
56
- $attachment_id = get_post_meta( get_the_ID(), $slug . '_custom-header_thumbnail_id', true );
57
-
58
- // If attachment ID set here, then update the new ID
59
- if ( '' != $attachment_id ) {
60
- update_post_meta( get_the_ID(), 'kd_custom-header_post_id', $attachment_id );
61
- }
62
- }
63
-
64
- // If no post thumbnail ID set, then use default
65
- if ( '' == $attachment_id ) {
66
- return $url;
67
- }
68
-
69
- // Grab URL from WordPress
70
- $url = wp_get_attachment_image_src( $attachment_id, 'full' );
71
- $url = $url[0];
72
-
73
- return $url;
74
- }
75
-
76
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/class-uh-taxonomy-header-images.php DELETED
@@ -1,188 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Add taxonomy specific header images
5
- *
6
- * @copyright Copyright (c), Ryan Hellyer
7
- * @license http://www.gnu.org/licenses/gpl.html GPL
8
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
9
- * @since 1.0
10
- */
11
- class UH_Taxonomy_Header_Images {
12
-
13
- /**
14
- * Class constructor
15
- *
16
- * Adds methods to appropriate hooks
17
- *
18
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
19
- * @since 1.0
20
- */
21
- public function __construct() {
22
- add_action( 'init', array( $this, 'init' ) );
23
- }
24
-
25
- /**
26
- * Print styles to admin page
27
- *
28
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
29
- * @since 1.0
30
- */
31
- public function init() {
32
-
33
- // Bail out now if taxonomy meta data plugin not installed
34
- if ( !class_exists( 'Taxonomy_Metadata' ) )
35
- return;
36
-
37
- // Add actions for administration pages
38
- if ( is_admin() ) {
39
- add_action( 'admin_print_scripts', array( $this, 'print_styles' ) );
40
- add_action( 'admin_print_scripts', array( $this, 'external_scripts' ) );
41
- add_action( 'admin_head', array( $this, 'inline_scripts' ) );
42
-
43
- add_action( 'category_edit_form_fields', array( $this, 'extra_fields'), 1 );
44
- add_action( 'post_tag_edit_form_fields', array( $this, 'extra_fields'), 1 );
45
-
46
- add_action( 'edit_category', array( $this, 'storing_taxonomy_data' ) );
47
- add_action( 'edit_post_tag', array( $this, 'storing_taxonomy_data' ) );
48
- }
49
-
50
- // Add filter for category image (uses reduced priority to ensure that single post thumbnails override it)
51
- add_filter( 'theme_mod_header_image', array( $this, 'header_image_filter' ), 5 );
52
-
53
- }
54
-
55
- /**
56
- * Print styles to admin page
57
- *
58
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
59
- * @since 1.0
60
- */
61
- public function print_styles() {
62
-
63
- // If on category page, then bail out
64
- if ( !isset( $_GET['taxonomy'] ) )
65
- return;
66
-
67
- wp_enqueue_style( 'thickbox' );
68
- }
69
-
70
- /**
71
- * Print external scripts to admin page
72
- *
73
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
74
- * @since 1.0
75
- */
76
- public function external_scripts() {
77
-
78
- // If on category page, then bail out
79
- if ( !isset( $_GET['taxonomy'] ) )
80
- return;
81
-
82
- wp_enqueue_script( 'media-upload' );
83
- wp_enqueue_script( 'thickbox' );
84
- }
85
-
86
- /**
87
- * Print inline scripts to admin page
88
- *
89
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
90
- * @since 1.0
91
- */
92
- public function inline_scripts() {
93
-
94
- // If on category page, then bail out
95
- if ( !isset( $_GET['taxonomy'] ) )
96
- return;
97
-
98
- echo "
99
- <script>
100
- jQuery(document).ready(function() {
101
- jQuery('#upload_image_button').click(function() {
102
- formfield = jQuery('#upload_image').attr('name');
103
- tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
104
- return false;
105
- });
106
- window.send_to_editor = function(html) {
107
- imgurl = jQuery('img',html).attr('src');
108
- jQuery('#upload_image').val(imgurl);
109
- tb_remove();
110
- }
111
- });
112
- </script>";
113
- }
114
-
115
- /*
116
- * Filter for modifying the output of get_header()
117
- *
118
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
119
- * @since 1.0
120
- */
121
- public function header_image_filter( $url ) {
122
-
123
- // Grab current taxonomy ID
124
- if ( is_category() ) {
125
- $tag_ID = get_query_var( 'cat' );
126
- } else if ( is_tag() ) {
127
- $tag_info = get_query_var( 'tag' );
128
- $tag = get_term_by( 'slug', $tag_info, 'post_tag' );
129
- $tag_ID = $tag->term_id;
130
- }
131
-
132
- // Bail out now if no category set
133
- if ( ! isset( $tag_ID ) )
134
- return $url;
135
-
136
- // Grab stored taxonomy header
137
- $new_url = get_term_meta( $tag_ID, 'taxonomy-header-image', true );
138
-
139
- // Only use new URL if it isn't blank ...
140
- if ( '' != $new_url )
141
- $url = $new_url;
142
-
143
- return $url;
144
- }
145
-
146
- /**
147
- * Storing the taxonomy header image selection
148
- *
149
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
150
- * @since 1.0
151
- */
152
- public function storing_taxonomy_data() {
153
-
154
- // Sanitize inputs
155
- $tag_ID = (int) $_POST['tag_ID'];
156
- $url = $_POST['taxonomy-header-image'];
157
- $url = esc_url( $url );
158
-
159
- update_term_meta( $tag_ID, 'taxonomy-header-image', $url );
160
- }
161
-
162
- /**
163
- * Extra fields
164
- *
165
- * @author Ryan Hellyer <ryanhellyer@gmail.com>
166
- * @since 1.0
167
- */
168
- public function extra_fields() {
169
- $tag_ID = $_GET['tag_ID'];
170
- $url = get_term_meta( $tag_ID, 'taxonomy-header-image', true );
171
-
172
- echo '
173
- <tr valign="top">
174
- <th scope="row">' . __( 'Upload header image', 'hyper_headers' ) . '</th>
175
- <td>
176
- <label for="upload_image">
177
- <input id="upload_image" type="text" size="36" name="taxonomy-header-image" value="' . $url . '" />
178
- <input id="upload_image_button" type="button" value="Upload Image" />
179
- <br />' . __( 'Enter an URL or upload an image for the banner.', 'hyper_headers' ) . '
180
- <br />
181
- <img style="width:500px;height:auto;" src="' . $url . '" alt="" />
182
- </label>
183
- </td>
184
- </tr>';
185
-
186
- }
187
-
188
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/class-unique-headers-display.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Add a custom image meta box
5
+ *
6
+ * @copyright Copyright (c), Ryan Hellyer
7
+ * @license http://www.gnu.org/licenses/gpl.html GPL
8
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
9
+ * @since 1.3
10
+ */
11
+ class Unique_Headers_Display {
12
+
13
+ /**
14
+ * The name of the image meta
15
+ *
16
+ * @since 1.3
17
+ * @access private
18
+ * @var string $name
19
+ */
20
+ private $name;
21
+
22
+ /**
23
+ * The name of the image meta, with forced underscores instead of dashes
24
+ * This is to ensure that meta keys and filters do not use dashes.
25
+ *
26
+ * @since 1.3
27
+ * @access private
28
+ * @var string $name_underscores
29
+ */
30
+ private $name_underscores;
31
+
32
+ /**
33
+ * Class constructor
34
+ * Adds methods to appropriate hooks
35
+ *
36
+ * @since 1.3
37
+ */
38
+ public function __construct( $args ) {
39
+ $this->name_underscores = str_replace( '-', '_', $args['name'] );
40
+
41
+ // Add filter for post header image (uses increased priority to ensure that single post thumbnails aren't overridden by category images)
42
+ add_filter( 'theme_mod_header_image', array( $this, 'header_image_filter' ), 20 );
43
+
44
+ }
45
+
46
+ /*
47
+ * Filter for modifying the output of get_header()
48
+ *
49
+ * @since 1.3
50
+ * @param string $url The header image URL
51
+ * @return string $custom_url The new custom header image URL
52
+ */
53
+ public function header_image_filter( $url ) {
54
+
55
+ // Bail out now if not in post or page
56
+ if ( ! is_single() && ! is_page() ) {
57
+ return $url;
58
+ }
59
+
60
+ // Get custom URL
61
+ $attachment_id = Custom_Image_Meta_Box::get_attachment_id( get_the_ID(), $this->name_underscores );
62
+ $custom_url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
63
+
64
+ // If custom URL doesn't exist, then output original URL
65
+ if ( false == $custom_url ) {
66
+ return $url;
67
+ }
68
+
69
+ return $custom_url;
70
+ }
71
+
72
+ }
inc/class-unique-headers-taxonomy-header-images.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Add taxonomy specific header images
5
+ *
6
+ * @copyright Copyright (c), Ryan Hellyer
7
+ * @license http://www.gnu.org/licenses/gpl.html GPL
8
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
9
+ * @since 1.0
10
+ */
11
+ class Unique_Header_Taxonomy_Header_Images {
12
+
13
+ /**
14
+ * The name of the image meta
15
+ *
16
+ * @since 1.3
17
+ * @access private
18
+ * @var string $name
19
+ */
20
+ private $name;
21
+
22
+ /**
23
+ * The name of the image meta, with forced underscores instead of dashes
24
+ * This is to ensure that meta keys and filters do not use dashes.
25
+ *
26
+ * @since 1.3
27
+ * @access private
28
+ * @var string $name_underscores
29
+ */
30
+ private $name_underscores;
31
+
32
+ /**
33
+ * The title of the meta box
34
+ *
35
+ * @since 1.3
36
+ * @access private
37
+ * @var string $title
38
+ */
39
+ private $title;
40
+
41
+ /**
42
+ * The set custom image text
43
+ *
44
+ * @since 1.3
45
+ * @access private
46
+ * @var string $set_custom_image
47
+ */
48
+ private $set_custom_image;
49
+
50
+ /**
51
+ * The remove custom image text
52
+ *
53
+ * @since 1.3
54
+ * @access private
55
+ * @var string $remove_custom_image
56
+ */
57
+ private $remove_custom_image;
58
+
59
+ /**
60
+ * List of taxonomies to add meta boxes to
61
+ *
62
+ * @since 1.3
63
+ * @access private
64
+ * @var string $taxonomies
65
+ */
66
+ private $taxonomies;
67
+
68
+ /**
69
+ * The text for uploading header images
70
+ *
71
+ * @since 1.3
72
+ * @access private
73
+ * @var string $upload_header_image
74
+ */
75
+ private $upload_header_image;
76
+
77
+ /**
78
+ * Class constructor
79
+ *
80
+ * Adds methods to appropriate hooks
81
+ *
82
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
83
+ * @since 1.0
84
+ */
85
+ public function __construct( $args ) {
86
+
87
+ $this->name = $args['name'];
88
+ $this->name_underscores = str_replace( '-', '_', $args['name'] );
89
+ $this->title = $args['title'];
90
+ $this->set_custom_image = $args['set_custom_image'];
91
+ $this->remove_custom_image = $args['remove_custom_image'];
92
+ $this->taxonomies = $args['taxonomies'];
93
+ $this->upload_header_image = $args['upload_header_image'];
94
+
95
+ add_action( 'init', array( $this, 'init' ) );
96
+ }
97
+
98
+ /**
99
+ * Print styles to admin page
100
+ *
101
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
102
+ * @since 1.0
103
+ */
104
+ public function init() {
105
+
106
+ // Add actions for administration pages
107
+ if ( is_admin() ) {
108
+
109
+ // Add hooks for each taxonomy
110
+ foreach( $this->taxonomies as $taxonomy ) {
111
+ add_action( $taxonomy . '_edit_form_fields', array( $this, 'extra_fields' ), 1 );
112
+ add_action( 'edit_' . $taxonomy, array( $this, 'storing_taxonomy_data' ) );
113
+ }
114
+
115
+ }
116
+
117
+ // Add filter for category image (uses reduced priority to ensure that single post thumbnails override it)
118
+ add_filter( 'theme_mod_header_image', array( $this, 'header_image_filter' ), 5 );
119
+
120
+ }
121
+
122
+ /*
123
+ * Filter for modifying the output of get_header()
124
+ *
125
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
126
+ * @since 1.0
127
+ */
128
+ public function header_image_filter( $url ) {
129
+
130
+ /* We need to grab the current taxonomy ID
131
+ * Unfortunately, categories and post tags behave different, so we
132
+ * are checking for their presense and processing them slightly
133
+ * differently.
134
+ */
135
+ if ( is_category() ) {
136
+ $tax_ID = get_query_var( 'cat' );
137
+ } elseif( is_tag() || is_tag() ) {
138
+
139
+ // Now we can loop through all taxonomies
140
+ foreach( $this->taxonomies as $taxonomy ) {
141
+
142
+ // We need to ignore categories since we have already processed them
143
+ if ( 'category' != $taxonomy ) {
144
+
145
+ // Tags behave oddly, so need to use a different query var accordingly
146
+ if ( 'post_tag' == $taxonomy ) {
147
+ $tax_info = get_query_var( 'tag' );
148
+ } else {
149
+ $tax_info = get_query_var( $taxonomy );
150
+ }
151
+
152
+ $tax = get_term_by( 'slug', $tax_info, $taxonomy );
153
+ if ( isset( $tax->term_id ) ) {
154
+ $tax_ID = $tax->term_id;
155
+ }
156
+ }
157
+ }
158
+ }
159
+
160
+
161
+ // Bail out now if no term set
162
+ if ( ! isset( $tax_ID ) ) {
163
+ return $url;
164
+ }
165
+
166
+ // Grab stored taxonomy header
167
+ $attachment_id = get_term_meta( $tax_ID, 'taxonomy-header-image', true );
168
+
169
+ // Grab attachment's SRC if we have an ID, otherwise fallback to legacy support for the older URL system from earlier versions of the plugin
170
+ if ( is_numeric( $attachment_id ) ) {
171
+ $new_url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
172
+ } else {
173
+ $new_url = $attachment_id;
174
+ }
175
+
176
+ // Only use new URL if it isn't blank ...
177
+ if ( '' != $new_url ) {
178
+ $url = $new_url;
179
+ }
180
+
181
+ return esc_url ( $url );
182
+ }
183
+
184
+ /**
185
+ * Storing the taxonomy header image selection
186
+ *
187
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
188
+ * @since 1.0
189
+ */
190
+ public function storing_taxonomy_data() {
191
+
192
+ // Bail out now if POST vars not set
193
+ if ( ! isset( $_POST[$this->name . '-nonce'] ) || ! isset( $_POST[$this->name . '-id'] ) ) {
194
+ return;
195
+ }
196
+
197
+ // Bail out now if nonce doesn't verify
198
+ if ( ! wp_verify_nonce( $_POST[$this->name . '-nonce'], $this->name ) ) {
199
+ return;
200
+ }
201
+
202
+ // Sanitize inputs
203
+ $tag_ID = absint( $_POST['tag_ID'] );
204
+ $attachment_id = $_POST[$this->name . '-id'];
205
+ if ( is_numeric( $attachment_id ) ) {
206
+ $attachment_id = absint( $attachment_id );
207
+ } elseif ( is_string( $attachment_id ) ) {
208
+ $attachment_id = $this->get_attachment_id_from_url( $attachment_id );
209
+
210
+ // If still a string, then give up and treat it as a URL
211
+ if ( ! is_numeric( $attachment_id ) ) {
212
+ $attachment_id = esc_url( $attachment_id );
213
+ }
214
+ }
215
+
216
+ // Save the term meta data
217
+ update_term_meta( $tag_ID, 'taxonomy-header-image', $attachment_id );
218
+ }
219
+
220
+ /*
221
+ * Legacy method
222
+ * Used to obtain the attachment ID, if a URL is detected
223
+ *
224
+ * URL's were used in earlier versions of the plugin. This was upgraded
225
+ * for version 1.3 to utilize attachment ID's instead. These older URL's
226
+ * will be supported into the forseeable future though, since it is not
227
+ * possible to access ALL URL's as attachment ID's.
228
+ *
229
+ * The code for this method was modified from code originally written by Phillip Newcomer
230
+ * https://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/
231
+ *
232
+ * @global object $wpdb The WordPress database object
233
+ * @param string $url The URL we are trying to find the attachment ID for
234
+ * @return int $attachment_id The attachment ID for the input URL
235
+ */
236
+ private function get_attachment_id_from_url( $url = '' ) {
237
+ global $wpdb;
238
+ $attachment_id = false;
239
+
240
+ // If there is no url, return false
241
+ if ( '' == $url ) {
242
+ return false;
243
+ }
244
+
245
+ // Get the upload directory paths
246
+ $upload_dir_paths = wp_upload_dir();
247
+
248
+ // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
249
+ if ( false !== strpos( $url, $upload_dir_paths['baseurl'] ) ) {
250
+
251
+ // If this is the URL of an auto-generated thumbnail, get the URL of the original image
252
+ $url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $url );
253
+
254
+ // Remove the upload path base directory from the attachment URL
255
+ $url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $url );
256
+
257
+ // Finally, run a custom database query to get the attachment ID from the modified attachment URL
258
+ $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $url ) );
259
+
260
+ }
261
+
262
+ if ( false == $attachment_id ) {
263
+ return $url;
264
+ }
265
+
266
+ return $attachment_id;
267
+ }
268
+
269
+ /**
270
+ * Extra fields
271
+ *
272
+ * @author Ryan Hellyer <ryanhellyer@gmail.com>
273
+ * @since 1.0
274
+ */
275
+ public function extra_fields() {
276
+
277
+ $tag_ID = absint( $_GET['tag_ID'] );
278
+ $attachment_id = get_term_meta( $tag_ID, 'taxonomy-header-image', true );
279
+
280
+ // We need to cater for legacy URL's as well as the newer attachment ID's
281
+ if ( is_numeric( $attachment_id ) ) {
282
+ $url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
283
+ $title = Custom_Image_Meta_Box::get_attachment_title( $attachment_id );
284
+ } elseif ( is_string( $attachment_id ) ) {
285
+ $url = $attachment_id; // The attachment ID is actually the URL
286
+ $title = ''; // We don't know the title since it's an attachment
287
+ }
288
+
289
+ ?>
290
+ <tr valign="top">
291
+ <th scope="row"><?php echo esc_html( $this->upload_header_image ); ?></th>
292
+ <td>
293
+ <div id="unique-header" class="postbox " >
294
+ <div class="inside">
295
+
296
+ <p class="hide-if-no-js">
297
+ <a title="<?php echo esc_attr( $this->set_custom_image ); ?>" href="javascript:;" id="<?php echo esc_attr( 'set-' . $this->name . '-thumbnail' ); ?>" class="set-custom-meta-image-thumbnail"><?php echo esc_html( $this->set_custom_image ); ?></a>
298
+ </p>
299
+
300
+ <div id="<?php echo esc_attr( $this->name . '-container' ); ?>" class="custom-meta-image-container hidden">
301
+ <img src="<?php echo esc_url( $url ); ?>" alt="<?php echo esc_attr( $title ); ?>" title="<?php echo esc_attr( $title ); ?>" />
302
+ </div><!-- #<?php esc_attr( $this->name . '-image-container' ); ?> -->
303
+
304
+ <p class="hide-if-no-js hidden">
305
+ <a title="<?php echo esc_attr( $this->remove_custom_image ); ?>" href="javascript:;" id="<?php echo esc_attr( 'remove-' . $this->name . '-thumbnail' ); ?>" class="remove-custom-meta-image-thumbnail"><?php echo esc_html( $this->remove_custom_image ); ?></a>
306
+ </p><!-- .hide-if-no-js -->
307
+
308
+ <p id="<?php echo esc_attr( $this->name . '-info' ); ?>" class="custom-meta-image-info">
309
+ <input type="hidden" id="<?php echo esc_attr( $this->name . '-id' ); ?>" class="custom-meta-image-id" name="<?php echo esc_attr( $this->name . '-id' ); ?>" value="<?php echo esc_attr( $attachment_id ); ?>" />
310
+ </p><!-- #<?php echo esc_attr( $this->name . '-image-info' ); ?> -->
311
+
312
+ <?php wp_nonce_field( $this->name, $this->name . '-nonce' ); ?>
313
+
314
+ </div>
315
+ </div>
316
+ </td>
317
+ </tr>
318
+ <?php
319
+
320
+
321
+ }
322
+
323
+ }
inc/legacy.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Legacy fallback for old images
5
+ *
6
+ * Older versions of the plugin piggy backed on featured thumbnails plugins
7
+ * These plugins were phased out due to not keeping pace with WordPress core functionality
8
+ * This filter is here to maintain backwards compatibilty with the meta keys used by those plugins
9
+ * Future versions of the Unique Headers plugin will phase out this legacy code
10
+ *
11
+ * Any old images found, are updated to use the new meta key, to improve performance and avoid
12
+ * this function being required in future versions.
13
+ *
14
+ * @since 1.3
15
+ * @param int $post_id The current post ID
16
+ * @param int $attachment_id The attachment ID
17
+ */
18
+ function unique_headers_legacy( $post_id ) {
19
+ $attachment_id = '';
20
+
21
+ // Loop through the legacy meta keys, looking for header images
22
+ $keys = array(
23
+ 'post_custom-header_thumbnail_id',
24
+ 'page_custom-header_thumbnail_id',
25
+ 'kd_custom-header_post_id',
26
+ 'kd_custom-header_page_id',
27
+ );
28
+ foreach( $keys as $key ) {
29
+ if ( '' == $attachment_id ) {
30
+ $attachment_id = get_post_meta( $post_id, $key, true );
31
+ if ( '' != $attachment_id ) {
32
+ $keys_to_remove[] = $key; // Create list of keys which need deleted
33
+ }
34
+ }
35
+ }
36
+
37
+ // If no attachment found, then return false. Otherwise, convert the data to the new format and delete old keys
38
+ if ( '' == $attachment_id ) {
39
+ return false;
40
+ } else {
41
+
42
+ // Update to use new meta key
43
+ update_post_meta( $post_id, '_unique_header_id', $attachment_id );
44
+
45
+ // Delete unused meta keys
46
+ foreach( $keys_to_remove as $key ) {
47
+ delete_post_meta( $post_id, $key );
48
+ }
49
+ }
50
+
51
+ return $attachment_id;
52
+ }
53
+ add_filter( 'unique_header_fallback_images', 'unique_headers_legacy' );
index.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  /*
3
  Plugin Name: Unique Headers
4
- Plugin URI: http://geek.ryanhellyer.net/
5
  Description: Unique Headers
6
- Version: 1.2.1
7
  Author: Ryan Hellyer
8
  Author URI: http://geek.ryanhellyer.net/
9
 
@@ -34,8 +34,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34
  * @since 1.0
35
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
36
  */
37
- if ( !defined( 'ABSPATH' ) )
38
  die( 'Eh! What you doin in here?' );
 
 
39
 
40
  /**
41
  * Load classes
@@ -43,37 +45,62 @@ if ( !defined( 'ABSPATH' ) )
43
  * @since 1.0
44
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
45
  */
46
- require( 'inc/class-uh-taxonomy-header-images.php' );
47
- require( 'inc/class-uh-post-header-images.php' );
48
- require( 'inc/class-kd-multiple-featured-images.php' );
 
 
49
 
50
  /**
51
- * Define constants
52
  *
53
- * @since 1.0
54
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
55
  */
56
- define( 'UNIQUEHEADERS_DIR', dirname( __FILE__ ) . '/' ); // Plugin folder DIR
57
- define( 'UNIQUEHEADERS_URL', WP_PLUGIN_URL . '/' . basename( UNIQUEHEADERS_DIR ) . '' ); // Plugin folder URL
58
 
59
- /**
60
- * Instantiate classes
61
- *
62
- * @since 1.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
64
  */
65
- new UH_Taxonomy_Header_Images();
66
- new UH_Post_Header_Images();
67
- $args = array(
68
- 'id' => 'custom-header',
69
- 'post_type' => 'post', // Set this to post or page
70
- 'labels' => array(
71
- 'name' => __( 'Custom header', 'unique_headers' ),
72
- 'set' => __( 'Set custom header', 'unique_headers' ),
73
- 'remove' => __( 'Remove custom header', 'unique_headers' ),
74
- 'use' => __( 'Use custom header', 'unique_headers' ),
75
- )
76
- );
77
- new kdMultipleFeaturedImages( $args );
78
- $args['post_type'] = 'page';
79
- new kdMultipleFeaturedImages( $args );
1
  <?php
2
  /*
3
  Plugin Name: Unique Headers
4
+ Plugin URI: http://geek.ryanhellyer.net/products/unique-headers/
5
  Description: Unique Headers
6
+ Version: 1.3.7
7
  Author: Ryan Hellyer
8
  Author URI: http://geek.ryanhellyer.net/
9
 
34
  * @since 1.0
35
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
36
  */
37
+ if ( ! defined( 'ABSPATH' ) ) {
38
  die( 'Eh! What you doin in here?' );
39
+ }
40
+
41
 
42
  /**
43
  * Load classes
45
  * @since 1.0
46
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
47
  */
48
+ require( 'inc/class-unique-headers-taxonomy-header-images.php' );
49
+ require( 'inc/class-unique-headers-display.php' );
50
+ require( 'inc/class-custom-image-meta-box.php' );
51
+ require( 'inc/legacy.php' );
52
+
53
 
54
  /**
55
+ * Instantiate classes
56
  *
57
+ * @since 1.3
58
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
59
  */
60
+ function unique_headers_instantiate_classes() {
 
61
 
62
+ $name = 'custom-header-image'; // This says "custom-header" instead of "unique-header" to ensure compatibilty with Justin Tadlock's Custom Header Extended plugin which originally used a different post meta key value than the Unique Headers plugin
63
+ $args = array(
64
+ 'name' => $name,
65
+ 'dir_uri' => plugin_dir_url( __FILE__ ) . 'assets',
66
+ 'title' => __( 'Custom header', 'unique-headers' ),
67
+ 'set_custom_image' => __( 'Set Custom Header Image', 'unique-headers' ),
68
+ 'remove_custom_image' => __( 'Remove Custom Header Image', 'unique-headers' ),
69
+ 'post_types' => apply_filters( 'unique_headers_post_types', array( 'post', 'page' ) ),
70
+ );
71
+
72
+ // Add support for post-types
73
+ if ( is_admin() ) {
74
+ new Custom_Image_Meta_Box( $args );
75
+ } else {
76
+ new Unique_Headers_Display( array( 'name' => $name ) );
77
+ }
78
+
79
+ // Add support for taxonomies
80
+ if ( function_exists( 'get_term_meta' ) ) {
81
+ $args['taxonomies'] = apply_filters( 'unique_headers_taxonomies', array( 'category', 'post_tag' ) );
82
+ $args['upload_header_image'] = __( 'Upload header image', 'unique-headers' );
83
+
84
+ new Unique_Header_Taxonomy_Header_Images( $args );
85
+ }
86
+
87
+ }
88
+ add_action( 'plugins_loaded', 'unique_headers_instantiate_classes' );
89
+
90
+ /*
91
+ * Setup localization for translations
92
+ *
93
+ * @since 1.3
94
  * @author Ryan Hellyer <ryanhellyer@gmail.com>
95
  */
96
+ function unique_headers_localization() {
97
+
98
+ // Localization
99
+ load_plugin_textdomain(
100
+ 'unique-headers', // Unique identifier
101
+ false, // Deprecated abs path
102
+ dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Languages folder
103
+ );
104
+
105
+ }
106
+ unique_headers_localization();
 
 
 
 
js/kd-admin.js DELETED
@@ -1,57 +0,0 @@
1
- function kdMuFeaImgSetBoxContent( content, featuredImageID, post_type ) {
2
- //jQuery( '.inside', '#kd_' + featuredImageID ).html( content );
3
- jQuery( '#' + featuredImageID + '_' + post_type + ' .inside' ).html( content );
4
- }
5
- function kdMuFeaImgSetMetaValue( id, featuredImageID, post_type ) {
6
- var field = jQuery('input[value=kd_' + featuredImageID + '_' + post_type + '_id]', '#list-table');
7
- if ( field.size() > 0 ) {
8
- jQuery('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text( id );
9
- }
10
- }
11
-
12
- function kdMuFeaImgRemove ( featuredImageID, post_type, nonce ) {
13
- jQuery.post( ajaxurl, {
14
- action: 'set-MuFeaImg-' + featuredImageID + '-' + post_type,
15
- post_id: jQuery('#post_ID').val(),
16
- thumbnail_id: -1,
17
- _ajax_nonce: nonce,
18
- cookie: encodeURIComponent(document.cookie)
19
- }, function( str ) {
20
- if( str == '0' ) {
21
- alert( setPostThumbnailL10n.error );
22
- }
23
- else {
24
- kdMuFeaImgSetBoxContent( str, featuredImageID, post_type );
25
- }
26
- });
27
- }
28
-
29
- function kdMuFeaImgSet( id, featuredImageID, post_type, nonce ) {
30
- var $link = jQuery( 'a#' + featuredImageID + '-featuredimage' );
31
-
32
- $link.text( setPostThumbnailL10n.saving );
33
-
34
- jQuery.post( ajaxurl, {
35
- action: 'set-MuFeaImg-' + featuredImageID + '-' + post_type,
36
- post_id: post_id,
37
- thumbnail_id: id,
38
- _ajax_nonce: nonce,
39
- cookie: encodeURIComponent(document.cookie)
40
- }, function( str ) {
41
- if( str == '0' ) {
42
- alert( setPostThumbnailL10n.error );
43
- }
44
- else {
45
- var win = window.dialogArguments || opener || parent || top;
46
-
47
- $link.show().text( setPostThumbnailL10n.done );
48
-
49
- $link.fadeOut( 'slow', function() {
50
- jQuery('tr.MuFeaImg-' + featuredImageID + '-' + post_type ).hide();
51
- });
52
-
53
- win.kdMuFeaImgSetBoxContent( str, featuredImageID, post_type );
54
- win.kdMuFeaImgSetMetaValue( id, featuredImageID, post_type );
55
- }
56
- });
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/unique-headers-es_ES.mo ADDED
Binary file
languages/unique-headers-es_ES.po ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "MIME-Version: 1.0\n"
4
+ "Content-Type: text/plain; charset=UTF-8\n"
5
+ "Content-Transfer-Encoding: 8bit\n"
6
+ "X-Generator: POEditor.com\n"
7
+ "Project-Id-Version: Unique Headers\n"
8
+ "Language: es\n"
9
+
10
+ #:
11
+ msgid "Custom header"
12
+ msgstr "Encabezado customizado"
13
+
14
+ #:
15
+ msgid "Set Custom Header Image"
16
+ msgstr "Setear imagen de encabezado customizada"
17
+
18
+ #:
19
+ msgid "Remove Custom Header Image"
20
+ msgstr "Remover imagen de encabezado"
21
+
22
+ #:
23
+ msgid "Upload header image"
24
+ msgstr "Subir imagen de encabezado"
25
+
readme.txt CHANGED
@@ -1,20 +1,26 @@
1
  === Unique Headers ===
2
  Contributors: ryanhellyer
3
- Tags: header, headers, image, header-image, header-images, taxonomy, tag, category, posts, pages, taxonomies, post, page, unique
4
- Donate link: http://geek.ryanhellyer.net/donate/
5
- Requires at least: 3.9
6
- Stable tag: 1.2.1
7
 
8
 
9
- Adds the ability to use unique custom headers on individual pages, posts or categories or tags.
10
 
11
  == Description ==
12
 
13
- The <a href="http://geek.ryanhellyer.net/products/unique-headers/">Unique Headers Plugin</a> adds the ability to use unique custom headers on
14
- individual pages, posts or categories. This plugin makes use of the excellent <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a> for handling header images for categories and tags.
15
 
16
- = Experimental version =
17
- Please check out the new experimental beta version of this plugin which is <a href="http://geek.ryanhellyer.net/2014/11/03/unique-headers/">available for testing now</a>.
 
 
 
 
 
 
18
 
19
 
20
  == Installation ==
@@ -23,50 +29,105 @@ After you've downloaded and extracted the files:
23
 
24
  1. Upload the complete 'unique-headers' folder to the '/wp-content/plugins/' directory OR install via the plugin installer
25
  2. Activate the plugin through the 'Plugins' menu in WordPress
26
- 3. Install and activate the <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a> to add support for changing images for category listings.
27
  4. And yer done!
28
 
29
- Now you will see sections for changing your custom headers on the posts, pages and category listings.
30
 
31
- Visit the <a href="http://geek.ryanhellyer.net/products/unique-headers/">Unique Headers Plugin</a> for more information.
32
 
33
 
34
  == Frequently Asked Questions ==
35
 
36
  = I can't change the image on my categories/tags, what's wrong? =
37
-
38
  You need to install the <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a>. WordPress does not support
39
  the taxonomy meta data which this plugin needs to use to store the custom header image URL. As soon as you install that plugin, the category/tag image
40
  functionality should begin working.
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- = I set an image, but now I can't change it :/ =
44
- This is caused by a bug in a code library we've used. To work around this, you need to remove the image before adding a new one.
 
45
 
 
 
46
 
47
- = Where's the settings page? =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  There isn't one.
50
 
51
 
 
 
 
 
 
52
  = Does it work in older versions of WordPress? =
53
 
54
- Probably, but we only support the latest version of WordPress.
55
 
56
 
57
  = I need custom functionality. Can we pay you to build it for us? =
58
 
59
- No, I'm too busy. Having said that, if you are willing to pay me a small fortune then I could <a href="http://geek.ryanhellyer.net/contact/">probably be persuaded</a>.
 
60
 
61
 
62
  == Screenshots ==
63
 
64
- 1. The custom image uploader for posts/pages, when using the <a href="http://geek.ryanhellyer.net/products/unique-headers/">Unique Headers Plugin</a>
65
- 2. The custom image uploader for categories, when using the <a href="http://geek.ryanhellyer.net/products/unique-headers/">Unique Headers Plugin</a> and <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a>
 
66
 
67
 
68
  == Changelog ==
69
 
 
 
 
70
  Version 1.2: Converted to use the class from the Multiple Featured Images plugin<br />
71
  Version 1.1: Added support for tags <br />
72
  Version 1.0.4: Added support for displaying a category specific image on the single post pages<br />
@@ -80,3 +141,8 @@ Version 1.0: Initial release<br />
80
 
81
  Thanks to the following for help with the development of this plugin:<br />
82
  * <a href="http://onmytodd.org">Todd</a> - Assistance with implementing support for tags<br />
 
 
 
 
 
1
  === Unique Headers ===
2
  Contributors: ryanhellyer
3
+ Tags: custom-header, header, headers, image, header-image, header-images, taxonomy, tag, category, posts, pages, taxonomies, post, page, unique, custom
4
+ Donate link: https://geek.hellyer.kiwi/donate/
5
+ Requires at least: 4.1
6
+ Stable tag: 1.3.7
7
 
8
 
9
+ Adds the ability to use unique custom header images on individual pages, posts or categories or tags.
10
 
11
  == Description ==
12
 
13
+ = Features =
14
+ The <a href="https://geek.hellyer.kiwi/products/unique-headers/">Unique Headers Plugin</a> adds a custom header image box to the post/page edit screen. You can use this to upload a unique header image for that post, or use another image from your WordPress media library. When you view that page on the front-end of your site, the default header image for your site will be replaced by the unique header you selected.
15
 
16
+ To use this functionality with categories or tags, you will also need to install the excellent <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a>.
17
+
18
+ = Requirements =
19
+ You must use a theme which utilizes the built-in custom header functionality of WordPress. If your theme implement it's own header functionality, then this plugin will not work with it.
20
+
21
+ = Language support =
22
+ The plugin includes translations for the following languages:
23
+ 1. Spanish - provided by <a href="http://westoresolutions.com/">Mariano J. Ponce</a>
24
 
25
 
26
  == Installation ==
29
 
30
  1. Upload the complete 'unique-headers' folder to the '/wp-content/plugins/' directory OR install via the plugin installer
31
  2. Activate the plugin through the 'Plugins' menu in WordPress
32
+ 3. If you need custom headers on taxonomy, category or tags pages, then also install and activate the <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a>.
33
  4. And yer done!
34
 
35
+ Now you will see a new custom header image uploader whilst editing your site.
36
 
37
+ Visit the <a href="https://geek.hellyer.kiwi/products/unique-headers/">Unique Headers Plugin</a> for more information.
38
 
39
 
40
  == Frequently Asked Questions ==
41
 
42
  = I can't change the image on my categories/tags, what's wrong? =
 
43
  You need to install the <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a>. WordPress does not support
44
  the taxonomy meta data which this plugin needs to use to store the custom header image URL. As soon as you install that plugin, the category/tag image
45
  functionality should begin working.
46
 
47
+ = Your plugin doesn't work =
48
+ Actually, it does work ;) The problem is likely with your theme. Some themes have "custom headers", but don't use the built-in WordPress custom header system and will not work with the Unique Headers plugin because of this. It is not possible to predict how other custom header systems work, and so those can not be supported by this plugin. To test if this is the problem, simply switch to one of the default themes which come with WordPress and see if the plugin works with those, if it does, then your theme is at fault.
49
+
50
+ = My theme doesn't work with your plugin, how do I fix it? =
51
+ This is a complex question and not something I can teach in a short FAQ. I recommend hiring a professional WordPress developer for assistance, or asking the developer of your theme to add support for the built-in WordPress custom header system.
52
+
53
+ This is because WordPress does not provide a place for us to store data connected to a taxonomy such as a category or post tag. The Taxonomy Metadata plugin works around this problem by implement taxonomy meta. Future versions of WordPress are likely to include taxonomy meta baked in, and when this happens, the Unique Headers plugin will be updated to use that new functionality.
54
+
55
+ = Does it work with custom post-types? =
56
+ Not out of the box, but you can modify the following code to add support to suit your own requirements. You can can add this code to either your theme or to a custom plugin. You will need to modify the post-type to suit your own requirements. Some knowledge of PHP coding is necessary for this step.
57
+
58
+ `
59
+ <?php
60
+
61
+ /*
62
+ * Add support for a post-type called "some-post-type"
63
+ *
64
+ * @param array $post_types The currently supported post-types
65
+ * @return array $post_types The modified list of supported post-types
66
+ */
67
+ function unique_headers_add_post_type( $post_types ) {
68
+ $post_types[] = 'some-post-type';
69
 
70
+ return $post_types;
71
+ }
72
+ add_filter( 'unique_headers_post_types', 'unique_headers_add_post_type' );
73
 
74
+ ?>
75
+ `
76
 
77
+ = Does it work with taxonomies? =
78
+ As with custom post-types, not out of the box. You can however modify the following code to add support to suit your own requirements. You can can add this code to either your theme or to a custom plugin. You will need to modify the taxonomy to suit your own requirements. Some knowledge of PHP coding is necessary for this step.
79
+
80
+ `
81
+ <?php
82
+
83
+ /*
84
+ * Add support for a taxonomy called "some-taxonomy"
85
+ *
86
+ * @param array $taxonomies The currently supported taxonomies
87
+ * @return array $taxonomies The modified list of supported taxonomies
88
+ */
89
+ function unique_headers_add_taxonomy( $taxonomies ) {
90
+ $taxonomies[] = 'some-taxonomy';
91
+ return $taxonomies;
92
+ }
93
+ add_filter( 'unique_headers_taxonomies', 'unique_headers_add_taxonomy' );
94
+
95
+ ?>
96
+ `
97
+
98
+ = Where's the plugin settings page? =
99
 
100
  There isn't one.
101
 
102
 
103
+ = Other plugins work out the width and height of the header and serve the correct sized header. Why doesn't your plugin do that? =
104
+
105
+ I prefer to allow you to set the width and height yourself by opening a correct sized image. This allows you to provide over-resolution images to cater for "retina screen" and zoomed in users. Plus, it allows you to control the compression and image quality yourself. Neither route is better in my opinion. If you require this functionality, please let me know though, as if most people prefer the other route, then I may change how the plugin works. I suspect most people won't care either way though.
106
+
107
+
108
  = Does it work in older versions of WordPress? =
109
 
110
+ Probably, but I only actively support the latest version of WordPress. Support for older versions is purely by accident.
111
 
112
 
113
  = I need custom functionality. Can we pay you to build it for us? =
114
 
115
+ No, I'm too busy. Having said that, if you are willing to pay me a small fortune then I could <a href="https://ryan.hellyer.kiwi/contact/">probably be persuaded</a>. I'm also open to suggestions for improvements, so feel free to send me ideas and if you are lucky, it may be added for free :)
116
+
117
 
118
 
119
  == Screenshots ==
120
 
121
+ 1. The new meta box as added to the posts/pages screen
122
+ 2. The custom header image uploader for adding new header images
123
+ 3. The new meta box for categories and tags. This view is only seen when using the <a href="http://wordpress.org/extend/plugins/taxonomy-metadata/">Taxonomy Metadata plugin</a>
124
 
125
 
126
  == Changelog ==
127
 
128
+ Version 1.3.7: Addition of Spanish translation<br />
129
+ Version 1.3.1: Adjustment to match post meta key to other plugins, for compatibilty reasons.<br />
130
+ Version 1.3: Total rewrite to use custom built in system for media uploads. Also adapted taxonomies to use ID's and added support for extra post-types and taxonomies.<br />
131
  Version 1.2: Converted to use the class from the Multiple Featured Images plugin<br />
132
  Version 1.1: Added support for tags <br />
133
  Version 1.0.4: Added support for displaying a category specific image on the single post pages<br />
141
 
142
  Thanks to the following for help with the development of this plugin:<br />
143
  * <a href="http://onmytodd.org">Todd</a> - Assistance with implementing support for tags<br />
144
+ * <a href="http://westoresolutions.com/">Mariano J. Ponce</a> - Spanish translation<br />
145
+ * <a href="http://nakri.co.uk/">Nadia Tokerud</a> - Proof-reading of Norwegian Bokmål translation (coming soon)<br />
146
+ * <a href="http://bjornjohansen.no/">Bjørn Johansen</a> - Proof-reading of Norwegian Bokmål translation (coming soon)<br />
147
+ * <a href="https://www.facebook.com/kaljam/">Karl Olofsson</a> - Proof-reading of Swedish translation (coming soon)<br />
148
+ * <a href="http://www.jennybeaumont.com/"">Jenny Beaumont</a> - French translation (coming soon)<br />
screenshot-1.png DELETED
Binary file
screenshot-2.png DELETED
Binary file