Version Description
- Increased code quality
Download this release
Release Info
Developer | ankitpokhrel |
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 +0 -0
- css/style-dfi.css +0 -0
- dynamic-featured-image.php +892 -872
- img/spinner.gif +0 -0
- js/script-dfi.js +126 -128
- languages/dynamic-featured-image-bs_BA.mo +0 -0
- languages/dynamic-featured-image-bs_BA.po +0 -0
- languages/dynamic-featured-image-he_IL.mo +0 -0
- languages/dynamic-featured-image-he_IL.po +0 -0
- languages/dynamic-featured-image-hr_HR.mo +0 -0
- languages/dynamic-featured-image-hr_HR.po +0 -0
- languages/dynamic-featured-image-it_IT.mo +0 -0
- languages/dynamic-featured-image-it_IT.po +0 -0
- languages/dynamic-featured-image-ne_NP.mo +0 -0
- languages/dynamic-featured-image-ne_NP.po +0 -0
- languages/dynamic-featured-image-sr_RS.mo +0 -0
- languages/dynamic-featured-image-sr_RS.po +0 -0
- languages/dynamic-featured-image-sv_SE.mo +0 -0
- languages/dynamic-featured-image-sv_SE.po +0 -0
- readme.txt +7 -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.
|
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.
|
52 |
-
private $upload_dir, $upload_url, $
|
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 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
add_action( '
|
74 |
-
add_action( '
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
$
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
*
|
101 |
-
*
|
102 |
-
*
|
103 |
-
* @
|
104 |
-
*
|
105 |
-
* @see
|
106 |
-
*
|
107 |
-
* @
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
'
|
126 |
-
'
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
*
|
139 |
-
*
|
140 |
-
* @
|
141 |
-
*
|
142 |
-
* @
|
143 |
-
*
|
144 |
-
* @see
|
145 |
-
* @see
|
146 |
-
*
|
147 |
-
* @
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
$
|
157 |
-
|
158 |
-
|
159 |
-
$
|
160 |
-
|
161 |
-
$
|
162 |
-
|
163 |
-
$
|
164 |
-
|
165 |
-
|
166 |
-
$postTypes =
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
}
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
*
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
$pieces
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
*
|
204 |
-
* @param
|
205 |
-
* @
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
'
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
'
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
*
|
244 |
-
*
|
245 |
-
* @
|
246 |
-
* @
|
247 |
-
*
|
248 |
-
* @
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
$
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
*
|
320 |
-
*
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
} // END
|
371 |
-
|
372 |
-
/**
|
373 |
-
*
|
374 |
-
*
|
375 |
-
* @since 1.0.0
|
376 |
-
* @access public
|
377 |
-
*
|
378 |
-
* @see
|
379 |
-
*
|
380 |
-
* @
|
381 |
-
*
|
382 |
-
*
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
*
|
436 |
-
*
|
437 |
-
*
|
438 |
-
* @
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
*
|
456 |
-
*
|
457 |
-
* @
|
458 |
-
*
|
459 |
-
* @
|
460 |
-
*
|
461 |
-
*
|
462 |
-
*
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
*
|
474 |
-
*
|
475 |
-
* @
|
476 |
-
*
|
477 |
-
*
|
478 |
-
*
|
479 |
-
* @
|
480 |
-
*
|
481 |
-
*
|
482 |
-
* @
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
*
|
497 |
-
*
|
498 |
-
* @
|
499 |
-
*
|
500 |
-
*
|
501 |
-
* @
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
*
|
521 |
-
*
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
*
|
541 |
-
*
|
542 |
-
*
|
543 |
-
* @
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
*
|
557 |
-
*
|
558 |
-
*
|
559 |
-
* @
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
*
|
573 |
-
*
|
574 |
-
*
|
575 |
-
* @
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
*
|
589 |
-
*
|
590 |
-
*
|
591 |
-
* @
|
592 |
-
*
|
593 |
-
* @
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
$
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
*
|
610 |
-
*
|
611 |
-
* @
|
612 |
-
*
|
613 |
-
*
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
return empty($alt) ? null : $alt[0];
|
625 |
-
|
626 |
-
} // END
|
627 |
-
|
628 |
-
/**
|
629 |
-
* Get image
|
630 |
-
*
|
631 |
-
* @since
|
632 |
-
* @access public
|
633 |
-
*
|
634 |
-
* @
|
635 |
-
*
|
636 |
-
* @
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
*
|
650 |
-
*
|
651 |
-
*
|
652 |
-
* @
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
*
|
666 |
-
*
|
667 |
-
*
|
668 |
-
* @
|
669 |
-
*
|
670 |
-
* @
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
$
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
*
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
*
|
717 |
-
*
|
718 |
-
*
|
719 |
-
* @
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
$
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
*
|
738 |
-
*
|
739 |
-
*
|
740 |
-
* @
|
741 |
-
*
|
742 |
-
* @
|
743 |
-
*
|
744 |
-
*
|
745 |
-
*
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
*
|
803 |
-
*
|
804 |
-
*
|
805 |
-
* @
|
806 |
-
*
|
807 |
-
* @param
|
808 |
-
*
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
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 |
-
|
33 |
-
|
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 |
-
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
var totalMetaBox = $('.featured-meta-box').length;
|
59 |
|
60 |
-
|
|
|
61 |
|
62 |
-
|
63 |
-
dfiMetaBox.find('.dfiImageHolder').val('');
|
64 |
-
dfiMetaBox.find('.dfiFeaturedImage')
|
65 |
-
.removeClass('hasFeaturedImage')
|
66 |
-
.show()
|
67 |
-
.animate({ opacity: 1, display: 'inline-block' }, 600);
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
|
90 |
|
91 |
-
|
92 |
|
93 |
-
|
94 |
-
button: {
|
95 |
-
text: WP_SPECIFIC.mediaSelector_buttonText
|
96 |
-
},
|
97 |
-
multiple: false,
|
98 |
|
99 |
-
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
|
102 |
-
var fullSize = attachment.url;
|
103 |
-
var imgUrl = (typeof attachment.sizes.thumbnail === "undefined") ? fullSize : attachment.sizes.thumbnail.url;
|
104 |
-
var imgUrlTrimmed, fullUrlTrimmed;
|
105 |
|
106 |
-
|
|
|
|
|
|
|
107 |
|
108 |
-
|
|
|
109 |
|
110 |
-
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
|
130 |
-
|
131 |
-
|
132 |
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
137 |
|
138 |
-
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
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.
|
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 |
|