Version Description
Download this release
Release Info
Developer | jeffrey-wp |
Plugin | Media Library Categories |
Version | 1.5.0 |
Comparing to | |
See all releases |
Code changes from version 1.4.15 to 1.5.0
- css/wpmediacategory.css +45 -0
- css/wpmediacategory.min.css +1 -0
- index.php +155 -2
- js/wpmediacategory-media-views.js +1 -1
- js/wpmediacategory-media-views.min.js +1 -1
- readme.txt +6 -2
css/wpmediacategory.css
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.mode-grid .wpmediacategory-filter {
|
3 |
+
float: left;
|
4 |
+
}
|
5 |
+
|
6 |
+
|
7 |
+
/* media-toolbar */
|
8 |
+
.attachments-browser .media-toolbar {
|
9 |
+
height: auto;
|
10 |
+
}
|
11 |
+
.attachments-browser .attachments, .attachments-browser .uploader-inline {
|
12 |
+
top: 72px;
|
13 |
+
}
|
14 |
+
|
15 |
+
/* category fields */
|
16 |
+
.compat-item .term-list {
|
17 |
+
background-color: #fff;
|
18 |
+
border: 1px solid #dfdfdf;
|
19 |
+
border-radius: 3px;
|
20 |
+
margin: 0 0 10px;
|
21 |
+
padding: 10px 10px 5px;
|
22 |
+
}
|
23 |
+
.compat-item .term-list li {
|
24 |
+
line-height: 22px;
|
25 |
+
}
|
26 |
+
.compat-item .term-list li input[type="checkbox"] {
|
27 |
+
margin: -4px 4px 0 0 !important;
|
28 |
+
width: auto;
|
29 |
+
}
|
30 |
+
.compat-item .term-list li input[type=checkbox]:indeterminate:before {
|
31 |
+
content: '\f147';
|
32 |
+
color: #CBCBCB;
|
33 |
+
display: inline-block;
|
34 |
+
float: left;
|
35 |
+
font: normal 21px/1 'dashicons';
|
36 |
+
margin: -3px 0 0 -4px;
|
37 |
+
speak: none;
|
38 |
+
vertical-align: middle;
|
39 |
+
width: 16px;
|
40 |
+
-webkit-font-smoothing: antialiased;
|
41 |
+
-moz-osx-font-smoothing: grayscale;
|
42 |
+
}
|
43 |
+
.compat-item .term-list .children {
|
44 |
+
margin: 5px 0 0 20px;
|
45 |
+
}
|
css/wpmediacategory.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.mode-grid .wpmediacategory-filter{float:left}.attachments-browser .media-toolbar{height:auto}.attachments-browser .attachments,.attachments-browser .uploader-inline{top:72px}.compat-item .term-list{background-color:#fff;border:1px solid #dfdfdf;border-radius:3px;margin:0 0 10px;padding:10px 10px 5px}.compat-item .term-list li{line-height:22px}.compat-item .term-list li input[type=checkbox]{margin:-4px 4px 0 0!important;width:auto}.compat-item .term-list li input[type=checkbox]:indeterminate:before{content:'\f147';color:#CBCBCB;display:inline-block;float:left;font:400 21px/1 dashicons;margin:-3px 0 0 -4px;speak:none;vertical-align:middle;width:16px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.compat-item .term-list .children{margin:5px 0 0 20px}
|
index.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Media Library Categories
|
4 |
* Plugin URI: http://wordpress.org/plugins/wp-media-library-categories/
|
5 |
* Description: Adds the ability to use categories in the media library.
|
6 |
-
* Version: 1.
|
7 |
* Author: Jeffrey-WP
|
8 |
* Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
|
9 |
*/
|
@@ -484,6 +484,7 @@ if ( is_admin() ) {
|
|
484 |
|
485 |
/** Enqueue admin scripts and styles */
|
486 |
function wpmediacategory_enqueue_media_action() {
|
|
|
487 |
global $pagenow;
|
488 |
if ( wp_script_is( 'media-editor' ) && 'upload.php' == $pagenow ) {
|
489 |
|
@@ -524,8 +525,9 @@ if ( is_admin() ) {
|
|
524 |
echo '/* ]]> */';
|
525 |
echo '</script>';
|
526 |
|
527 |
-
wp_enqueue_script( 'wpmediacategory-media-views', plugins_url( 'js/wpmediacategory-media-views.min.js', __FILE__ ), array( 'media-views' ), '1.
|
528 |
}
|
|
|
529 |
}
|
530 |
add_action( 'admin_enqueue_scripts', 'wpmediacategory_enqueue_media_action' );
|
531 |
|
@@ -550,5 +552,156 @@ if ( is_admin() ) {
|
|
550 |
|
551 |
}
|
552 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
}
|
554 |
?>
|
3 |
* Plugin Name: Media Library Categories
|
4 |
* Plugin URI: http://wordpress.org/plugins/wp-media-library-categories/
|
5 |
* Description: Adds the ability to use categories in the media library.
|
6 |
+
* Version: 1.5.0
|
7 |
* Author: Jeffrey-WP
|
8 |
* Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
|
9 |
*/
|
484 |
|
485 |
/** Enqueue admin scripts and styles */
|
486 |
function wpmediacategory_enqueue_media_action() {
|
487 |
+
|
488 |
global $pagenow;
|
489 |
if ( wp_script_is( 'media-editor' ) && 'upload.php' == $pagenow ) {
|
490 |
|
525 |
echo '/* ]]> */';
|
526 |
echo '</script>';
|
527 |
|
528 |
+
wp_enqueue_script( 'wpmediacategory-media-views', plugins_url( 'js/wpmediacategory-media-views.min.js', __FILE__ ), array( 'media-views' ), '1.5.0', true );
|
529 |
}
|
530 |
+
wp_enqueue_style( 'wpmediacategory', plugins_url( 'css/wpmediacategory.min.css', __FILE__ ), array(), '1.5.0' );
|
531 |
}
|
532 |
add_action( 'admin_enqueue_scripts', 'wpmediacategory_enqueue_media_action' );
|
533 |
|
552 |
|
553 |
}
|
554 |
|
555 |
+
|
556 |
+
/** Save categories from attachment details on insert media popup */
|
557 |
+
function wpmediacategory_save_attachment_compat() {
|
558 |
+
|
559 |
+
if ( ! isset( $_REQUEST['id'] ) ) {
|
560 |
+
wp_send_json_error();
|
561 |
+
}
|
562 |
+
|
563 |
+
if ( ! $id = absint( $_REQUEST['id'] ) ) {
|
564 |
+
wp_send_json_error();
|
565 |
+
}
|
566 |
+
|
567 |
+
if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
|
568 |
+
wp_send_json_error();
|
569 |
+
}
|
570 |
+
$attachment_data = $_REQUEST['attachments'][ $id ];
|
571 |
+
|
572 |
+
check_ajax_referer( 'update-post_' . $id, 'nonce' );
|
573 |
+
|
574 |
+
if ( ! current_user_can( 'edit_post', $id ) ) {
|
575 |
+
wp_send_json_error();
|
576 |
+
}
|
577 |
+
|
578 |
+
$post = get_post( $id, ARRAY_A );
|
579 |
+
|
580 |
+
if ( 'attachment' != $post['post_type'] ) {
|
581 |
+
wp_send_json_error();
|
582 |
+
}
|
583 |
+
|
584 |
+
/** This filter is documented in wp-admin/includes/media.php */
|
585 |
+
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
|
586 |
+
|
587 |
+
if ( isset( $post['errors'] ) ) {
|
588 |
+
$errors = $post['errors']; // @todo return me and display me!
|
589 |
+
unset( $post['errors'] );
|
590 |
+
}
|
591 |
+
|
592 |
+
wp_update_post( $post );
|
593 |
+
|
594 |
+
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
|
595 |
+
if ( isset( $attachment_data[ $taxonomy ] ) ) {
|
596 |
+
wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
|
597 |
+
} else if ( isset($_REQUEST['tax_input']) && isset( $_REQUEST['tax_input'][ $taxonomy ] ) ) {
|
598 |
+
wp_set_object_terms( $id, $_REQUEST['tax_input'][ $taxonomy ], $taxonomy, false );
|
599 |
+
} else {
|
600 |
+
wp_set_object_terms( $id, '', $taxonomy, false );
|
601 |
+
}
|
602 |
+
}
|
603 |
+
|
604 |
+
if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) {
|
605 |
+
wp_send_json_error();
|
606 |
+
}
|
607 |
+
|
608 |
+
wp_send_json_success( $attachment );
|
609 |
+
}
|
610 |
+
add_action( 'wp_ajax_save-attachment-compat', 'wpmediacategory_save_attachment_compat', 0 );
|
611 |
+
|
612 |
+
|
613 |
+
/** Add category checkboxes to attachment details on insert media popup */
|
614 |
+
function wpmediacategory_attachment_fields_to_edit( $form_fields, $post ) {
|
615 |
+
|
616 |
+
foreach ( get_attachment_taxonomies( $post->ID ) as $taxonomy ) {
|
617 |
+
$terms = get_object_term_cache( $post->ID, $taxonomy );
|
618 |
+
|
619 |
+
$t = (array)get_taxonomy( $taxonomy );
|
620 |
+
if ( ! $t['public'] || ! $t['show_ui'] ) {
|
621 |
+
continue;
|
622 |
+
}
|
623 |
+
if ( empty($t['label']) ) {
|
624 |
+
$t['label'] = $taxonomy;
|
625 |
+
}
|
626 |
+
if ( empty($t['args']) ) {
|
627 |
+
$t['args'] = array();
|
628 |
+
}
|
629 |
+
|
630 |
+
if ( false === $terms ) {
|
631 |
+
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
|
632 |
+
}
|
633 |
+
|
634 |
+
$values = array();
|
635 |
+
|
636 |
+
foreach ( $terms as $term ) {
|
637 |
+
$values[] = $term->slug;
|
638 |
+
}
|
639 |
+
|
640 |
+
$t['value'] = join(', ', $values);
|
641 |
+
$t['show_in_edit'] = false;
|
642 |
+
|
643 |
+
if ( $t['hierarchical'] ) {
|
644 |
+
ob_start();
|
645 |
+
|
646 |
+
wp_terms_checklist( $post->ID, array( 'taxonomy' => $taxonomy, 'checked_ontop' => false, 'walker' => new wpmediacategory_walker_media_taxonomy_checklist() ) );
|
647 |
+
|
648 |
+
if ( ob_get_contents() != false ) {
|
649 |
+
$html = '<ul class="term-list">' . ob_get_contents() . '</ul>';
|
650 |
+
} else {
|
651 |
+
$html = '<ul class="term-list"><li>No ' . $t['label'] . '</li></ul>';
|
652 |
+
}
|
653 |
+
|
654 |
+
ob_end_clean();
|
655 |
+
|
656 |
+
$t['input'] = 'html';
|
657 |
+
$t['html'] = $html;
|
658 |
+
}
|
659 |
+
|
660 |
+
$form_fields[$taxonomy] = $t;
|
661 |
+
}
|
662 |
+
|
663 |
+
return $form_fields;
|
664 |
+
}
|
665 |
+
add_filter( 'attachment_fields_to_edit', 'wpmediacategory_attachment_fields_to_edit', 10, 2 );
|
666 |
+
|
667 |
+
|
668 |
+
/** Custom walker for wp_dropdown_categories for media grid view filter */
|
669 |
+
class wpmediacategory_walker_media_taxonomy_checklist extends Walker {
|
670 |
+
|
671 |
+
var $tree_type = 'category';
|
672 |
+
var $db_fields = array(
|
673 |
+
'parent' => 'parent',
|
674 |
+
'id' => 'term_id'
|
675 |
+
);
|
676 |
+
|
677 |
+
function start_lvl( &$output, $depth = 0, $args = array() ) {
|
678 |
+
$indent = str_repeat( "\t", $depth );
|
679 |
+
$output .= "$indent<ul class='children'>\n";
|
680 |
+
}
|
681 |
+
|
682 |
+
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
683 |
+
$indent = str_repeat("\t", $depth);
|
684 |
+
$output .= "$indent</ul>\n";
|
685 |
+
}
|
686 |
+
|
687 |
+
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
688 |
+
extract( $args );
|
689 |
+
|
690 |
+
// Default taxonomy
|
691 |
+
$taxonomy = 'category';
|
692 |
+
// Add filter to change the default taxonomy
|
693 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
694 |
+
|
695 |
+
$name = 'tax_input[' . $taxonomy . ']';
|
696 |
+
|
697 |
+
$class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
|
698 |
+
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->slug . '" type="checkbox" name="' . $name . '[' . $category->slug . ']" id="in-' . $taxonomy . '-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
|
699 |
+
}
|
700 |
+
|
701 |
+
function end_el( &$output, $category, $depth = 0, $args = array() ) {
|
702 |
+
$output .= "</li>\n";
|
703 |
+
}
|
704 |
+
}
|
705 |
+
|
706 |
}
|
707 |
?>
|
js/wpmediacategory-media-views.js
CHANGED
@@ -60,7 +60,7 @@ window.wp = window.wp || {};
|
|
60 |
taxonomy: taxonomy,
|
61 |
termList: values.term_list,
|
62 |
termListTitle: values.list_title,
|
63 |
-
className: 'attachment-'+taxonomy+'-filter'
|
64 |
}).render() );
|
65 |
}
|
66 |
});
|
60 |
taxonomy: taxonomy,
|
61 |
termList: values.term_list,
|
62 |
termListTitle: values.list_title,
|
63 |
+
className: 'wpmediacategory-filter attachment-'+taxonomy+'-filter'
|
64 |
}).render() );
|
65 |
}
|
66 |
});
|
js/wpmediacategory-media-views.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
window.wp=window.wp||{}
|
1 |
+
window.wp=window.wp||{},function(t){var e=wp.media;e.view.AttachmentFilters.Taxonomy=e.view.AttachmentFilters.extend({tagName:"select",createFilters:function(){var e={},o=this;_.each(o.options.termList||{},function(r,i){var a=r.term_id,n=t("<div/>").html(r.term_name).text();e[a]={text:n,priority:i+2},e[a].props={},e[a].props[o.options.taxonomy]=a}),e.all={text:o.options.termListTitle,priority:1},e.all.props={},e.all.props[o.options.taxonomy]=null,this.filters=e}});var o=e.view.AttachmentsBrowser;e.view.AttachmentsBrowser=e.view.AttachmentsBrowser.extend({createToolbar:function(){var r=this.options.filters;o.prototype.createToolbar.apply(this,arguments);var i=this,a=1;t.each(wpmediacategory_taxonomies,function(t,o){o.term_list&&r&&i.toolbar.set(t+"-filter",new e.view.AttachmentFilters.Taxonomy({controller:i.controller,model:i.collection.props,priority:-80+10*a++,taxonomy:t,termList:o.term_list,termListTitle:o.list_title,className:"wpmediacategory-filter attachment-"+t+"-filter"}).render())})}})}(jQuery);
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 4.1
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -72,12 +72,16 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
|
|
72 |
|
73 |
== Screenshots ==
|
74 |
|
75 |
-
1. Filter by category in the media library
|
76 |
2. Manage categories in the media library
|
77 |
3. Filter by category when inserting media [(premium version)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
78 |
|
79 |
== Changelog ==
|
80 |
|
|
|
|
|
|
|
|
|
81 |
= 1.4.15 =
|
82 |
* Support for WordPress 4.0
|
83 |
* Added categories filter to media grid view.
|
4 |
Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 4.1
|
7 |
+
Stable tag: 1.5
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
72 |
|
73 |
== Screenshots ==
|
74 |
|
75 |
+
1. Filter by category in the media library. Use bulk actions to add and remove categories of multiple images at once.
|
76 |
2. Manage categories in the media library
|
77 |
3. Filter by category when inserting media [(premium version)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
78 |
|
79 |
== Changelog ==
|
80 |
|
81 |
+
= 1.5 =
|
82 |
+
* Support for WordPress 4.1
|
83 |
+
* Add category checkboxes to attachment details on insert media popup
|
84 |
+
|
85 |
= 1.4.15 =
|
86 |
* Support for WordPress 4.0
|
87 |
* Added categories filter to media grid view.
|