Dynamic Featured Image - Version 3.3.1

Version Description

  • Increased code quality
Download this release

Release Info

Developer ankitpokhrel
Plugin Icon wp plugin Dynamic Featured Image
Version 3.3.1
Comparing to
See all releases

Code changes from version 3.3.0 to 3.3.1

css/dashicons.css CHANGED
File without changes
css/style-dfi.css CHANGED
File without changes
dynamic-featured-image.php CHANGED
@@ -1,872 +1,892 @@
1
- <?php
2
- /***
3
- Plugin Name: Dynamic Featured Image
4
- Plugin URI: http://wordpress.org/plugins/dynamic-featured-image/
5
- Description: Dynamically adds multiple featured image or post thumbnail functionality to your posts, pages and custom post types.
6
- Version: 3.3.0
7
- Author: Ankit Pokhrel
8
- Author URI: http://ankitpokhrel.com.np
9
- License: GPL2 or later
10
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
- Text Domain: dynamic-featured-image
12
- Domain Path: /languages
13
-
14
- Copyright (C) 2013 Ankit Pokhrel <ankitpokhrel@gmail.com, http://ankitpokhrel.com.np>,
15
-
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; either version 3 of the License, or
19
- (at your option) any later version.
20
-
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
-
26
- You should have received a copy of the GNU General Public License
27
- along with this program. If not, see <http://www.gnu.org/licenses/>.
28
- */
29
-
30
- // Avoid direct calls to this file
31
- if ( !defined( 'ABSPATH' ) ) {
32
- header( 'Status: 403 Forbidden' );
33
- header( 'HTTP/1.1 403 Forbidden' );
34
- exit();
35
- }
36
-
37
- /**
38
- * Dynamic Featured Image plugin main class
39
- *
40
- * @package dynamic-featured-image
41
- * @author Ankit Pokhrel <ankitpokhrel@gmail.com>
42
- * @version 3.0.1
43
- */
44
- class Dynamic_Featured_Image
45
- {
46
- /**
47
- * Current version of the plugin.
48
- *
49
- * @since 3.0.0
50
- */
51
- const VERSION = '3.3.0';
52
- private $upload_dir, $upload_url, $prefix, $db, $textDomain, $_metabox_title, $_userFilter;
53
-
54
- /**
55
- * Constructor. Hooks all interactions to initialize the class.
56
- *
57
- * @since 1.0.0
58
- * @access public
59
- * @global object $wpdb
60
- *
61
- * @see add_action()
62
- *
63
- * @return Void
64
- */
65
- public function __construct()
66
- {
67
- $this->textDomain = 'dynamic-featured-image';
68
-
69
- if ( is_admin() ) {
70
- add_action( 'in_plugin_update_message-' . plugin_basename(__FILE__), array( $this, 'update_notice' ) );
71
- }
72
-
73
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
74
- add_action( 'add_meta_boxes', array( $this, 'initialize_featured_box' ) );
75
- add_action( 'save_post', array( $this, 'save_meta' ) );
76
- add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
77
-
78
- //handle ajax request
79
- add_action( 'wp_ajax_dfiMetaBox_callback', array( $this, 'ajax_callback' ) );
80
-
81
- //get the site protocol
82
- $protocol = ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
83
- $_SERVER['SERVER_PORT'] == 443 ) ? "https://" : "http://";
84
-
85
- $this->upload_dir = wp_upload_dir();
86
- $this->upload_url = preg_replace('#^https?://#', '', $this->upload_dir['baseurl']);
87
-
88
- //add protocol to the upload url
89
- $this->upload_url = $protocol . $this->upload_url;
90
-
91
- //post type filter added by user
92
- $this->_userFilter = array();
93
-
94
- global $wpdb;
95
- $this->db = $wpdb;
96
-
97
- } // END __construct()
98
-
99
- /**
100
- * Add required admin scripts
101
- *
102
- * @since 1.0.0
103
- * @access public
104
- *
105
- * @see wp_enque_style()
106
- * @see wp_register_script()
107
- * @see wp_enqueue_script()
108
- *
109
- * @return Void
110
- */
111
- public function enqueue_admin_scripts()
112
- {
113
- //enqueue styles
114
- wp_enqueue_style( 'style-dfi', plugins_url( '/css/style-dfi.css', __FILE__ ), array(), self::VERSION );
115
- wp_enqueue_style( 'dashicons', plugins_url( '/css/dashicons.css', __FILE__ ), array(), self::VERSION );
116
-
117
- //register script
118
- wp_register_script( 'scripts-dfi', plugins_url( '/js/script-dfi.js', __FILE__), array( 'jquery' ), self::VERSION );
119
-
120
- //localize the script with required data
121
- wp_localize_script(
122
- 'scripts-dfi',
123
- 'WP_SPECIFIC',
124
- array(
125
- 'upload_url' => $this->upload_url,
126
- 'metabox_title' => __($this->_metabox_title, $this->textDomain),
127
- 'mediaSelector_title' => __('Dynamic Featured Image - Media Selector', $this->textDomain),
128
- 'mediaSelector_buttonText' => __('Set Featured Image', $this->textDomain)
129
- )
130
- );
131
-
132
- //enqueue scripts
133
- wp_enqueue_script( 'scripts-dfi' );
134
-
135
- } // END initialize_components()
136
-
137
- /**
138
- * Add featured meta boxes dynamically
139
- *
140
- * @since 1.0.0
141
- * @access public
142
- * @global object $post
143
- *
144
- * @see get_post_meta()
145
- * @see get_post_types()
146
- * @see add_meta_box()
147
- * @see add_filter()
148
- *
149
- * @return Void
150
- */
151
- public function initialize_featured_box()
152
- {
153
- global $post;
154
-
155
- //make metabox title dynamic
156
- $this->_metabox_title = apply_filters('dfi_set_metabox_title', "Featured Image");
157
-
158
- $featuredData = get_post_meta( $post->ID, 'dfiFeatured', true );
159
- $totalFeatured = count( $featuredData );
160
-
161
- $defaultFilter = array( 'attachment', 'revision', 'nav_menu_item' );
162
- $this->_userFilter = apply_filters('dfi_post_type_user_filter', $this->_userFilter);
163
- $filter = array_merge($defaultFilter, $this->_userFilter);
164
-
165
- $postTypes = get_post_types();
166
- $postTypes = array_diff( $postTypes, $filter );
167
-
168
- $postTypes = apply_filters('dfi_post_types', $postTypes);
169
-
170
- if ( !empty($featuredData) && $totalFeatured >= 1 ) {
171
- $i = 2;
172
- foreach ($featuredData as $featured) {
173
- self::_dfi_add_meta_box($postTypes, $featured, $i);
174
- $i++;
175
- }
176
- } else {
177
- self::_dfi_add_meta_box($postTypes);
178
- }
179
-
180
- } // END initialize_featured_box()
181
-
182
- /**
183
- * Translates more than one digit number digit by digit.
184
- * @param Integer $number Integer to be translated
185
- * @return String Translated number
186
- */
187
- private function _get_number_translation($number)
188
- {
189
- if ($number <= 9) {
190
- return __($number, $this->textDomain);
191
- } else {
192
- $pieces = str_split($number, 1);
193
- $buffer = '';
194
- foreach ($pieces as $piece) {
195
- $buffer .= __($piece, $this->textDomain);
196
- }
197
-
198
- return $buffer;
199
- }
200
- }
201
-
202
- /**
203
- * adds meta boxes
204
- * @param Array $postTypes post types to show featured image box
205
- * @param Object $featured callback arguments
206
- * @param Integer $i index of the featured image
207
- * @return Void
208
- */
209
- private function _dfi_add_meta_box($postTypes, $featured = null, $i = null)
210
- {
211
- if ( !is_null($i) ) {
212
- foreach ($postTypes as $type) {
213
- add_meta_box(
214
- 'dfiFeaturedMetaBox-' . $i,
215
- __($this->_metabox_title, $this->textDomain) . " " . self::_get_number_translation($i),
216
- array( $this, 'featured_meta_box' ),
217
- $type,
218
- 'side',
219
- 'low',
220
- array( $featured, $i + 1 )
221
- );
222
- add_filter( "postbox_classes_{$type}_dfiFeaturedMetaBox-" . $i, array( $this, 'add_metabox_classes' ) );
223
- }
224
-
225
- } else {
226
- foreach ($postTypes as $type) {
227
- add_meta_box(
228
- 'dfiFeaturedMetaBox',
229
- __( $this->_metabox_title, $this->textDomain ) . " " . __(2, $this->textDomain),
230
- array( $this, 'featured_meta_box' ),
231
- $type,
232
- 'side',
233
- 'low',
234
- array( null, null )
235
- );
236
- add_filter( "postbox_classes_{$type}_dfiFeaturedMetaBox", array( $this, 'add_metabox_classes' ) );
237
- }
238
- }
239
-
240
- }
241
-
242
- /**
243
- * Featured meta box as seen in the admin
244
- *
245
- * @since 1.0.0
246
- * @access public
247
- *
248
- * @see wp_nonce_field()
249
- * @see plugin_basename()
250
- *
251
- * @param Object $post global post object
252
- * @param Array $featured array containing featured image count
253
- *
254
- * @return Void
255
- */
256
- public function featured_meta_box($post, $featured)
257
- {
258
- $featuredImg = $featured['args'][0];
259
- $featuredId = is_null( $featured['args'][1]) ? 2 : --$featured['args'][1];
260
-
261
- $featuredImgTrimmed = $featuredImgFull = $featuredImg;
262
- if ( !is_null( $featured['args'][0] ) ) {
263
- @list( $featuredImgTrimmed, $featuredImgFull ) = explode( ',', $featuredImg );
264
- }
265
-
266
- try {
267
-
268
- $thumbnail = $this->get_image_thumb( $this->upload_url . $featuredImgFull, 'medium' );
269
- if ( is_null($thumbnail) ) {
270
-
271
- //medium sized thumbnail image is missing
272
- throw new Exception("Medium size image not found", 1);
273
-
274
- }
275
-
276
- } catch (Exception $e) {
277
-
278
- //since medium sized thumbnail image was not found,
279
- //let's set full image url as thumbnail
280
- $thumbnail = $featuredImgFull;
281
-
282
- }
283
-
284
- //Add a nonce field
285
- wp_nonce_field(plugin_basename(__FILE__), 'dfi_fimageplug-' . $featuredId);
286
- echo self::_get_featured_box($featuredImgTrimmed, $featuredImg, $featuredId, $thumbnail);
287
-
288
- } // END featured_meta_box()
289
-
290
- /**
291
- * Returns featured box html content
292
- * @since 3.1.0
293
- * @access private
294
- *
295
- * @param String $featuredImgTrimmed Medium sized image
296
- * @param String $featuredImg Full sized image
297
- * @param String $featuredId Attachment Id
298
- * @param String $thumbnail Thumb sized image
299
- *
300
- * @return String Html content
301
- */
302
- private function _get_featured_box($featuredImgTrimmed, $featuredImg, $featuredId, $thumbnail)
303
- {
304
- $hasFeaturedImage = !empty($featuredImgTrimmed) ? 'hasFeaturedImage' : '';
305
- $thumbnail = !is_null($thumbnail) ? $thumbnail : '';
306
- $dfiEmpty = is_null($featuredImgTrimmed) ? 'dfiImgEmpty' : '';
307
-
308
- return "<a href='javascript:void(0)' class='dfiFeaturedImage {$hasFeaturedImage}' title='". __('Set Featured Image', $this->textDomain) . "' data-post-id='" . get_the_ID() . "'><span class='dashicons dashicons-camera'></span></a><br/>
309
- <img src='" . $thumbnail . "' class='dfiImg {$dfiEmpty}'/>
310
- <div class='dfiLinks'>
311
- <a href='javascript:void(0)'' data-id='{$featuredId}' data-id-local='" . self::_get_number_translation( ($featuredId + 1) ) . "' class='dfiAddNew dashicons dashicons-plus' title='" . __('Add New', $this->textDomain) ."'></a>
312
- <a href='javascript:void(0)' class='dfiRemove dashicons dashicons-minus' title='" . __('Remove', $this->textDomain) . "'></a>
313
- </div>
314
- <div class='dfiClearFloat'></div>
315
- <input type='hidden' name='dfiFeatured[]' value='{$featuredImg}' class='dfiImageHolder' />";
316
- }
317
-
318
- /**
319
- * Load new featured meta box via ajax
320
- *
321
- * @since 1.0.0
322
- * @access public
323
- *
324
- * @see wp_nonce_field()
325
- * @see plugin_basename()
326
- *
327
- * @return Void
328
- */
329
- public function ajax_callback()
330
- {
331
- $featuredId = isset($_POST['id']) ? (int) strip_tags( trim( $_POST['id'] ) ) : null;
332
-
333
- if ( is_null( $featuredId ) ) {
334
- return;
335
- }
336
-
337
- wp_nonce_field( plugin_basename(__FILE__), 'dfi_fimageplug-' . $featuredId );
338
- ?>
339
- <a href="javascript:void(0)" class='dfiFeaturedImage' title="<?php echo __('Set Featured Image', $this->textDomain) ?>"><span class="dashicons dashicons-camera"></span></a><br/>
340
- <img src="" class='dfiImg dfiImgEmpty'/>
341
- <div class='dfiLinks'>
342
- <a href="javascript:void(0)" data-id='<?php echo $featuredId ?>' data-id-local='<?php echo self::_get_number_translation( ($featuredId + 1) ) ?>' class='dfiAddNew dashicons dashicons-plus' title="<?php echo __('Add New', $this->textDomain) ?>"></a>
343
- <a href="javascript:void(0)" class='dfiRemove dashicons dashicons-minus' title="<?php echo __('Remove', $this->textDomain) ?>"></a>
344
- </div>
345
- <div class='dfiClearFloat'></div>
346
- <input type='hidden' name="dfiFeatured[]" value="" class="dfiImageHolder" />
347
- <?php
348
- die();
349
-
350
- } // END MetaBox_callback())
351
-
352
- /**
353
- * Add custom class 'featured-meta-box' to meta box
354
- *
355
- * @since 1.0.0
356
- * @access public
357
- *
358
- * @see add_metabox_classes
359
- *
360
- * @param $classes classes to add in the meta box
361
- *
362
- * @return string
363
- */
364
- public function add_metabox_classes($classes)
365
- {
366
- array_push( $classes, 'featured-meta-box' );
367
-
368
- return $classes;
369
-
370
- } // END add_metabox_classes()
371
-
372
- /**
373
- * Update featured images in the database
374
- *
375
- * @since 1.0.0
376
- * @access public
377
- *
378
- * @see wp_verify_nonce()
379
- * @see plugin_basename()
380
- * @see update_post_meta()
381
- * @see current_user_can()
382
- *
383
- * @param Integer $post_id current post id
384
- *
385
- * @return Void
386
- */
387
- public function save_meta($post_id)
388
- {
389
- //Check autosave
390
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
391
- return;
392
- }
393
-
394
- $keys = array_keys( $_POST );
395
- foreach ($keys as $key) {
396
- if ( preg_match( '/dfi_fimageplug-\d+$/', $key ) ) {
397
- //Verify nonce
398
- if ( !wp_verify_nonce( $_POST[$key], plugin_basename(__FILE__) ) ) {
399
- return;
400
- }
401
- }
402
- }
403
-
404
- //Check permission before saving data
405
- if ( current_user_can( 'edit_posts', $post_id ) && isset( $_POST['dfiFeatured'] ) ) {
406
- update_post_meta( $post_id, 'dfiFeatured', $_POST['dfiFeatured'] );
407
- }
408
-
409
- } // END save_meta()
410
-
411
- /**
412
- * Add update notice. Displayed in plugin update page.
413
- *
414
- * @since 2.0.0
415
- * @access public
416
- * @ignore
417
- *
418
- * @return Void
419
- */
420
- public function update_notice()
421
- {
422
- $info = __( 'ATTENTION! Please read the <a href="https://github.com/ankitpokhrel/Dynamic-Featured-Image/wiki" target="_blank">DOCUMENTATION</a> properly before update.', $this->textDomain );
423
- echo '<div style="color:red; padding:7px 0;">' . strip_tags( $info, '<a><b><i><span>' ) . '</div>';
424
-
425
- } // END update_notice()
426
-
427
- /** Helper functions */
428
-
429
- private function execute_query($query)
430
- {
431
- return $this->db->get_var( $query );
432
- }
433
-
434
- /**
435
- * Get attachment id of the image by image url
436
- *
437
- * @since 3.1.7
438
- * @access private
439
- * @global object $wpdb
440
- *
441
- * @param String $image_url url of the image
442
- *
443
- * @return string
444
- */
445
- private function _get_attachment_id($image_url)
446
- {
447
- return self::execute_query($this->db->prepare( "SELECT ID FROM " . $this->db->posts . " WHERE guid = %s", $image_url ));
448
-
449
- } // END _get_attachment_id()
450
-
451
- /**
452
- * Get image url of the image by attachment id
453
- *
454
- * @since 2.0.0
455
- * @access public
456
- *
457
- * @see wp_get_attachment_image_src()
458
- *
459
- * @param Integer $attachment_id attachment id of an image
460
- * @param String $size size of the image to fetch (thumbnail, medium, full)
461
- *
462
- * @return String
463
- */
464
- public function get_image_url($attachment_id, $size = 'full')
465
- {
466
- $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
467
-
468
- return empty( $image_thumb ) ? null : $image_thumb[0];
469
-
470
- } // END get_image_url()
471
-
472
- /**
473
- * Get image thumbnail url of specific size by image url
474
- *
475
- * @since 2.0.0
476
- * @access public
477
- *
478
- * @see get_image_id()
479
- * @see wp_get_attachment_image_src()
480
- *
481
- * @param String $image_url url of an image
482
- * @param String $size size of the image to fetch (thumbnail, medium, full)
483
- *
484
- * @return String
485
- */
486
- public function get_image_thumb($image_url, $size = 'thumbnail')
487
- {
488
- $attachment_id = self::get_image_id( $image_url );
489
- $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
490
-
491
- return empty( $image_thumb ) ? null : $image_thumb[0];
492
-
493
- } // END get_image_thumb()
494
-
495
- /**
496
- * Gets attachment id from given image url
497
- * @param String $image_url url of an image
498
- * @return Integer|Null attachment id of an image
499
- *
500
- * @since 2.0.0
501
- * @access public
502
- */
503
- public function get_image_id($image_url)
504
- {
505
- $attachment_id = self::_get_attachment_id( $image_url );
506
- if ( is_null($attachment_id) ) {
507
- //check if the image is edited image
508
- //and try to get the attachment id
509
- $image_url = str_replace($this->upload_url . "/", '', $image_url);
510
- $row = self::execute_query( $this->db->prepare( "SELECT post_id FROM " . $this->db->postmeta . " WHERE meta_value = %s", $image_url ) );
511
- if ( !is_null($row) ) {
512
- $attachment_id = $row;
513
- }
514
- }
515
-
516
- return $attachment_id;
517
- }
518
-
519
- /**
520
- * Get image title
521
- *
522
- * @since 2.0.0
523
- * @access public
524
- *
525
- * @param String $image_url url of an image
526
- *
527
- * @return String
528
- */
529
- public function get_image_title($image_url)
530
- {
531
- return self::execute_query( $this->db->prepare( "SELECT post_title FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
532
-
533
- } // END get_image_title()
534
-
535
- /**
536
- * Get image title by id
537
- *
538
- * @since 2.0.0
539
- * @access public
540
- *
541
- * @param Integer $attachment_id attachment id of an image
542
- *
543
- * @return String
544
- */
545
- public function get_image_title_by_id($attachment_id)
546
- {
547
- return self::execute_query( $this->db->prepare( "SELECT post_title FROM " . $this->db->posts . " WHERE ID = %d", $attachment_id ) );
548
-
549
- } // END get_image_title_by_id()
550
-
551
- /**
552
- * Get image caption
553
- *
554
- * @since 2.0.0
555
- * @access public
556
- *
557
- * @param String $image_url url of an image
558
- *
559
- * @return String
560
- */
561
- public function get_image_caption($image_url)
562
- {
563
- return self::execute_query( $this->db->prepare("SELECT post_excerpt FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
564
-
565
- } // END get_image_caption()
566
-
567
- /**
568
- * Get image caption by id
569
- *
570
- * @since 2.0.0
571
- * @access public
572
- *
573
- * @param Integer $attachment_id attachment id of an image
574
- *
575
- * @return String
576
- */
577
- public function get_image_caption_by_id($attachment_id)
578
- {
579
- return self::execute_query( $this->db->prepare("SELECT post_excerpt FROM " . $this->db->posts . " WHERE ID = %d", $attachment_id) );
580
-
581
- } // END get_image_caption_by_id()
582
-
583
- /**
584
- * Get image alternate text
585
- *
586
- * @since 2.0.0
587
- * @access public
588
- *
589
- * @see get_post_meta()
590
- *
591
- * @param String $image_url url of an image
592
- *
593
- * @return String
594
- */
595
- public function get_image_alt($image_url)
596
- {
597
- $attachment = $this->db->get_col( $this->db->prepare( "SELECT ID FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
598
-
599
- $alt = null;
600
- if ( !empty( $attachment ) ) {
601
- $alt = get_post_meta( $attachment[0], '_wp_attachment_image_alt' );
602
- }
603
-
604
- return ( is_null( $alt ) || empty( $alt ) ) ? null : $alt[0];
605
-
606
- } // END get_image_alt()
607
-
608
- /**
609
- * Get image alternate text by attachment id
610
- *
611
- * @since 2.0.0
612
- * @access public
613
- *
614
- * @see get_post_meta()
615
- *
616
- * @param Integer $attachment_id attachment id of an image
617
- *
618
- * @return String
619
- */
620
- public function get_image_alt_by_id($attachment_id)
621
- {
622
- $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt');
623
-
624
- return empty($alt) ? null : $alt[0];
625
-
626
- } // END get_image_alt_by_id()
627
-
628
- /**
629
- * Get image description
630
- *
631
- * @since 3.0.0
632
- * @access public
633
- *
634
- * @param String $image_url url of an image
635
- *
636
- * @return String
637
- */
638
- public function get_image_description($image_url)
639
- {
640
- return self::execute_query( $this->db->prepare( "SELECT post_content FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
641
-
642
- } // END get_image_description()
643
-
644
- /**
645
- * Get image description by id
646
- *
647
- * @since 3.0.0
648
- * @access public
649
- *
650
- * @param Integer $attachment_id attachment id of an image
651
- *
652
- * @return String
653
- */
654
- public function get_image_description_by_id($attachment_id)
655
- {
656
- return self::execute_query( $this->db->prepare( "SELECT post_content FROM " . $this->db->posts . " WHERE ID = %d", $attachment_id ) );
657
-
658
- } // END get_image_description_by_id()
659
-
660
- /**
661
- * Get all attachment ids of the post
662
- *
663
- * @since 2.0.0
664
- * @access public
665
- *
666
- * @see get_post_meta()
667
- *
668
- * @param Integer $post_id id of the current post
669
- *
670
- * @return Array
671
- */
672
- public function get_post_attachment_ids($post_id)
673
- {
674
- $dfiImages = get_post_meta($post_id, 'dfiFeatured', true);
675
-
676
- $retVal = array();
677
- if ( !empty( $dfiImages ) && is_array( $dfiImages ) ) {
678
- foreach ($dfiImages as $dfiImage) {
679
- @list( $dfiImageTrimmed, $dfiImageFull ) = explode( ',', $dfiImage );
680
-
681
- $retVal[] = $this->get_image_id( $this->upload_url . $dfiImageFull );
682
- }
683
- }
684
-
685
- return $retVal;
686
-
687
- } // END get_post_attachment_ids()
688
-
689
- /**
690
- * Fetches featured image data of nth position
691
- *
692
- * @since 3.0.0
693
- * @access public
694
- *
695
- * @see get_featured_images()
696
- *
697
- * @param Integer $position position of the featured image
698
- * @param Integer $post_id id of the current post
699
- *
700
- * @return Array if found, null otherwise
701
- */
702
- public function get_nth_featured_image($position, $post_id = null)
703
- {
704
- if ( is_null( $post_id ) ) {
705
- global $post;
706
- $post_id = $post->ID;
707
- }
708
-
709
- $featured_images = $this->get_featured_images( $post_id );
710
-
711
- return isset($featured_images[$position - 2 ]) ? $featured_images[$position - 2] : null;
712
-
713
- } // END get_nth_featured_image()
714
-
715
- /**
716
- * Check if the image is attached with the particular post
717
- *
718
- * @since 2.0.0
719
- * @access public
720
- *
721
- * @see get_post_attachment_ids()
722
- *
723
- * @param $attachment_id attachment id of an image
724
- * @param $post_id id of the current post
725
- *
726
- * @return boolean
727
- */
728
- public function is_attached($attachment_id, $post_id)
729
- {
730
- $attachment_ids = $this->get_post_attachment_ids( $post_id );
731
-
732
- return in_array( $attachment_id, $attachment_ids ) ? true : false;
733
-
734
- } // END is_attached()
735
-
736
- /**
737
- * Retrieve featured images for specific post(s)
738
- *
739
- * @since 2.0.0
740
- * @access public
741
- *
742
- * @see get_post_meta()
743
- *
744
- * @param Integer $post_id id of the current post
745
- *
746
- * @return Array
747
- */
748
- public function get_featured_images($post_id = null)
749
- {
750
- if ( is_null( $post_id ) ) {
751
- global $post;
752
- $post_id = $post->ID;
753
- }
754
-
755
- $dfiImages = get_post_meta($post_id, 'dfiFeatured', true);
756
-
757
- $retImages = array();
758
- if ( !empty( $dfiImages ) && is_array( $dfiImages ) ) {
759
- $dfiImages = array_filter($dfiImages);
760
-
761
- $count = 0;
762
- foreach ($dfiImages as $dfiImage) {
763
- @list( $dfiImageTrimmed, $dfiImageFull ) = explode( ',', $dfiImage );
764
-
765
- try {
766
-
767
- $retImages[$count]['thumb'] = self::_get_real_upload_path( $dfiImageTrimmed );
768
- $retImages[$count]['full'] = self::_get_real_upload_path( $dfiImageFull );
769
- $retImages[$count]['attachment_id'] = $this->get_image_id( $retImages[$count]['full'] );
770
-
771
- } catch (Exception $e) { /* Ignore the exception and continue with other featured images */ }
772
-
773
- $count++;
774
- }
775
- }
776
-
777
- return $retImages;
778
-
779
- } // END get_featured_images()
780
-
781
- /**
782
- * Check to see if the upload url is already available in path.
783
- *
784
- * @since 3.1.14
785
- * @access protected
786
- *
787
- * @param string $img
788
- * @return string
789
- */
790
- protected function _get_real_upload_path( $img ) {
791
- //check if upload path is already attached
792
- if ( strpos($img, $this->upload_url) !== false ) {
793
- return $img;
794
- }
795
-
796
- return $this->upload_url . $img;
797
- } // END _get_real_upload_path()
798
-
799
- /**
800
- * Retrieve featured images for specific post(s) including the default Featured Image
801
- *
802
- * @since 3.1.7
803
- * @access public
804
- *
805
- * @see $this->get_featured_images()
806
- *
807
- * @param Integer $post_id id of the current post
808
- *
809
- * @return Array An array of images or an empty array on failure
810
- */
811
- public function get_all_featured_images($post_id = null)
812
- {
813
- if ( is_null( $post_id ) ) {
814
- global $post;
815
- $post_id = $post->ID;
816
- }
817
-
818
- $thumbnail_id = get_post_thumbnail_id( $post_id );
819
-
820
- $featured_image_array = array();
821
- if ( ! empty( $thumbnail_id ) ) {
822
- $featured_image = array(
823
- 'thumb' => wp_get_attachment_thumb_url( $thumbnail_id ),
824
- 'full' => wp_get_attachment_url( $thumbnail_id ),
825
- 'attachment_id' => $thumbnail_id
826
- );
827
- $featured_image_array[] = $featured_image;
828
- }
829
-
830
- $dfiImages = $this->get_featured_images( $post_id );
831
-
832
- $all_featured_images = array_merge( $featured_image_array, $dfiImages );
833
-
834
- return $all_featured_images;
835
-
836
- }
837
-
838
- /**
839
- * Load the plugin's textdomain hooked to 'plugins_loaded'.
840
- *
841
- * @since 1.0.0
842
- * @access public
843
- *
844
- * @see load_plugin_textdomain()
845
- * @see plugin_basename()
846
- * @action plugins_loaded
847
- *
848
- * @return void
849
- */
850
- public function load_plugin_textdomain()
851
- {
852
- load_plugin_textdomain(
853
- $this->textDomain,
854
- false,
855
- dirname( plugin_basename( __FILE__ ) ) . '/languages/'
856
- );
857
-
858
- } // END load_plugin_textdomain()
859
-
860
- } // END class Dynamic_Featured_Image
861
-
862
-
863
- /**
864
- * Instantiate the main class
865
- *
866
- * @since 1.0.0
867
- * @access public
868
- *
869
- * @var object $dynamic_featured_image holds the instantiated class {@uses Dynamic_Featured_Image}
870
- */
871
- global $dynamic_featured_image;
872
- $dynamic_featured_image = new Dynamic_Featured_Image();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /***
3
+ Plugin Name: Dynamic Featured Image
4
+ Plugin URI: http://wordpress.org/plugins/dynamic-featured-image/
5
+ Description: Dynamically adds multiple featured image or post thumbnail functionality to your posts, pages and custom post types.
6
+ Version: 3.3.1
7
+ Author: Ankit Pokhrel
8
+ Author URI: http://ankitpokhrel.com.np
9
+ License: GPL2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+ Text Domain: dynamic-featured-image
12
+ Domain Path: /languages
13
+
14
+ Copyright (C) 2013 Ankit Pokhrel <ankitpokhrel@gmail.com, http://ankitpokhrel.com.np>,
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 3 of the License, or
19
+ (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
28
+ */
29
+
30
+ // Avoid direct calls to this file
31
+ if ( !defined( 'ABSPATH' ) ) {
32
+ header( 'Status: 403 Forbidden' );
33
+ header( 'HTTP/1.1 403 Forbidden' );
34
+ exit();
35
+ }
36
+
37
+ /**
38
+ * Dynamic Featured Image plugin main class
39
+ *
40
+ * @package dynamic-featured-image
41
+ * @author Ankit Pokhrel <ankitpokhrel@gmail.com>
42
+ * @version 3.0.1
43
+ */
44
+ class Dynamic_Featured_Image
45
+ {
46
+ /**
47
+ * Current version of the plugin.
48
+ *
49
+ * @since 3.0.0
50
+ */
51
+ const VERSION = '3.3.1';
52
+ private $upload_dir, $upload_url, $db, $textDomain, $_metabox_title, $_userFilter;
53
+
54
+ /**
55
+ * Constructor. Hooks all interactions to initialize the class.
56
+ *
57
+ * @since 1.0.0
58
+ * @access public
59
+ * @global object $wpdb
60
+ *
61
+ * @see add_action()
62
+ */
63
+ public function __construct()
64
+ {
65
+ $this->textDomain = 'dynamic-featured-image';
66
+
67
+ if ( is_admin() ) {
68
+ add_action( 'in_plugin_update_message-' . plugin_basename(__FILE__), array( $this, 'update_notice' ) );
69
+ }
70
+
71
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
72
+ add_action( 'add_meta_boxes', array( $this, 'initialize_featured_box' ) );
73
+ add_action( 'save_post', array( $this, 'save_meta' ) );
74
+ add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
75
+
76
+ //handle ajax request
77
+ add_action( 'wp_ajax_dfiMetaBox_callback', array( $this, 'ajax_callback' ) );
78
+
79
+ //get the site protocol
80
+ $protocol = ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
81
+ $_SERVER['SERVER_PORT'] == 443 ) ? "https://" : "http://";
82
+
83
+ $this->upload_dir = wp_upload_dir();
84
+ $this->upload_url = preg_replace('#^https?://#', '', $this->upload_dir['baseurl']);
85
+
86
+ //add protocol to the upload url
87
+ $this->upload_url = $protocol . $this->upload_url;
88
+
89
+ //post type filter added by user
90
+ $this->_userFilter = array();
91
+
92
+ global $wpdb;
93
+ $this->db = $wpdb;
94
+
95
+ } // END __construct()
96
+
97
+ /**
98
+ * Add required admin scripts
99
+ *
100
+ * @since 1.0.0
101
+ * @access public
102
+ *
103
+ * @see wp_enque_style()
104
+ * @see wp_register_script()
105
+ * @see wp_enqueue_script()
106
+ *
107
+ * @return Void
108
+ */
109
+ public function enqueue_admin_scripts()
110
+ {
111
+ //enqueue styles
112
+ wp_enqueue_style( 'style-dfi', plugins_url( '/css/style-dfi.css', __FILE__ ), array(), self::VERSION );
113
+ wp_enqueue_style( 'dashicons', plugins_url( '/css/dashicons.css', __FILE__ ), array(), self::VERSION );
114
+
115
+ //register script
116
+ wp_register_script( 'scripts-dfi', plugins_url( '/js/script-dfi.js', __FILE__), array( 'jquery' ), self::VERSION );
117
+
118
+ //localize the script with required data
119
+ wp_localize_script(
120
+ 'scripts-dfi',
121
+ 'WP_SPECIFIC',
122
+ array(
123
+ 'upload_url' => $this->upload_url,
124
+ 'metabox_title' => __($this->_metabox_title, $this->textDomain),
125
+ 'mediaSelector_title' => __('Dynamic Featured Image - Media Selector', $this->textDomain),
126
+ 'mediaSelector_buttonText' => __('Set Featured Image', $this->textDomain)
127
+ )
128
+ );
129
+
130
+ //enqueue scripts
131
+ wp_enqueue_script( 'scripts-dfi' );
132
+
133
+ } // END initialize_components()
134
+
135
+ /**
136
+ * Add featured meta boxes dynamically
137
+ *
138
+ * @since 1.0.0
139
+ * @access public
140
+ * @global object $post
141
+ *
142
+ * @see get_post_meta()
143
+ * @see get_post_types()
144
+ * @see add_meta_box()
145
+ * @see add_filter()
146
+ *
147
+ * @return Void
148
+ */
149
+ public function initialize_featured_box()
150
+ {
151
+ global $post;
152
+
153
+ //make metabox title dynamic
154
+ $this->_metabox_title = apply_filters('dfi_set_metabox_title', "Featured Image");
155
+
156
+ $featuredData = get_post_meta( $post->ID, 'dfiFeatured', true );
157
+ $totalFeatured = count( $featuredData );
158
+
159
+ $defaultFilter = array( 'attachment', 'revision', 'nav_menu_item' );
160
+ $this->_userFilter = apply_filters('dfi_post_type_user_filter', $this->_userFilter);
161
+ $filter = array_merge($defaultFilter, $this->_userFilter);
162
+
163
+ $postTypes = get_post_types();
164
+ $postTypes = array_diff( $postTypes, $filter );
165
+
166
+ $postTypes = apply_filters('dfi_post_types', $postTypes);
167
+
168
+ if ( !empty($featuredData) && $totalFeatured >= 1 ) {
169
+ $i = 2;
170
+ foreach ($featuredData as $featured) {
171
+ self::_dfi_add_meta_box($postTypes, $featured, $i);
172
+ $i++;
173
+ }
174
+ } else {
175
+ self::_dfi_add_meta_box($postTypes);
176
+ }
177
+
178
+ } // END initialize_featured_box()
179
+
180
+ /**
181
+ * Translates more than one digit number digit by digit.
182
+ * @param Integer $number Integer to be translated
183
+ * @return String Translated number
184
+ */
185
+ private function _get_number_translation($number)
186
+ {
187
+ if ($number <= 9) {
188
+ return __($number, $this->textDomain);
189
+ } else {
190
+ $pieces = str_split($number, 1);
191
+ $buffer = '';
192
+ foreach ($pieces as $piece) {
193
+ $buffer .= __($piece, $this->textDomain);
194
+ }
195
+
196
+ return $buffer;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * adds meta boxes
202
+ * @param Array $postTypes post types to show featured image box
203
+ * @param Object $featured callback arguments
204
+ * @param Integer $i index of the featured image
205
+ * @return Void
206
+ */
207
+ private function _dfi_add_meta_box($postTypes, $featured = null, $i = null)
208
+ {
209
+ if ( !is_null($i) ) {
210
+ foreach ($postTypes as $type) {
211
+ add_meta_box(
212
+ 'dfiFeaturedMetaBox-' . $i,
213
+ __($this->_metabox_title, $this->textDomain) . " " . self::_get_number_translation($i),
214
+ array( $this, 'featured_meta_box' ),
215
+ $type,
216
+ 'side',
217
+ 'low',
218
+ array( $featured, $i + 1 )
219
+ );
220
+ add_filter( "postbox_classes_{$type}_dfiFeaturedMetaBox-" . $i, array( $this, 'add_metabox_classes' ) );
221
+ }
222
+
223
+ } else {
224
+ foreach ($postTypes as $type) {
225
+ add_meta_box(
226
+ 'dfiFeaturedMetaBox',
227
+ __( $this->_metabox_title, $this->textDomain ) . " " . __(2, $this->textDomain),
228
+ array( $this, 'featured_meta_box' ),
229
+ $type,
230
+ 'side',
231
+ 'low',
232
+ array( null, null )
233
+ );
234
+ add_filter( "postbox_classes_{$type}_dfiFeaturedMetaBox", array( $this, 'add_metabox_classes' ) );
235
+ }
236
+ }
237
+
238
+ }
239
+
240
+ /**
241
+ * Separate thumb and full image url from given URL string
242
+ *
243
+ * @since 3.3.1
244
+ *
245
+ * @param string $urlString [description]
246
+ * @param string $state Thumb or full
247
+ *
248
+ * @return string|null
249
+ */
250
+ private function _separate($urlString, $state = 'thumb')
251
+ {
252
+ $imagePiece = explode( ',', $urlString );
253
+
254
+ if( $state == 'thumb' ) {
255
+ return isset($imagePiece[0]) ? $imagePiece[0] : null;
256
+ }
257
+
258
+ return isset($imagePiece[1]) ? $imagePiece[1] : null;
259
+ }
260
+
261
+ /**
262
+ * Featured meta box as seen in the admin
263
+ *
264
+ * @since 1.0.0
265
+ * @access public
266
+ *
267
+ * @see wp_nonce_field()
268
+ * @see plugin_basename()
269
+ *
270
+ * @param Object $post global post object
271
+ * @param Array $featured array containing featured image count
272
+ *
273
+ * @return Void
274
+ */
275
+ public function featured_meta_box($post, $featured)
276
+ {
277
+ $featuredImg = $featured['args'][0];
278
+ $featuredId = is_null( $featured['args'][1]) ? 2 : --$featured['args'][1];
279
+
280
+ $featuredImgTrimmed = $featuredImgFull = $featuredImg;
281
+ if ( !is_null( $featuredImg ) ) {
282
+ $featuredImgTrimmed = self::_separate($featuredImg);
283
+ $featuredImgFull = self::_separate($featuredImg, 'full');
284
+ }
285
+
286
+ try {
287
+
288
+ $thumbnail = $this->get_image_thumb( $this->upload_url . $featuredImgFull, 'medium' );
289
+ if ( is_null($thumbnail) ) {
290
+
291
+ //medium sized thumbnail image is missing
292
+ throw new Exception("Medium size image not found", 1);
293
+
294
+ }
295
+
296
+ } catch (Exception $e) {
297
+
298
+ //since medium sized thumbnail image was not found,
299
+ //let's set full image url as thumbnail
300
+ $thumbnail = $featuredImgFull;
301
+
302
+ }
303
+
304
+ //Add a nonce field
305
+ wp_nonce_field(plugin_basename(__FILE__), 'dfi_fimageplug-' . $featuredId);
306
+ echo self::_get_featured_box($featuredImgTrimmed, $featuredImg, $featuredId, $thumbnail);
307
+
308
+ } // END featured_meta_box()
309
+
310
+ /**
311
+ * Returns featured box html content
312
+ * @since 3.1.0
313
+ * @access private
314
+ *
315
+ * @param String $featuredImgTrimmed Medium sized image
316
+ * @param String $featuredImg Full sized image
317
+ * @param String $featuredId Attachment Id
318
+ * @param String $thumbnail Thumb sized image
319
+ *
320
+ * @return String Html content
321
+ */
322
+ private function _get_featured_box($featuredImgTrimmed, $featuredImg, $featuredId, $thumbnail)
323
+ {
324
+ $hasFeaturedImage = !empty($featuredImgTrimmed) ? 'hasFeaturedImage' : '';
325
+ $thumbnail = !is_null($thumbnail) ? $thumbnail : '';
326
+ $dfiEmpty = is_null($featuredImgTrimmed) ? 'dfiImgEmpty' : '';
327
+
328
+ return "<a href='javascript:void(0)' class='dfiFeaturedImage {$hasFeaturedImage}' title='". __('Set Featured Image', $this->textDomain) . "' data-post-id='" . get_the_ID() . "'><span class='dashicons dashicons-camera'></span></a><br/>
329
+ <img src='" . $thumbnail . "' class='dfiImg {$dfiEmpty}'/>
330
+ <div class='dfiLinks'>
331
+ <a href='javascript:void(0)'' data-id='{$featuredId}' data-id-local='" . self::_get_number_translation( ($featuredId + 1) ) . "' class='dfiAddNew dashicons dashicons-plus' title='" . __('Add New', $this->textDomain) ."'></a>
332
+ <a href='javascript:void(0)' class='dfiRemove dashicons dashicons-minus' title='" . __('Remove', $this->textDomain) . "'></a>
333
+ </div>
334
+ <div class='dfiClearFloat'></div>
335
+ <input type='hidden' name='dfiFeatured[]' value='{$featuredImg}' class='dfiImageHolder' />";
336
+ }
337
+
338
+ /**
339
+ * Load new featured meta box via ajax
340
+ *
341
+ * @since 1.0.0
342
+ * @access public
343
+ *
344
+ * @see wp_nonce_field()
345
+ * @see plugin_basename()
346
+ *
347
+ * @return Void
348
+ */
349
+ public function ajax_callback()
350
+ {
351
+ $featuredId = isset($_POST['id']) ? (int) strip_tags( trim( $_POST['id'] ) ) : null;
352
+
353
+ if ( is_null( $featuredId ) ) {
354
+ return;
355
+ }
356
+
357
+ wp_nonce_field( plugin_basename(__FILE__), 'dfi_fimageplug-' . $featuredId );
358
+ ?>
359
+ <a href="javascript:void(0)" class='dfiFeaturedImage' title="<?php echo __('Set Featured Image', $this->textDomain) ?>"><span class="dashicons dashicons-camera"></span></a><br/>
360
+ <img src="" class='dfiImg dfiImgEmpty'/>
361
+ <div class='dfiLinks'>
362
+ <a href="javascript:void(0)" data-id='<?php echo $featuredId ?>' data-id-local='<?php echo self::_get_number_translation( ($featuredId + 1) ) ?>' class='dfiAddNew dashicons dashicons-plus' title="<?php echo __('Add New', $this->textDomain) ?>"></a>
363
+ <a href="javascript:void(0)" class='dfiRemove dashicons dashicons-minus' title="<?php echo __('Remove', $this->textDomain) ?>"></a>
364
+ </div>
365
+ <div class='dfiClearFloat'></div>
366
+ <input type='hidden' name="dfiFeatured[]" value="" class="dfiImageHolder" />
367
+ <?php
368
+ die();
369
+
370
+ } // END MetaBox_callback())
371
+
372
+ /**
373
+ * Add custom class 'featured-meta-box' to meta box
374
+ *
375
+ * @since 1.0.0
376
+ * @access public
377
+ *
378
+ * @see add_metabox_classes
379
+ *
380
+ * @param $classes classes to add in the meta box
381
+ *
382
+ * @return string
383
+ */
384
+ public function add_metabox_classes($classes)
385
+ {
386
+ array_push( $classes, 'featured-meta-box' );
387
+
388
+ return $classes;
389
+
390
+ } // END add_metabox_classes()
391
+
392
+ /**
393
+ * Update featured images in the database
394
+ *
395
+ * @since 1.0.0
396
+ * @access public
397
+ *
398
+ * @see wp_verify_nonce()
399
+ * @see plugin_basename()
400
+ * @see update_post_meta()
401
+ * @see current_user_can()
402
+ *
403
+ * @param Integer $post_id current post id
404
+ *
405
+ * @return Void
406
+ */
407
+ public function save_meta($post_id)
408
+ {
409
+ //Check autosave
410
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
411
+ return;
412
+ }
413
+
414
+ $keys = array_keys( $_POST );
415
+ foreach ($keys as $key) {
416
+ if ( preg_match( '/dfi_fimageplug-\d+$/', $key ) ) {
417
+ //Verify nonce
418
+ if ( !wp_verify_nonce( $_POST[$key], plugin_basename(__FILE__) ) ) {
419
+ return;
420
+ }
421
+ }
422
+ }
423
+
424
+ //Check permission before saving data
425
+ if ( current_user_can( 'edit_posts', $post_id ) && isset( $_POST['dfiFeatured'] ) ) {
426
+ update_post_meta( $post_id, 'dfiFeatured', $_POST['dfiFeatured'] );
427
+ }
428
+
429
+ } // END save_meta()
430
+
431
+ /**
432
+ * Add update notice. Displayed in plugin update page.
433
+ *
434
+ * @since 2.0.0
435
+ * @access public
436
+ * @ignore
437
+ *
438
+ * @return Void
439
+ */
440
+ public function update_notice()
441
+ {
442
+ $info = __( 'ATTENTION! Please read the <a href="https://github.com/ankitpokhrel/Dynamic-Featured-Image/wiki" target="_blank">DOCUMENTATION</a> properly before update.', $this->textDomain );
443
+ echo '<div style="color:red; padding:7px 0;">' . strip_tags( $info, '<a><b><i><span>' ) . '</div>';
444
+
445
+ } // END update_notice()
446
+
447
+ /** Helper functions */
448
+
449
+ private function execute_query($query)
450
+ {
451
+ return $this->db->get_var( $query );
452
+ }
453
+
454
+ /**
455
+ * Get attachment id of the image by image url
456
+ *
457
+ * @since 3.1.7
458
+ * @access private
459
+ * @global object $wpdb
460
+ *
461
+ * @param String $image_url url of the image
462
+ *
463
+ * @return string
464
+ */
465
+ private function _get_attachment_id($image_url)
466
+ {
467
+ return self::execute_query($this->db->prepare( "SELECT ID FROM " . $this->db->posts . " WHERE guid = %s", $image_url ));
468
+
469
+ } // END _get_attachment_id()
470
+
471
+ /**
472
+ * Get image url of the image by attachment id
473
+ *
474
+ * @since 2.0.0
475
+ * @access public
476
+ *
477
+ * @see wp_get_attachment_image_src()
478
+ *
479
+ * @param Integer $attachment_id attachment id of an image
480
+ * @param String $size size of the image to fetch (thumbnail, medium, full)
481
+ *
482
+ * @return String
483
+ */
484
+ public function get_image_url($attachment_id, $size = 'full')
485
+ {
486
+ $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
487
+
488
+ return empty( $image_thumb ) ? null : $image_thumb[0];
489
+
490
+ } // END get_image_url()
491
+
492
+ /**
493
+ * Get image thumbnail url of specific size by image url
494
+ *
495
+ * @since 2.0.0
496
+ * @access public
497
+ *
498
+ * @see get_image_id()
499
+ * @see wp_get_attachment_image_src()
500
+ *
501
+ * @param String $image_url url of an image
502
+ * @param String $size size of the image to fetch (thumbnail, medium, full)
503
+ *
504
+ * @return String
505
+ */
506
+ public function get_image_thumb($image_url, $size = 'thumbnail')
507
+ {
508
+ $attachment_id = self::get_image_id( $image_url );
509
+ $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
510
+
511
+ return empty( $image_thumb ) ? null : $image_thumb[0];
512
+
513
+ } // END get_image_thumb()
514
+
515
+ /**
516
+ * Gets attachment id from given image url
517
+ * @param String $image_url url of an image
518
+ * @return Integer|Null attachment id of an image
519
+ *
520
+ * @since 2.0.0
521
+ * @access public
522
+ */
523
+ public function get_image_id($image_url)
524
+ {
525
+ $attachment_id = self::_get_attachment_id( $image_url );
526
+ if ( is_null($attachment_id) ) {
527
+ //check if the image is edited image
528
+ //and try to get the attachment id
529
+ $image_url = str_replace($this->upload_url . "/", '', $image_url);
530
+ $row = self::execute_query( $this->db->prepare( "SELECT post_id FROM " . $this->db->postmeta . " WHERE meta_value = %s", $image_url ) );
531
+ if ( !is_null($row) ) {
532
+ $attachment_id = $row;
533
+ }
534
+ }
535
+
536
+ return $attachment_id;
537
+ }
538
+
539
+ /**
540
+ * Get image title
541
+ *
542
+ * @since 2.0.0
543
+ * @access public
544
+ *
545
+ * @param String $image_url url of an image
546
+ *
547
+ * @return String
548
+ */
549
+ public function get_image_title($image_url)
550
+ {
551
+ return self::execute_query( $this->db->prepare( "SELECT post_title FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
552
+
553
+ } // END get_image_title()
554
+
555
+ /**
556
+ * Get image title by id
557
+ *
558
+ * @since 2.0.0
559
+ * @access public
560
+ *
561
+ * @param Integer $attachment_id attachment id of an image
562
+ *
563
+ * @return String
564
+ */
565
+ public function get_image_title_by_id($attachment_id)
566
+ {
567
+ return self::execute_query( $this->db->prepare( "SELECT post_title FROM " . $this->db->posts . " WHERE ID = %d", $attachment_id ) );
568
+
569
+ } // END get_image_title_by_id()
570
+
571
+ /**
572
+ * Get image caption
573
+ *
574
+ * @since 2.0.0
575
+ * @access public
576
+ *
577
+ * @param String $image_url url of an image
578
+ *
579
+ * @return String
580
+ */
581
+ public function get_image_caption($image_url)
582
+ {
583
+ return self::execute_query( $this->db->prepare("SELECT post_excerpt FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
584
+
585
+ } // END get_image_caption()
586
+
587
+ /**
588
+ * Get image caption by id
589
+ *
590
+ * @since 2.0.0
591
+ * @access public
592
+ *
593
+ * @param Integer $attachment_id attachment id of an image
594
+ *
595
+ * @return String
596
+ */
597
+ public function get_image_caption_by_id($attachment_id)
598
+ {
599
+ return self::execute_query( $this->db->prepare("SELECT post_excerpt FROM " . $this->db->posts . " WHERE ID = %d", $attachment_id) );
600
+
601
+ } // END get_image_caption_by_id()
602
+
603
+ /**
604
+ * Get image alternate text
605
+ *
606
+ * @since 2.0.0
607
+ * @access public
608
+ *
609
+ * @see get_post_meta()
610
+ *
611
+ * @param String $image_url url of an image
612
+ *
613
+ * @return String
614
+ */
615
+ public function get_image_alt($image_url)
616
+ {
617
+ $attachment = $this->db->get_col( $this->db->prepare( "SELECT ID FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
618
+
619
+ $alt = null;
620
+ if ( !empty( $attachment ) ) {
621
+ $alt = get_post_meta( $attachment[0], '_wp_attachment_image_alt' );
622
+ }
623
+
624
+ return ( is_null( $alt ) || empty( $alt ) ) ? null : $alt[0];
625
+
626
+ } // END get_image_alt()
627
+
628
+ /**
629
+ * Get image alternate text by attachment id
630
+ *
631
+ * @since 2.0.0
632
+ * @access public
633
+ *
634
+ * @see get_post_meta()
635
+ *
636
+ * @param Integer $attachment_id attachment id of an image
637
+ *
638
+ * @return String
639
+ */
640
+ public function get_image_alt_by_id($attachment_id)
641
+ {
642
+ $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt');
643
+
644
+ return empty($alt) ? null : $alt[0];
645
+
646
+ } // END get_image_alt_by_id()
647
+
648
+ /**
649
+ * Get image description
650
+ *
651
+ * @since 3.0.0
652
+ * @access public
653
+ *
654
+ * @param String $image_url url of an image
655
+ *
656
+ * @return String
657
+ */
658
+ public function get_image_description($image_url)
659
+ {
660
+ return self::execute_query( $this->db->prepare( "SELECT post_content FROM " . $this->db->posts . " WHERE guid = %s", $image_url ) );
661
+
662
+ } // END get_image_description()
663
+
664
+ /**
665
+ * Get image description by id
666
+ *
667
+ * @since 3.0.0
668
+ * @access public
669
+ *
670
+ * @param Integer $attachment_id attachment id of an image
671
+ *
672
+ * @return String
673
+ */
674
+ public function get_image_description_by_id($attachment_id)
675
+ {
676
+ return self::execute_query( $this->db->prepare( "SELECT post_content FROM " . $this->db->posts . " WHERE ID = %d", $attachment_id ) );
677
+
678
+ } // END get_image_description_by_id()
679
+
680
+ /**
681
+ * Get all attachment ids of the post
682
+ *
683
+ * @since 2.0.0
684
+ * @access public
685
+ *
686
+ * @see get_post_meta()
687
+ *
688
+ * @param Integer $post_id id of the current post
689
+ *
690
+ * @return Array
691
+ */
692
+ public function get_post_attachment_ids($post_id)
693
+ {
694
+ $dfiImages = get_post_meta($post_id, 'dfiFeatured', true);
695
+
696
+ $retVal = array();
697
+ if ( !empty( $dfiImages ) && is_array( $dfiImages ) ) {
698
+ foreach ($dfiImages as $dfiImage) {
699
+ $dfiImageFull = self::_separate($dfiImage, 'full');
700
+ $retVal[] = $this->get_image_id( $this->upload_url . $dfiImageFull );
701
+ }
702
+ }
703
+
704
+ return $retVal;
705
+
706
+ } // END get_post_attachment_ids()
707
+
708
+ /**
709
+ * Fetches featured image data of nth position
710
+ *
711
+ * @since 3.0.0
712
+ * @access public
713
+ *
714
+ * @see get_featured_images()
715
+ *
716
+ * @param Integer $position position of the featured image
717
+ * @param Integer $post_id id of the current post
718
+ *
719
+ * @return Array if found, null otherwise
720
+ */
721
+ public function get_nth_featured_image($position, $post_id = null)
722
+ {
723
+ if ( is_null( $post_id ) ) {
724
+ global $post;
725
+ $post_id = $post->ID;
726
+ }
727
+
728
+ $featured_images = $this->get_featured_images( $post_id );
729
+
730
+ return isset($featured_images[$position - 2 ]) ? $featured_images[$position - 2] : null;
731
+
732
+ } // END get_nth_featured_image()
733
+
734
+ /**
735
+ * Check if the image is attached with the particular post
736
+ *
737
+ * @since 2.0.0
738
+ * @access public
739
+ *
740
+ * @see get_post_attachment_ids()
741
+ *
742
+ * @param $attachment_id attachment id of an image
743
+ * @param $post_id id of the current post
744
+ *
745
+ * @return boolean
746
+ */
747
+ public function is_attached($attachment_id, $post_id)
748
+ {
749
+ $attachment_ids = $this->get_post_attachment_ids( $post_id );
750
+
751
+ return in_array( $attachment_id, $attachment_ids ) ? true : false;
752
+
753
+ } // END is_attached()
754
+
755
+ /**
756
+ * Retrieve featured images for specific post(s)
757
+ *
758
+ * @since 2.0.0
759
+ * @access public
760
+ *
761
+ * @see get_post_meta()
762
+ *
763
+ * @param Integer $post_id id of the current post
764
+ *
765
+ * @return Array
766
+ */
767
+ public function get_featured_images($post_id = null)
768
+ {
769
+ if ( is_null( $post_id ) ) {
770
+ global $post;
771
+ $post_id = $post->ID;
772
+ }
773
+
774
+ $dfiImages = get_post_meta($post_id, 'dfiFeatured', true);
775
+
776
+ $retImages = array();
777
+ if ( !empty( $dfiImages ) && is_array( $dfiImages ) ) {
778
+ $dfiImages = array_filter($dfiImages);
779
+
780
+ $count = 0;
781
+ foreach ($dfiImages as $dfiImage) {
782
+ $dfiImageTrimmed = self::_separate($dfiImage);
783
+ $dfiImageFull = self::_separate($dfiImage, 'full');
784
+
785
+ try {
786
+
787
+ $retImages[$count]['thumb'] = self::_get_real_upload_path( $dfiImageTrimmed );
788
+ $retImages[$count]['full'] = self::_get_real_upload_path( $dfiImageFull );
789
+ $retImages[$count]['attachment_id'] = $this->get_image_id( $retImages[$count]['full'] );
790
+
791
+ } catch (Exception $e) { /* Ignore the exception and continue with other featured images */ }
792
+
793
+ $count++;
794
+ }
795
+ }
796
+
797
+ return $retImages;
798
+
799
+ } // END get_featured_images()
800
+
801
+ /**
802
+ * Check to see if the upload url is already available in path.
803
+ *
804
+ * @since 3.1.14
805
+ * @access protected
806
+ *
807
+ * @param string $img
808
+ * @return string
809
+ */
810
+ protected function _get_real_upload_path( $img ) {
811
+ //check if upload path is already attached
812
+ if ( strpos($img, $this->upload_url) !== false ) {
813
+ return $img;
814
+ }
815
+
816
+ return $this->upload_url . $img;
817
+ } // END _get_real_upload_path()
818
+
819
+ /**
820
+ * Retrieve featured images for specific post(s) including the default Featured Image
821
+ *
822
+ * @since 3.1.7
823
+ * @access public
824
+ *
825
+ * @see $this->get_featured_images()
826
+ *
827
+ * @param Integer $post_id id of the current post
828
+ *
829
+ * @return Array An array of images or an empty array on failure
830
+ */
831
+ public function get_all_featured_images($post_id = null)
832
+ {
833
+ if ( is_null( $post_id ) ) {
834
+ global $post;
835
+ $post_id = $post->ID;
836
+ }
837
+
838
+ $thumbnail_id = get_post_thumbnail_id( $post_id );
839
+
840
+ $featured_image_array = array();
841
+ if ( ! empty( $thumbnail_id ) ) {
842
+ $featured_image = array(
843
+ 'thumb' => wp_get_attachment_thumb_url( $thumbnail_id ),
844
+ 'full' => wp_get_attachment_url( $thumbnail_id ),
845
+ 'attachment_id' => $thumbnail_id
846
+ );
847
+ $featured_image_array[] = $featured_image;
848
+ }
849
+
850
+ $dfiImages = $this->get_featured_images( $post_id );
851
+
852
+ $all_featured_images = array_merge( $featured_image_array, $dfiImages );
853
+
854
+ return $all_featured_images;
855
+
856
+ }
857
+
858
+ /**
859
+ * Load the plugin's textdomain hooked to 'plugins_loaded'.
860
+ *
861
+ * @since 1.0.0
862
+ * @access public
863
+ *
864
+ * @see load_plugin_textdomain()
865
+ * @see plugin_basename()
866
+ * @action plugins_loaded
867
+ *
868
+ * @return void
869
+ */
870
+ public function load_plugin_textdomain()
871
+ {
872
+ load_plugin_textdomain(
873
+ $this->textDomain,
874
+ false,
875
+ dirname( plugin_basename( __FILE__ ) ) . '/languages/'
876
+ );
877
+
878
+ } // END load_plugin_textdomain()
879
+
880
+ } // END class Dynamic_Featured_Image
881
+
882
+
883
+ /**
884
+ * Instantiate the main class
885
+ *
886
+ * @since 1.0.0
887
+ * @access public
888
+ *
889
+ * @var object $dynamic_featured_image holds the instantiated class {@uses Dynamic_Featured_Image}
890
+ */
891
+ global $dynamic_featured_image;
892
+ $dynamic_featured_image = new Dynamic_Featured_Image();
img/spinner.gif CHANGED
File without changes
js/script-dfi.js CHANGED
@@ -1,165 +1,163 @@
1
- /**
2
- * @file script-dfi.js
3
- *
4
- * Script for dynamic featured image plugin.
5
- *
6
- * Copyright (c) 2013, Ankit Pokhrel <ankitpokhrel@gmail.com, http://ankitpokhrel.com.np>
7
- */
8
-
9
- jQuery(document).ready(function($) {
10
- var current = null;
11
-
12
- /**
13
- * Add new meta box
14
- */
15
- $(document).on('click', '.dfiAddNew', function() {
16
-
17
- var obj = $(this);
18
- var id = parseInt( $('.featured-meta-box:last').find('.dfiAddNew').data('id'), 10 );
19
- var idLocal = $('.featured-meta-box:last').find('.dfiAddNew').attr('data-id-local');
20
-
21
- var newMetaBox = obj.closest('.featured-meta-box').clone();
22
- newMetaBox.find('.hndle span').html( WP_SPECIFIC.metabox_title + " " + idLocal );
23
-
24
- newMetaBox.attr('id', 'dfiFeaturedMetaBox' + "-" + (++id) );
25
- newMetaBox.find('.handlediv').addClass('dfiDynamicBox');
26
-
27
- var metaBoxContentObj = newMetaBox.find('.inside');
28
- metaBoxContentObj.html('');
29
- obj.hide();
30
- obj.parent().append('<span class="dfiLoading"></span>').hide().fadeIn(200);
31
 
32
- $.ajax({
33
- type: 'POST',
34
- url: 'admin-ajax.php',
35
- data: { action: 'dfiMetaBox_callback', id: id },
36
- success: function(response){
37
- metaBoxContentObj.append(response);
38
- newMetaBox.appendTo( obj.closest('.featured-meta-box').parent() );
39
-
40
- //Add post id
41
- newMetaBox.find('.dfiFeaturedImage').attr('data-post-id', obj.parent().parent().find('.dfiFeaturedImage').attr('data-post-id') );
42
-
43
- var alias = obj;
44
- obj.parent().find('.dfiLoading').fadeOut(300, function(){ $(this).remove(); alias.fadeIn(200); });
45
- }
46
- });
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  });
49
 
50
- /**
51
- * Remove featured image meta box
52
- */
53
- $(document).on('click', '.dfiRemove', function() {
54
 
55
- if( confirm('Are you sure?') ) {
 
 
 
56
 
57
- var dfiMetaBox = $(this).closest('.featured-meta-box');
58
- var totalMetaBox = $('.featured-meta-box').length;
59
 
60
- if( totalMetaBox === 1 ) {
 
61
 
62
- dfiMetaBox.find('.dfiImg').attr('src', '');
63
- dfiMetaBox.find('.dfiImageHolder').val('');
64
- dfiMetaBox.find('.dfiFeaturedImage')
65
- .removeClass('hasFeaturedImage')
66
- .show()
67
- .animate({ opacity: 1, display: 'inline-block' }, 600);
68
 
69
- } else {
 
 
 
 
 
70
 
71
- dfiMetaBox.fadeOut(500, function(){
72
- $(this).remove();
73
- });
74
 
75
- }
 
 
76
 
77
  }
78
 
79
- });
80
 
81
- /**
82
- * Display custom media uploader and allow to
83
- * select featured image from the media library
84
- */
85
- $(document).on('click', '.dfiFeaturedImage', function() {
86
 
87
- current = $(this);
 
 
 
 
88
 
89
- if( null !== current) {
90
 
91
- var dfi_uploader = wp.media({
92
 
93
- title: WP_SPECIFIC.mediaSelector_title,
94
- button: {
95
- text: WP_SPECIFIC.mediaSelector_buttonText
96
- },
97
- multiple: false,
98
 
99
- }).on('select', function() {
 
 
 
 
100
 
101
- var attachment = dfi_uploader.state().get('selection').first().toJSON();
102
- var fullSize = attachment.url;
103
- var imgUrl = (typeof attachment.sizes.thumbnail === "undefined") ? fullSize : attachment.sizes.thumbnail.url;
104
- var imgUrlTrimmed, fullUrlTrimmed;
105
 
106
- imgUrlTrimmed = imgUrl.replace(WP_SPECIFIC.upload_url, "");
 
 
 
107
 
108
- fullUrlTrimmed = fullSize.replace(WP_SPECIFIC.upload_url, "");
 
109
 
110
- var featuredBox = current.parent();
111
 
112
- featuredBox.find('.fImg').attr({
113
- 'src': imgUrl,
114
- 'data-src': fullSize
115
- });
116
 
117
- featuredBox.find('.dfiFeaturedImage').addClass('hasFeaturedImage');
118
 
119
- var dfiFeaturedImages = [imgUrlTrimmed, fullUrlTrimmed];
120
 
121
- /**
122
- * Check if medium sized image exists
123
- * @type object
124
- */
125
- var medium = attachment.url;
126
- if( typeof attachment.sizes.medium !== "undefined" ) {
127
- medium = attachment.sizes.medium.url;
128
- }
129
 
130
- featuredBox.find('img').attr('src', medium).fadeIn(200);
131
- featuredBox.find('input.dfiImageHolder').val(dfiFeaturedImages);
132
 
133
- }).open();
134
- }
135
 
136
- return false;
137
 
138
- });
139
 
140
- /**
141
- * Enable toggle of dynamically generated featured box
142
- */
143
- $(document).on('click', '.dfiDynamicBox', function() {
144
- $(this).parent().toggleClass('closed');
145
- });
146
 
147
- /**
148
- * Add a hover animation in image
149
- */
150
- $(document).on({
151
- mouseenter: function(){
152
- var obj = $(this).closest('.featured-meta-box');
153
- obj.find('.dfiImg').stop(true, true).animate({ opacity: 0.3 }, 300 );
154
- obj.find('.hasFeaturedImage').fadeIn(200);
155
- },
156
- mouseleave: function(){
157
- var obj = $(this);
158
- obj.find('.dfiImg').stop(true, true).animate({ opacity: 1 }, 300 );
159
- obj.find('.hasFeaturedImage').fadeOut(100);
160
- }
161
- }, '.featured-meta-box .inside');
162
 
163
- });
164
 
165
  //END
1
+ /**
2
+ * @file script-dfi.js
3
+ *
4
+ * Script for dynamic featured image plugin.
5
+ *
6
+ * Copyright (c) 2013, Ankit Pokhrel <ankitpokhrel@gmail.com, http://ankitpokhrel.com.np>
7
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ jQuery(document).ready(function($) {
10
+ var current = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ /**
13
+ * Add new meta box
14
+ */
15
+ $(document).on('click', '.dfiAddNew', function() {
16
+
17
+ var obj = $(this),
18
+ id = parseInt( $('.featured-meta-box:last').find('.dfiAddNew').data('id'), 10 ),
19
+ idLocal = $('.featured-meta-box:last').find('.dfiAddNew').attr('data-id-local'),
20
+ newMetaBox = obj.closest('.featured-meta-box').clone();
21
+
22
+ newMetaBox.find('.hndle span').html( WP_SPECIFIC.metabox_title + " " + idLocal );
23
+ newMetaBox.attr('id', 'dfiFeaturedMetaBox' + "-" + (++id) );
24
+ newMetaBox.find('.handlediv').addClass('dfiDynamicBox');
25
+
26
+ var metaBoxContentObj = newMetaBox.find('.inside');
27
+ metaBoxContentObj.html('');
28
+ obj.hide();
29
+ obj.parent().append('<span class="dfiLoading"></span>').hide().fadeIn(200);
30
+
31
+ $.ajax({
32
+ type: 'POST',
33
+ url: 'admin-ajax.php',
34
+ data: { action: 'dfiMetaBox_callback', id: id },
35
+ success: function(response){
36
+ metaBoxContentObj.append(response);
37
+ newMetaBox.appendTo( obj.closest('.featured-meta-box').parent() );
38
+
39
+ //Add post id
40
+ newMetaBox.find('.dfiFeaturedImage').attr('data-post-id', obj.parent().parent().find('.dfiFeaturedImage').attr('data-post-id') );
41
+
42
+ var alias = obj;
43
+ obj.parent().find('.dfiLoading').fadeOut(300, function(){ $(this).remove(); alias.fadeIn(200); });
44
+ }
45
  });
46
 
47
+ });
 
 
 
48
 
49
+ /**
50
+ * Remove featured image meta box
51
+ */
52
+ $(document).on('click', '.dfiRemove', function() {
53
 
54
+ if( confirm('Are you sure?') ) {
 
55
 
56
+ var dfiMetaBox = $(this).closest('.featured-meta-box'),
57
+ totalMetaBox = $('.featured-meta-box').length;
58
 
59
+ if( totalMetaBox === 1 ) {
 
 
 
 
 
60
 
61
+ dfiMetaBox.find('.dfiImg').attr('src', '');
62
+ dfiMetaBox.find('.dfiImageHolder').val('');
63
+ dfiMetaBox.find('.dfiFeaturedImage')
64
+ .removeClass('hasFeaturedImage')
65
+ .show()
66
+ .animate({ opacity: 1, display: 'inline-block' }, 600);
67
 
68
+ } else {
 
 
69
 
70
+ dfiMetaBox.fadeOut(500, function(){
71
+ $(this).remove();
72
+ });
73
 
74
  }
75
 
76
+ }
77
 
78
+ });
 
 
 
 
79
 
80
+ /**
81
+ * Display custom media uploader and allow to
82
+ * select featured image from the media library
83
+ */
84
+ $(document).on('click', '.dfiFeaturedImage', function() {
85
 
86
+ current = $(this);
87
 
88
+ if( null !== current) {
89
 
90
+ var dfi_uploader = wp.media({
 
 
 
 
91
 
92
+ title: WP_SPECIFIC.mediaSelector_title,
93
+ button: {
94
+ text: WP_SPECIFIC.mediaSelector_buttonText
95
+ },
96
+ multiple: false,
97
 
98
+ }).on('select', function() {
 
 
 
99
 
100
+ var attachment = dfi_uploader.state().get('selection').first().toJSON(),
101
+ fullSize = attachment.url,
102
+ imgUrl = (typeof attachment.sizes.thumbnail === "undefined") ? fullSize : attachment.sizes.thumbnail.url,
103
+ imgUrlTrimmed, fullUrlTrimmed;
104
 
105
+ imgUrlTrimmed = imgUrl.replace(WP_SPECIFIC.upload_url, "");
106
+ fullUrlTrimmed = fullSize.replace(WP_SPECIFIC.upload_url, "");
107
 
108
+ var featuredBox = current.parent();
109
 
110
+ featuredBox.find('.fImg').attr({
111
+ 'src': imgUrl,
112
+ 'data-src': fullSize
113
+ });
114
 
115
+ featuredBox.find('.dfiFeaturedImage').addClass('hasFeaturedImage');
116
 
117
+ var dfiFeaturedImages = [imgUrlTrimmed, fullUrlTrimmed];
118
 
119
+ /**
120
+ * Check if medium sized image exists
121
+ * @type object
122
+ */
123
+ var medium = attachment.url;
124
+ if( typeof attachment.sizes.medium !== "undefined" ) {
125
+ medium = attachment.sizes.medium.url;
126
+ }
127
 
128
+ featuredBox.find('img').attr('src', medium).fadeIn(200);
129
+ featuredBox.find('input.dfiImageHolder').val(dfiFeaturedImages);
130
 
131
+ }).open();
132
+ }
133
 
134
+ return false;
135
 
136
+ });
137
 
138
+ /**
139
+ * Enable toggle of dynamically generated featured box
140
+ */
141
+ $(document).on('click', '.dfiDynamicBox', function() {
142
+ $(this).parent().toggleClass('closed');
143
+ });
144
 
145
+ /**
146
+ * Add a hover animation in image
147
+ */
148
+ $(document).on({
149
+ mouseenter: function(){
150
+ var obj = $(this).closest('.featured-meta-box');
151
+ obj.find('.dfiImg').stop(true, true).animate({ opacity: 0.3 }, 300 );
152
+ obj.find('.hasFeaturedImage').fadeIn(200);
153
+ },
154
+ mouseleave: function(){
155
+ var obj = $(this);
156
+ obj.find('.dfiImg').stop(true, true).animate({ opacity: 1 }, 300 );
157
+ obj.find('.hasFeaturedImage').fadeOut(100);
158
+ }
159
+ }, '.featured-meta-box .inside');
160
 
161
+ });
162
 
163
  //END
languages/dynamic-featured-image-bs_BA.mo CHANGED
File without changes
languages/dynamic-featured-image-bs_BA.po CHANGED
File without changes
languages/dynamic-featured-image-he_IL.mo CHANGED
File without changes
languages/dynamic-featured-image-he_IL.po CHANGED
File without changes
languages/dynamic-featured-image-hr_HR.mo CHANGED
File without changes
languages/dynamic-featured-image-hr_HR.po CHANGED
File without changes
languages/dynamic-featured-image-it_IT.mo CHANGED
File without changes
languages/dynamic-featured-image-it_IT.po CHANGED
File without changes
languages/dynamic-featured-image-ne_NP.mo CHANGED
File without changes
languages/dynamic-featured-image-ne_NP.po CHANGED
File without changes
languages/dynamic-featured-image-sr_RS.mo CHANGED
File without changes
languages/dynamic-featured-image-sr_RS.po CHANGED
File without changes
languages/dynamic-featured-image-sv_SE.mo CHANGED
File without changes
languages/dynamic-featured-image-sv_SE.po CHANGED
File without changes
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: dynamic featured image, featured image, post thumbnail, dynamic post thumbnail, multiple featured image, multiple post thumbnail
5
  Requires at least: 3.5
6
  Tested up to: 4.1
7
- Stable tag: 3.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -120,6 +120,9 @@ Please feel free to report any bug found at https://github.com/ankitpokhrel/Dyna
120
  3. Add new featured image box.
121
 
122
  == Changelog ==
 
 
 
123
  = 3.3.0 =
124
  * Fixed Invalid image path returned - Pull Request #35
125
  * Added dfi_post_type_user_filter to disable metabox in post types.
@@ -194,6 +197,9 @@ Please feel free to report any bug found at https://github.com/ankitpokhrel/Dyna
194
  * Fixed some minor issues.
195
 
196
  == Upgrade Notice ==
 
 
 
197
  = 3.3.0 =
198
  This version has multisite url bug fix and has added various useful filters.
199
 
4
  Tags: dynamic featured image, featured image, post thumbnail, dynamic post thumbnail, multiple featured image, multiple post thumbnail
5
  Requires at least: 3.5
6
  Tested up to: 4.1
7
+ Stable tag: 3.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
120
  3. Add new featured image box.
121
 
122
  == Changelog ==
123
+ = 3.3.1 =
124
+ * Increased code quality
125
+
126
  = 3.3.0 =
127
  * Fixed Invalid image path returned - Pull Request #35
128
  * Added dfi_post_type_user_filter to disable metabox in post types.
197
  * Fixed some minor issues.
198
 
199
  == Upgrade Notice ==
200
+ = 3.3.1 =
201
+ This version has no functionality change.
202
+
203
  = 3.3.0 =
204
  This version has multisite url bug fix and has added various useful filters.
205