Version Description
- Notice for first time users how to separate media categories.
- Rewrite entire plugin to improve quality and make it ready for future development.
- Move language files to GlotPress.
Download this release
Release Info
Developer | jeffrey-wp |
Plugin | Media Library Categories |
Version | 1.6 |
Comparing to | |
See all releases |
Code changes from version 1.5.6 to 1.6
- include/walkers.php +88 -0
- index.php +721 -692
- languages/wp-media-library-categories-de_DE.mo +0 -0
- languages/wp-media-library-categories-de_DE.po +0 -53
- languages/wp-media-library-categories-en_US.mo +0 -0
- languages/wp-media-library-categories-en_US.po +0 -53
- languages/wp-media-library-categories-nl_NL.mo +0 -0
- languages/wp-media-library-categories-nl_NL.po +0 -53
- languages/wp-media-library-categories.pot +50 -50
- readme.txt +22 -3
include/walkers.php
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** Custom walker for wp_dropdown_categories, based on https://gist.github.com/stephenh1988/2902509 */
|
3 |
+
class wpmediacategory_walker_category_filter extends Walker_CategoryDropdown{
|
4 |
+
|
5 |
+
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
6 |
+
$pad = str_repeat( ' ', $depth * 3 );
|
7 |
+
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
8 |
+
|
9 |
+
if( ! isset( $args['value'] ) ) {
|
10 |
+
$args['value'] = ( $category->taxonomy != 'category' ? 'slug' : 'id' );
|
11 |
+
}
|
12 |
+
|
13 |
+
$value = ( $args['value']=='slug' ? $category->slug : $category->term_id );
|
14 |
+
if ( 0 == $args['selected'] && isset( $_GET['category_media'] ) && '' != $_GET['category_media'] ) { // custom taxonomy
|
15 |
+
$args['selected'] = $_GET['category_media'];
|
16 |
+
}
|
17 |
+
|
18 |
+
$output .= '<option class="level-' . $depth . '" value="' . $value . '"';
|
19 |
+
if ( (string) $value === (string) $args['selected'] ) {
|
20 |
+
$output .= ' selected="selected"';
|
21 |
+
}
|
22 |
+
$output .= '>';
|
23 |
+
$output .= $pad . $cat_name;
|
24 |
+
if ( $args['show_count'] )
|
25 |
+
$output .= ' (' . $category->count . ')';
|
26 |
+
|
27 |
+
$output .= "</option>\n";
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
/** Custom walker for wp_dropdown_categories for media grid view filter */
|
33 |
+
class wpmediacategory_walker_category_mediagridfilter extends Walker_CategoryDropdown {
|
34 |
+
|
35 |
+
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
36 |
+
$pad = str_repeat( ' ', $depth * 3 );
|
37 |
+
|
38 |
+
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
39 |
+
|
40 |
+
// {"term_id":"1","term_name":"no category"}
|
41 |
+
$output .= ',{"term_id":"' . $category->term_id . '",';
|
42 |
+
|
43 |
+
$output .= '"term_name":"' . $pad . esc_attr( $cat_name );
|
44 |
+
if ( $args['show_count'] ) {
|
45 |
+
$output .= ' ('. $category->count .')';
|
46 |
+
}
|
47 |
+
$output .= '"}';
|
48 |
+
}
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
/** Custom walker for wp_dropdown_categories for media grid view filter */
|
53 |
+
class wpmediacategory_walker_media_taxonomy_checklist extends Walker {
|
54 |
+
|
55 |
+
var $tree_type = 'category';
|
56 |
+
var $db_fields = array(
|
57 |
+
'parent' => 'parent',
|
58 |
+
'id' => 'term_id'
|
59 |
+
);
|
60 |
+
|
61 |
+
function start_lvl( &$output, $depth = 0, $args = array() ) {
|
62 |
+
$indent = str_repeat( "\t", $depth );
|
63 |
+
$output .= "$indent<ul class='children'>\n";
|
64 |
+
}
|
65 |
+
|
66 |
+
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
67 |
+
$indent = str_repeat("\t", $depth);
|
68 |
+
$output .= "$indent</ul>\n";
|
69 |
+
}
|
70 |
+
|
71 |
+
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
72 |
+
extract( $args );
|
73 |
+
|
74 |
+
// Default taxonomy
|
75 |
+
$taxonomy = 'category';
|
76 |
+
// Add filter to change the default taxonomy
|
77 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
78 |
+
|
79 |
+
$name = 'tax_input[' . $taxonomy . ']';
|
80 |
+
|
81 |
+
$class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
|
82 |
+
$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>';
|
83 |
+
}
|
84 |
+
|
85 |
+
function end_el( &$output, $category, $depth = 0, $args = array() ) {
|
86 |
+
$output .= "</li>\n";
|
87 |
+
}
|
88 |
+
}
|
index.php
CHANGED
@@ -3,711 +3,740 @@
|
|
3 |
* Plugin Name: Media Library Categories
|
4 |
* Plugin URI: https://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 |
* Text Domain: wp-media-library-categories
|
9 |
* Domain Path: /languages
|
10 |
* Author URI: https://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
|
11 |
*/
|
12 |
|
13 |
-
/**
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
// default taxonomy
|
18 |
-
$taxonomy = 'category';
|
19 |
-
// add filter to change the default taxonomy
|
20 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
21 |
-
|
22 |
-
// select id & count from taxonomy
|
23 |
-
$query = "SELECT term_taxonomy_id, MAX(total) AS total FROM ((
|
24 |
-
SELECT tt.term_taxonomy_id, COUNT(*) AS total FROM $wpdb->term_relationships tr, $wpdb->term_taxonomy tt WHERE tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = %s GROUP BY tt.term_taxonomy_id
|
25 |
-
) UNION ALL (
|
26 |
-
SELECT term_taxonomy_id, 0 AS total FROM $wpdb->term_taxonomy WHERE taxonomy = %s
|
27 |
-
)) AS unioncount GROUP BY term_taxonomy_id";
|
28 |
-
$rsCount = $wpdb->get_results( $wpdb->prepare( $query, $taxonomy, $taxonomy ) );
|
29 |
-
// update all count values from taxonomy
|
30 |
-
foreach ( $rsCount as $rowCount ) {
|
31 |
-
$wpdb->update( $wpdb->term_taxonomy, array( 'count' => $rowCount->total ), array( 'term_taxonomy_id' => $rowCount->term_taxonomy_id ) );
|
32 |
-
}
|
33 |
}
|
34 |
|
35 |
|
36 |
-
/**
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
add_action( '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
// Add filter to change the default taxonomy
|
71 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
return false;
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
// category slug?
|
97 |
-
if ( ! is_numeric( $category ) ) {
|
98 |
-
|
99 |
-
if ( $taxonomy != 'category' ) {
|
100 |
-
|
101 |
-
$term = get_term_by( 'slug', $category, $taxonomy );
|
102 |
-
if ( false !== $term ) {
|
103 |
-
$category = $term->term_id;
|
104 |
-
} else {
|
105 |
-
// not existing category slug
|
106 |
-
$category = '';
|
107 |
-
}
|
108 |
-
|
109 |
-
} else {
|
110 |
-
|
111 |
-
$categoryObject = get_category_by_slug( $category );
|
112 |
-
if ( false !== $categoryObject ) {
|
113 |
-
$category = $categoryObject->term_id;
|
114 |
-
} else {
|
115 |
-
// not existing category slug
|
116 |
-
$category = '';
|
117 |
-
}
|
118 |
-
}
|
119 |
-
|
120 |
-
}
|
121 |
-
|
122 |
-
if ( $category != '' ) {
|
123 |
-
|
124 |
-
$ids_new = array();
|
125 |
-
|
126 |
-
if ( $taxonomy != 'category' ) {
|
127 |
-
|
128 |
-
$args = array(
|
129 |
-
'post_type' => 'attachment',
|
130 |
-
'numberposts' => -1,
|
131 |
-
'post_status' => null,
|
132 |
-
'tax_query' => array(
|
133 |
-
array(
|
134 |
-
'taxonomy' => $taxonomy,
|
135 |
-
'field' => 'id',
|
136 |
-
'terms' => $category
|
137 |
-
)
|
138 |
-
)
|
139 |
-
);
|
140 |
-
|
141 |
-
} else {
|
142 |
-
|
143 |
-
$args = array(
|
144 |
-
'post_type' => 'attachment',
|
145 |
-
'numberposts' => -1,
|
146 |
-
'post_status' => null,
|
147 |
-
'category' => $category
|
148 |
-
);
|
149 |
-
|
150 |
-
}
|
151 |
-
|
152 |
-
// use id attribute and show attachments in selected category and uploaded to post ID
|
153 |
-
if ( isset( $atts['id'] ) ) {
|
154 |
-
if ( empty( $atts['id'] ) ) {
|
155 |
-
$args['post_parent'] = get_the_ID(); // get ID of the current post if id attribute is empty
|
156 |
-
} else {
|
157 |
-
$args['post_parent'] = $atts['id'];
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
$attachments = get_posts( $args );
|
162 |
-
|
163 |
-
if ( ! empty( $attachments ) ) {
|
164 |
-
|
165 |
-
// ids attribute already present?
|
166 |
-
if ( isset( $atts['ids'] ) ) {
|
167 |
-
$ids_old = explode( ',', $atts['ids'] );
|
168 |
-
foreach ( $attachments as $attachment ) {
|
169 |
-
// preserve id if in the selected category
|
170 |
-
if ( in_array( $attachment->ID, $ids_old ) ) {
|
171 |
-
$ids_new[] = $attachment->ID;
|
172 |
-
}
|
173 |
-
}
|
174 |
-
} else {
|
175 |
-
foreach ( $attachments as $attachment ) {
|
176 |
-
$ids_new[] = $attachment->ID;
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
$atts['ids'] = $ids_new;
|
181 |
-
} else {
|
182 |
-
$atts['ids'] = array(-1); // don't display images if category is empty
|
183 |
-
}
|
184 |
-
|
185 |
-
}
|
186 |
-
if ( isset( $atts['ids'] ) ) {
|
187 |
-
$result['include'] = implode( ',', $atts['ids'] );
|
188 |
-
}
|
189 |
-
$result['category'] = $atts['category'];
|
190 |
-
|
191 |
-
}
|
192 |
-
|
193 |
-
return $result;
|
194 |
-
|
195 |
-
}
|
196 |
-
add_filter( 'shortcode_atts_gallery', 'wpmediacategory_gallery_atts', 10, 3 );
|
197 |
-
|
198 |
-
|
199 |
-
// load code that is only needed in the admin section
|
200 |
-
if ( is_admin() ) {
|
201 |
-
|
202 |
-
/** Handle default category of attachments without category */
|
203 |
-
function wpmediacategory_set_attachment_category( $post_ID ) {
|
204 |
-
|
205 |
-
// default taxonomy
|
206 |
-
$taxonomy = 'category';
|
207 |
-
// add filter to change the default taxonomy
|
208 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
209 |
-
|
210 |
-
// if attachment already have categories, stop here
|
211 |
-
if ( wp_get_object_terms( $post_ID, $taxonomy ) )
|
212 |
-
return;
|
213 |
-
|
214 |
-
// no, then get the default one
|
215 |
-
$post_category = array( get_option('default_category') );
|
216 |
-
|
217 |
-
// then set category if default category is set on writting page
|
218 |
-
if ( $post_category )
|
219 |
-
wp_set_post_categories( $post_ID, $post_category );
|
220 |
-
}
|
221 |
-
add_action( 'add_attachment', 'wpmediacategory_set_attachment_category' );
|
222 |
-
add_action( 'edit_attachment', 'wpmediacategory_set_attachment_category' );
|
223 |
-
|
224 |
-
|
225 |
-
/** Custom walker for wp_dropdown_categories, based on https://gist.github.com/stephenh1988/2902509 */
|
226 |
-
class wpmediacategory_walker_category_filter extends Walker_CategoryDropdown{
|
227 |
-
|
228 |
-
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
229 |
-
$pad = str_repeat( ' ', $depth * 3 );
|
230 |
-
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
231 |
-
|
232 |
-
if( ! isset( $args['value'] ) ) {
|
233 |
-
$args['value'] = ( $category->taxonomy != 'category' ? 'slug' : 'id' );
|
234 |
-
}
|
235 |
-
|
236 |
-
$value = ( $args['value']=='slug' ? $category->slug : $category->term_id );
|
237 |
-
if ( 0 == $args['selected'] && isset( $_GET['category_media'] ) && '' != $_GET['category_media'] ) { // custom taxonomy
|
238 |
-
$args['selected'] = $_GET['category_media'];
|
239 |
-
}
|
240 |
-
|
241 |
-
$output .= '<option class="level-' . $depth . '" value="' . $value . '"';
|
242 |
-
if ( (string) $value === (string) $args['selected'] ) {
|
243 |
-
$output .= ' selected="selected"';
|
244 |
-
}
|
245 |
-
$output .= '>';
|
246 |
-
$output .= $pad . $cat_name;
|
247 |
-
if ( $args['show_count'] )
|
248 |
-
$output .= ' (' . $category->count . ')';
|
249 |
-
|
250 |
-
$output .= "</option>\n";
|
251 |
-
}
|
252 |
-
|
253 |
-
}
|
254 |
-
|
255 |
-
|
256 |
-
/** Add a category filter */
|
257 |
-
function wpmediacategory_add_category_filter() {
|
258 |
-
global $pagenow;
|
259 |
-
if ( 'upload.php' == $pagenow ) {
|
260 |
-
// Default taxonomy
|
261 |
-
$taxonomy = 'category';
|
262 |
-
// Add filter to change the default taxonomy
|
263 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
264 |
-
if ( $taxonomy != 'category' ) {
|
265 |
-
$dropdown_options = array(
|
266 |
-
'taxonomy' => $taxonomy,
|
267 |
-
'name' => $taxonomy,
|
268 |
-
'show_option_all' => __( 'View all categories', 'wp-media-library-categories' ),
|
269 |
-
'hide_empty' => false,
|
270 |
-
'hierarchical' => true,
|
271 |
-
'orderby' => 'name',
|
272 |
-
'show_count' => true,
|
273 |
-
'walker' => new wpmediacategory_walker_category_filter(),
|
274 |
-
'value' => 'slug'
|
275 |
-
);
|
276 |
-
} else {
|
277 |
-
$dropdown_options = array(
|
278 |
-
'taxonomy' => $taxonomy,
|
279 |
-
'show_option_all' => __( 'View all categories', 'wp-media-library-categories' ),
|
280 |
-
'hide_empty' => false,
|
281 |
-
'hierarchical' => true,
|
282 |
-
'orderby' => 'name',
|
283 |
-
'show_count' => false,
|
284 |
-
'walker' => new wpmediacategory_walker_category_filter(),
|
285 |
-
'value' => 'id'
|
286 |
-
);
|
287 |
-
}
|
288 |
-
wp_dropdown_categories( $dropdown_options );
|
289 |
-
}
|
290 |
-
}
|
291 |
-
add_action( 'restrict_manage_posts', 'wpmediacategory_add_category_filter' );
|
292 |
-
|
293 |
-
|
294 |
-
/** Add custom Bulk Action to the select menus */
|
295 |
-
function wpmediacategory_custom_bulk_admin_footer() {
|
296 |
-
// default taxonomy
|
297 |
-
$taxonomy = 'category';
|
298 |
-
// add filter to change the default taxonomy
|
299 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
300 |
-
$terms = get_terms( $taxonomy, 'hide_empty=0' );
|
301 |
-
if ( $terms && ! is_wp_error( $terms ) ) :
|
302 |
-
|
303 |
-
echo '<script type="text/javascript">';
|
304 |
-
echo 'jQuery(window).load(function() {';
|
305 |
-
echo 'jQuery(\'<optgroup id="wpmediacategory_optgroup1" label="' . html_entity_decode( __( 'Categories', 'wp-media-library-categories' ), ENT_QUOTES, 'UTF-8' ) . '">\').appendTo("select[name=\'action\']");';
|
306 |
-
echo 'jQuery(\'<optgroup id="wpmediacategory_optgroup2" label="' . html_entity_decode( __( 'Categories', 'wp-media-library-categories' ), ENT_QUOTES, 'UTF-8' ) . '">\').appendTo("select[name=\'action2\']");';
|
307 |
-
|
308 |
-
// add categories
|
309 |
-
foreach ( $terms as $term ) {
|
310 |
-
$sTxtAdd = esc_js( __( 'Add', 'wp-media-library-categories' ) . ': ' . $term->name );
|
311 |
-
echo "jQuery('<option>').val('wpmediacategory_add_" . $term->term_taxonomy_id . "').text('" . $sTxtAdd . "').appendTo('#wpmediacategory_optgroup1');";
|
312 |
-
echo "jQuery('<option>').val('wpmediacategory_add_" . $term->term_taxonomy_id . "').text('" . $sTxtAdd . "').appendTo('#wpmediacategory_optgroup2');";
|
313 |
-
}
|
314 |
-
// remove categories
|
315 |
-
foreach ( $terms as $term ) {
|
316 |
-
$sTxtRemove = esc_js( __( 'Remove', 'wp-media-library-categories' ) . ': ' . $term->name );
|
317 |
-
echo "jQuery('<option>').val('wpmediacategory_remove_" . $term->term_taxonomy_id . "').text('" . $sTxtRemove . "').appendTo('#wpmediacategory_optgroup1');";
|
318 |
-
echo "jQuery('<option>').val('wpmediacategory_remove_" . $term->term_taxonomy_id . "').text('" . $sTxtRemove . "').appendTo('#wpmediacategory_optgroup2');";
|
319 |
-
}
|
320 |
-
// remove all categories
|
321 |
-
echo "jQuery('<option>').val('wpmediacategory_remove_0').text('" . esc_js( __( 'Remove all categories', 'wp-media-library-categories' ) ) . "').appendTo('#wpmediacategory_optgroup1');";
|
322 |
-
echo "jQuery('<option>').val('wpmediacategory_remove_0').text('" . esc_js( __( 'Remove all categories', 'wp-media-library-categories' ) ) . "').appendTo('#wpmediacategory_optgroup2');";
|
323 |
-
echo "});";
|
324 |
-
echo "</script>";
|
325 |
-
|
326 |
-
endif;
|
327 |
-
}
|
328 |
-
add_action( 'admin_footer-upload.php', 'wpmediacategory_custom_bulk_admin_footer' );
|
329 |
-
|
330 |
-
|
331 |
-
/** Handle the custom Bulk Action */
|
332 |
-
function wpmediacategory_custom_bulk_action() {
|
333 |
-
global $wpdb;
|
334 |
-
|
335 |
-
if ( ! isset( $_REQUEST['action'] ) ) {
|
336 |
-
return;
|
337 |
-
}
|
338 |
-
|
339 |
-
// is it a category?
|
340 |
-
$sAction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
|
341 |
-
if ( substr( $sAction, 0, 16 ) != 'wpmediacategory_' ) {
|
342 |
-
return;
|
343 |
-
}
|
344 |
-
|
345 |
-
// security check
|
346 |
-
check_admin_referer( 'bulk-media' );
|
347 |
-
|
348 |
-
// make sure ids are submitted. depending on the resource type, this may be 'media' or 'post'
|
349 |
-
if( isset( $_REQUEST['media'] ) ) {
|
350 |
-
$post_ids = array_map( 'intval', $_REQUEST['media'] );
|
351 |
-
}
|
352 |
-
|
353 |
-
if( empty( $post_ids ) ) {
|
354 |
-
return;
|
355 |
-
}
|
356 |
-
|
357 |
-
$sendback = admin_url( "upload.php?editCategory=1" );
|
358 |
-
|
359 |
-
// remember pagenumber
|
360 |
-
$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
|
361 |
-
$sendback = add_query_arg( 'paged', $pagenum, $sendback );
|
362 |
-
|
363 |
-
// remember orderby
|
364 |
-
if ( isset( $_REQUEST['orderby'] ) ) {
|
365 |
-
$sOrderby = $_REQUEST['orderby'];
|
366 |
-
$sendback = esc_url( add_query_arg( 'orderby', $sOrderby, $sendback ) );
|
367 |
-
}
|
368 |
-
// remember order
|
369 |
-
if ( isset( $_REQUEST['order'] ) ) {
|
370 |
-
$sOrder = $_REQUEST['order'];
|
371 |
-
$sendback = esc_url( add_query_arg( 'order', $sOrder, $sendback ) );
|
372 |
-
}
|
373 |
-
// remember author
|
374 |
-
if ( isset( $_REQUEST['author'] ) ) {
|
375 |
-
$sOrderby = $_REQUEST['author'];
|
376 |
-
$sendback = esc_url( add_query_arg( 'author', $sOrderby, $sendback ) );
|
377 |
-
}
|
378 |
-
|
379 |
-
foreach( $post_ids as $post_id ) {
|
380 |
-
|
381 |
-
if ( is_numeric( str_replace( 'wpmediacategory_add_', '', $sAction ) ) ) {
|
382 |
-
$nCategory = str_replace( 'wpmediacategory_add_', '', $sAction );
|
383 |
-
|
384 |
-
// update or insert category
|
385 |
-
$wpdb->replace( $wpdb->term_relationships,
|
386 |
-
array(
|
387 |
-
'object_id' => $post_id,
|
388 |
-
'term_taxonomy_id' => $nCategory
|
389 |
-
),
|
390 |
-
array(
|
391 |
-
'%d',
|
392 |
-
'%d'
|
393 |
-
)
|
394 |
-
);
|
395 |
-
|
396 |
-
} else if ( is_numeric( str_replace( 'wpmediacategory_remove_', '', $sAction ) ) ) {
|
397 |
-
$nCategory = str_replace( 'wpmediacategory_remove_', '', $sAction );
|
398 |
-
|
399 |
-
// remove all categories
|
400 |
-
if ( $nCategory == 0 ) {
|
401 |
-
$wpdb->delete( $wpdb->term_relationships,
|
402 |
-
array(
|
403 |
-
'object_id' => $post_id
|
404 |
-
),
|
405 |
-
array(
|
406 |
-
'%d'
|
407 |
-
)
|
408 |
-
);
|
409 |
-
// remove category
|
410 |
-
} else {
|
411 |
-
$wpdb->delete( $wpdb->term_relationships,
|
412 |
-
array(
|
413 |
-
'object_id' => $post_id,
|
414 |
-
'term_taxonomy_id' => $nCategory
|
415 |
-
),
|
416 |
-
array(
|
417 |
-
'%d',
|
418 |
-
'%d'
|
419 |
-
)
|
420 |
-
);
|
421 |
-
}
|
422 |
-
|
423 |
-
}
|
424 |
-
}
|
425 |
-
|
426 |
-
wpmediacategory_update_count_callback();
|
427 |
-
|
428 |
-
wp_safe_redirect( $sendback ); // perform a safe (local) redirect
|
429 |
-
exit();
|
430 |
-
}
|
431 |
-
add_action( 'load-upload.php', 'wpmediacategory_custom_bulk_action' );
|
432 |
-
|
433 |
-
|
434 |
-
/** Display an admin notice on the page after changing category */
|
435 |
-
function wpmediacategory_custom_bulk_admin_notices() {
|
436 |
-
global $post_type, $pagenow;
|
437 |
-
|
438 |
-
if ( $pagenow == 'upload.php' && $post_type == 'attachment' && isset( $_GET['editCategory'] ) ) {
|
439 |
-
echo '<div class="updated"><p>' . __( 'Category changes are saved.', 'wp-media-library-categories' ) . '</p></div>';
|
440 |
-
}
|
441 |
-
}
|
442 |
-
add_action( 'admin_notices', 'wpmediacategory_custom_bulk_admin_notices' );
|
443 |
-
|
444 |
-
|
445 |
-
/** Add a link to media categories on the plugin page */
|
446 |
-
function wpmediacategory_add_plugin_action_links( $links ) {
|
447 |
-
// default taxonomy
|
448 |
-
$taxonomy = 'category';
|
449 |
-
// add filter to change the default taxonomy
|
450 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
451 |
-
return array_merge(
|
452 |
-
array(
|
453 |
-
'settings' => '<a href="' . get_bloginfo( 'wpurl' ) . '/wp-admin/edit-tags.php?taxonomy=' . $taxonomy . '&post_type=attachment">' . __( 'Categories', 'wp-media-library-categories' ) . '</a>',
|
454 |
-
'premium' => '<a href="https://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp">' . __( 'Get Premium Version', 'wp-media-library-categories' ) . '</a>'
|
455 |
-
),
|
456 |
-
$links
|
457 |
-
);
|
458 |
-
}
|
459 |
-
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpmediacategory_add_plugin_action_links' );
|
460 |
-
|
461 |
-
|
462 |
-
/** Changing categories in the 'grid view' */
|
463 |
-
function wpmediacategory_ajax_query_attachments_args( $query = array() ) {
|
464 |
-
// grab original query, the given query has already been filtered by WordPress
|
465 |
-
$taxquery = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
|
466 |
-
|
467 |
-
$taxonomies = get_object_taxonomies( 'attachment', 'names' );
|
468 |
-
$taxquery = array_intersect_key( $taxquery, array_flip( $taxonomies ) );
|
469 |
-
|
470 |
-
// merge our query into the WordPress query
|
471 |
-
$query = array_merge( $query, $taxquery );
|
472 |
-
|
473 |
-
$query['tax_query'] = array( 'relation' => 'AND' );
|
474 |
-
|
475 |
-
foreach ( $taxonomies as $taxonomy ) {
|
476 |
-
if ( isset( $query[$taxonomy] ) && is_numeric( $query[$taxonomy] ) ) {
|
477 |
-
array_push( $query['tax_query'], array(
|
478 |
-
'taxonomy' => $taxonomy,
|
479 |
-
'field' => 'id',
|
480 |
-
'terms' => $query[$taxonomy]
|
481 |
-
) );
|
482 |
-
}
|
483 |
-
unset( $query[$taxonomy] );
|
484 |
-
}
|
485 |
-
|
486 |
-
return $query;
|
487 |
-
}
|
488 |
-
add_filter( 'ajax_query_attachments_args', 'wpmediacategory_ajax_query_attachments_args' );
|
489 |
-
|
490 |
-
|
491 |
-
/** Enqueue admin scripts and styles */
|
492 |
-
function wpmediacategory_enqueue_media_action() {
|
493 |
-
|
494 |
-
global $pagenow;
|
495 |
-
if ( wp_script_is( 'media-editor' ) && 'upload.php' == $pagenow ) {
|
496 |
-
|
497 |
-
// Default taxonomy
|
498 |
-
$taxonomy = 'category';
|
499 |
-
// Add filter to change the default taxonomy
|
500 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
501 |
-
|
502 |
-
if ( $taxonomy != 'category' ) {
|
503 |
-
$dropdown_options = array(
|
504 |
-
'taxonomy' => $taxonomy,
|
505 |
-
'hide_empty' => false,
|
506 |
-
'hierarchical' => true,
|
507 |
-
'orderby' => 'name',
|
508 |
-
'show_count' => true,
|
509 |
-
'walker' => new wpmediacategory_walker_category_mediagridfilter(),
|
510 |
-
'value' => 'id',
|
511 |
-
'echo' => false
|
512 |
-
);
|
513 |
-
} else {
|
514 |
-
$dropdown_options = array(
|
515 |
-
'taxonomy' => $taxonomy,
|
516 |
-
'hide_empty' => false,
|
517 |
-
'hierarchical' => true,
|
518 |
-
'orderby' => 'name',
|
519 |
-
'show_count' => false,
|
520 |
-
'walker' => new wpmediacategory_walker_category_mediagridfilter(),
|
521 |
-
'value' => 'id',
|
522 |
-
'echo' => false
|
523 |
-
);
|
524 |
-
}
|
525 |
-
$attachment_terms = wp_dropdown_categories( $dropdown_options );
|
526 |
-
$attachment_terms = preg_replace( array( "/<select([^>]*)>/", "/<\/select>/" ), "", $attachment_terms );
|
527 |
-
|
528 |
-
echo '<script type="text/javascript">';
|
529 |
-
echo '/* <![CDATA[ */';
|
530 |
-
echo 'var wpmediacategory_taxonomies = {"' . $taxonomy . '":{"list_title":"' . html_entity_decode( __( 'View all categories', 'wp-media-library-categories' ), ENT_QUOTES, 'UTF-8' ) . '","term_list":[' . substr( $attachment_terms, 2 ) . ']}};';
|
531 |
-
echo '/* ]]> */';
|
532 |
-
echo '</script>';
|
533 |
-
|
534 |
-
wp_enqueue_script( 'wpmediacategory-media-views', plugins_url( 'js/wpmediacategory-media-views.min.js', __FILE__ ), array( 'media-views' ), '1.5.6', true );
|
535 |
-
}
|
536 |
-
wp_enqueue_style( 'wpmediacategory', plugins_url( 'css/wpmediacategory.min.css', __FILE__ ), array(), '1.5.6' );
|
537 |
-
}
|
538 |
-
add_action( 'admin_enqueue_scripts', 'wpmediacategory_enqueue_media_action' );
|
539 |
-
|
540 |
-
|
541 |
-
/** Custom walker for wp_dropdown_categories for media grid view filter */
|
542 |
-
class wpmediacategory_walker_category_mediagridfilter extends Walker_CategoryDropdown {
|
543 |
-
|
544 |
-
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
545 |
-
$pad = str_repeat( ' ', $depth * 3 );
|
546 |
-
|
547 |
-
$cat_name = apply_filters( 'list_cats', $category->name, $category );
|
548 |
-
|
549 |
-
// {"term_id":"1","term_name":"no category"}
|
550 |
-
$output .= ',{"term_id":"' . $category->term_id . '",';
|
551 |
-
|
552 |
-
$output .= '"term_name":"' . $pad . esc_attr( $cat_name );
|
553 |
-
if ( $args['show_count'] ) {
|
554 |
-
$output .= ' ('. $category->count .')';
|
555 |
-
}
|
556 |
-
$output .= '"}';
|
557 |
-
}
|
558 |
-
|
559 |
-
}
|
560 |
-
|
561 |
-
|
562 |
-
/** Save categories from attachment details on insert media popup */
|
563 |
-
function wpmediacategory_save_attachment_compat() {
|
564 |
-
|
565 |
-
if ( ! isset( $_REQUEST['id'] ) ) {
|
566 |
-
wp_send_json_error();
|
567 |
-
}
|
568 |
-
|
569 |
-
if ( ! $id = absint( $_REQUEST['id'] ) ) {
|
570 |
-
wp_send_json_error();
|
571 |
-
}
|
572 |
-
|
573 |
-
if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
|
574 |
-
wp_send_json_error();
|
575 |
-
}
|
576 |
-
$attachment_data = $_REQUEST['attachments'][ $id ];
|
577 |
-
|
578 |
-
check_ajax_referer( 'update-post_' . $id, 'nonce' );
|
579 |
-
|
580 |
-
if ( ! current_user_can( 'edit_post', $id ) ) {
|
581 |
-
wp_send_json_error();
|
582 |
-
}
|
583 |
-
|
584 |
-
$post = get_post( $id, ARRAY_A );
|
585 |
-
|
586 |
-
if ( 'attachment' != $post['post_type'] ) {
|
587 |
-
wp_send_json_error();
|
588 |
-
}
|
589 |
-
|
590 |
-
/** This filter is documented in wp-admin/includes/media.php */
|
591 |
-
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
|
592 |
-
|
593 |
-
if ( isset( $post['errors'] ) ) {
|
594 |
-
$errors = $post['errors']; // @todo return me and display me!
|
595 |
-
unset( $post['errors'] );
|
596 |
-
}
|
597 |
-
|
598 |
-
wp_update_post( $post );
|
599 |
-
|
600 |
-
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
|
601 |
-
if ( isset( $attachment_data[ $taxonomy ] ) ) {
|
602 |
-
wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
|
603 |
-
} else if ( isset($_REQUEST['tax_input']) && isset( $_REQUEST['tax_input'][ $taxonomy ] ) ) {
|
604 |
-
wp_set_object_terms( $id, $_REQUEST['tax_input'][ $taxonomy ], $taxonomy, false );
|
605 |
-
} else {
|
606 |
-
wp_set_object_terms( $id, '', $taxonomy, false );
|
607 |
-
}
|
608 |
-
}
|
609 |
-
|
610 |
-
if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) {
|
611 |
-
wp_send_json_error();
|
612 |
-
}
|
613 |
-
|
614 |
-
wp_send_json_success( $attachment );
|
615 |
-
}
|
616 |
-
add_action( 'wp_ajax_save-attachment-compat', 'wpmediacategory_save_attachment_compat', 0 );
|
617 |
-
|
618 |
-
|
619 |
-
/** Add category checkboxes to attachment details on insert media popup */
|
620 |
-
function wpmediacategory_attachment_fields_to_edit( $form_fields, $post ) {
|
621 |
-
|
622 |
-
foreach ( get_attachment_taxonomies( $post->ID ) as $taxonomy ) {
|
623 |
-
$terms = get_object_term_cache( $post->ID, $taxonomy );
|
624 |
-
|
625 |
-
$t = (array)get_taxonomy( $taxonomy );
|
626 |
-
if ( ! $t['public'] || ! $t['show_ui'] ) {
|
627 |
-
continue;
|
628 |
-
}
|
629 |
-
if ( empty($t['label']) ) {
|
630 |
-
$t['label'] = $taxonomy;
|
631 |
-
}
|
632 |
-
if ( empty($t['args']) ) {
|
633 |
-
$t['args'] = array();
|
634 |
-
}
|
635 |
-
|
636 |
-
if ( false === $terms ) {
|
637 |
-
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
|
638 |
-
}
|
639 |
-
|
640 |
-
$values = array();
|
641 |
-
|
642 |
-
foreach ( $terms as $term ) {
|
643 |
-
$values[] = $term->slug;
|
644 |
-
}
|
645 |
-
|
646 |
-
$t['value'] = join(', ', $values);
|
647 |
-
$t['show_in_edit'] = false;
|
648 |
-
|
649 |
-
if ( $t['hierarchical'] ) {
|
650 |
-
ob_start();
|
651 |
-
|
652 |
-
wp_terms_checklist( $post->ID, array( 'taxonomy' => $taxonomy, 'checked_ontop' => false, 'walker' => new wpmediacategory_walker_media_taxonomy_checklist() ) );
|
653 |
-
|
654 |
-
if ( ob_get_contents() != false ) {
|
655 |
-
$html = '<ul class="term-list">' . ob_get_contents() . '</ul>';
|
656 |
-
} else {
|
657 |
-
$html = '<ul class="term-list"><li>No ' . $t['label'] . '</li></ul>';
|
658 |
-
}
|
659 |
-
|
660 |
-
ob_end_clean();
|
661 |
-
|
662 |
-
$t['input'] = 'html';
|
663 |
-
$t['html'] = $html;
|
664 |
-
}
|
665 |
-
|
666 |
-
$form_fields[$taxonomy] = $t;
|
667 |
-
}
|
668 |
-
|
669 |
-
return $form_fields;
|
670 |
-
}
|
671 |
-
add_filter( 'attachment_fields_to_edit', 'wpmediacategory_attachment_fields_to_edit', 10, 2 );
|
672 |
-
|
673 |
-
|
674 |
-
/** Custom walker for wp_dropdown_categories for media grid view filter */
|
675 |
-
class wpmediacategory_walker_media_taxonomy_checklist extends Walker {
|
676 |
-
|
677 |
-
var $tree_type = 'category';
|
678 |
-
var $db_fields = array(
|
679 |
-
'parent' => 'parent',
|
680 |
-
'id' => 'term_id'
|
681 |
-
);
|
682 |
-
|
683 |
-
function start_lvl( &$output, $depth = 0, $args = array() ) {
|
684 |
-
$indent = str_repeat( "\t", $depth );
|
685 |
-
$output .= "$indent<ul class='children'>\n";
|
686 |
-
}
|
687 |
-
|
688 |
-
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
689 |
-
$indent = str_repeat("\t", $depth);
|
690 |
-
$output .= "$indent</ul>\n";
|
691 |
-
}
|
692 |
-
|
693 |
-
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
694 |
-
extract( $args );
|
695 |
-
|
696 |
-
// Default taxonomy
|
697 |
-
$taxonomy = 'category';
|
698 |
-
// Add filter to change the default taxonomy
|
699 |
-
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
700 |
-
|
701 |
-
$name = 'tax_input[' . $taxonomy . ']';
|
702 |
-
|
703 |
-
$class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
|
704 |
-
$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>';
|
705 |
-
}
|
706 |
-
|
707 |
-
function end_el( &$output, $category, $depth = 0, $args = array() ) {
|
708 |
-
$output .= "</li>\n";
|
709 |
-
}
|
710 |
-
}
|
711 |
|
712 |
}
|
713 |
-
|
|
|
|
|
|
|
|
3 |
* Plugin Name: Media Library Categories
|
4 |
* Plugin URI: https://wordpress.org/plugins/wp-media-library-categories/
|
5 |
* Description: Adds the ability to use categories in the media library.
|
6 |
+
* Version: 1.6
|
7 |
* Author: Jeffrey-WP
|
8 |
* Text Domain: wp-media-library-categories
|
9 |
* Domain Path: /languages
|
10 |
* Author URI: https://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
|
11 |
*/
|
12 |
|
13 |
+
/** If this file is called directly, abort. */
|
14 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
15 |
+
exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
|
18 |
|
19 |
+
/**
|
20 |
+
* class wpMediaLibraryCategories
|
21 |
+
* the main class
|
22 |
+
*/
|
23 |
+
class wpMediaLibraryCategories {
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Initialize the hooks and filters
|
27 |
+
*/
|
28 |
+
public function __construct() {
|
29 |
+
add_action( 'plugins_loaded', array( $this, 'wpmediacategory_load_plugin_textdomain' ) );
|
30 |
+
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
31 |
+
add_action( 'init', array( $this, 'wpmediacategory_init' ) );
|
32 |
+
add_action( 'init', array( $this, 'wpmediacategory_change_category_update_count_callback' ), 100 );
|
33 |
+
|
34 |
+
add_filter( 'shortcode_atts_gallery', array( $this, 'wpmediacategory_gallery_atts' ), 10, 3 );
|
35 |
+
|
36 |
+
// load code that is only needed in the admin section
|
37 |
+
if ( is_admin() ) {
|
38 |
+
|
39 |
+
add_action( 'add_attachment', array( $this, 'wpmediacategory_set_attachment_category' ) );
|
40 |
+
add_action( 'edit_attachment', array( $this, 'wpmediacategory_set_attachment_category' ) );
|
41 |
+
add_action( 'restrict_manage_posts', array( $this, 'wpmediacategory_add_category_filter' ) );
|
42 |
+
add_action( 'admin_footer-upload.php', array( $this, 'wpmediacategory_custom_bulk_admin_footer' ) );
|
43 |
+
add_action( 'load-upload.php', array( $this, 'wpmediacategory_custom_bulk_action' ) );
|
44 |
+
add_action( 'admin_notices', array( $this, 'wpmediacategory_custom_bulk_admin_notices' ) );
|
45 |
+
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wpmediacategory_add_plugin_action_links' ) );
|
46 |
+
add_filter( 'ajax_query_attachments_args', array( $this, 'wpmediacategory_ajax_query_attachments_args' ) );
|
47 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'wpmediacategory_enqueue_media_action' ) );
|
48 |
+
add_action( 'wp_ajax_save-attachment-compat', array( $this, 'wpmediacategory_save_attachment_compat' ), 0 );
|
49 |
+
add_filter( 'attachment_fields_to_edit', array( $this, 'wpmediacategory_attachment_fields_to_edit' ), 10, 2 );
|
50 |
+
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Fired when the plugin is activated
|
57 |
+
*/
|
58 |
+
static function plugin_activation() {
|
59 |
+
// Create transient data
|
60 |
+
set_transient( 'wpmlc-admin-activation-notice', true, 60 );
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Load text domain
|
66 |
+
* @action plugins_loaded
|
67 |
+
*/
|
68 |
+
public function wpmediacategory_load_plugin_textdomain() {
|
69 |
+
load_plugin_textdomain( 'wp-media-library-categories', false, basename( dirname( __FILE__ ) ) . '/languages/' );
|
70 |
+
}
|
71 |
+
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Show admin notices
|
75 |
+
* @action admin_notices
|
76 |
+
*/
|
77 |
+
public function admin_notices() {
|
78 |
+
|
79 |
+
// Check transient, if available display notice
|
80 |
+
if ( get_transient( 'wpmlc-admin-activation-notice' ) ) {
|
81 |
+
|
82 |
+
// Default taxonomy
|
83 |
+
$taxonomy = 'category';
|
84 |
+
// Add filter to change the default taxonomy
|
85 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
86 |
+
if ( $taxonomy == 'category' ) { // check if category hasn't already been changed
|
87 |
+
?>
|
88 |
+
<div class="notice notice-info is-dismissible">
|
89 |
+
<p><?php _e( 'Thank you for using the <strong>Media Library Categories</strong> plugin.', 'wp-media-library-categories' ); ?></p>
|
90 |
+
<p><?php _e( 'By default the WordPress Media Library uses the same categories as WordPress does (such as in posts & pages).<br />
|
91 |
+
If you want to use separate categories for the WordPress Media Library take a look at our <a href="https://wordpress.org/plugins/wp-media-library-categories/#faq" target="_blank">Frequently asked questions</a>.', 'wp-media-library-categories' ); ?></p>
|
92 |
+
</div>
|
93 |
+
<?php
|
94 |
+
}
|
95 |
+
|
96 |
+
// Delete transient, only display this notice once
|
97 |
+
delete_transient( 'wpmlc-admin-activation-notice' );
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Register taxonomy for attachments
|
104 |
+
* @action init
|
105 |
+
*/
|
106 |
+
public function wpmediacategory_init() {
|
107 |
+
// Default taxonomy
|
108 |
+
$taxonomy = 'category';
|
109 |
+
// Add filter to change the default taxonomy
|
110 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
111 |
+
|
112 |
+
if ( taxonomy_exists( $taxonomy ) ) {
|
113 |
+
register_taxonomy_for_object_type( $taxonomy, 'attachment' );
|
114 |
+
} else {
|
115 |
+
$args = array(
|
116 |
+
'hierarchical' => true, // hierarchical: true = display as categories, false = display as tags
|
117 |
+
'show_admin_column' => true,
|
118 |
+
'update_count_callback' => array( &$this, 'wpmediacategory_update_count_callback' )
|
119 |
+
);
|
120 |
+
register_taxonomy( $taxonomy, array( 'attachment' ), $args );
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Change default update_count_callback for category taxonomy
|
127 |
+
* @action init
|
128 |
+
*/
|
129 |
+
public function wpmediacategory_change_category_update_count_callback() {
|
130 |
+
global $wp_taxonomies;
|
131 |
+
|
132 |
+
// Default taxonomy
|
133 |
+
$taxonomy = 'category';
|
134 |
+
// Add filter to change the default taxonomy
|
135 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
136 |
+
|
137 |
+
if ( $taxonomy == 'category' ) {
|
138 |
+
if ( ! taxonomy_exists( 'category' ) ) {
|
139 |
+
return false;
|
140 |
+
}
|
141 |
+
|
142 |
+
$new_arg = &$wp_taxonomies['category']->update_count_callback;
|
143 |
+
$new_arg = array( &$this, 'wpmediacategory_update_count_callback' );
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Custom update_count_callback
|
150 |
+
* @param array $terms
|
151 |
+
* @param string $taxonomy
|
152 |
+
*/
|
153 |
+
public function wpmediacategory_update_count_callback( $terms = array(), $taxonomy = 'category' ) {
|
154 |
+
global $wpdb;
|
155 |
+
|
156 |
+
// default taxonomy
|
157 |
+
$taxonomy = 'category';
|
158 |
+
// add filter to change the default taxonomy
|
159 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
160 |
+
|
161 |
+
// select id & count from taxonomy
|
162 |
+
$query = "SELECT term_taxonomy_id, MAX(total) AS total FROM ((
|
163 |
+
SELECT tt.term_taxonomy_id, COUNT(*) AS total FROM $wpdb->term_relationships tr, $wpdb->term_taxonomy tt WHERE tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = %s GROUP BY tt.term_taxonomy_id
|
164 |
+
) UNION ALL (
|
165 |
+
SELECT term_taxonomy_id, 0 AS total FROM $wpdb->term_taxonomy WHERE taxonomy = %s
|
166 |
+
)) AS unioncount GROUP BY term_taxonomy_id";
|
167 |
+
$rsCount = $wpdb->get_results( $wpdb->prepare( $query, $taxonomy, $taxonomy ) );
|
168 |
+
// update all count values from taxonomy
|
169 |
+
foreach ( $rsCount as $rowCount ) {
|
170 |
+
$wpdb->update( $wpdb->term_taxonomy, array( 'count' => $rowCount->total ), array( 'term_taxonomy_id' => $rowCount->term_taxonomy_id ) );
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Custom gallery shortcode
|
177 |
+
* @filter shortcode_atts_gallery
|
178 |
+
* @param array $result
|
179 |
+
* @param array $defaults
|
180 |
+
* @param array $atts
|
181 |
+
*/
|
182 |
+
public function wpmediacategory_gallery_atts( $result, $defaults, $atts ) {
|
183 |
+
|
184 |
+
if ( isset( $atts['category'] ) ) {
|
185 |
+
|
186 |
+
// Default taxonomy
|
187 |
+
$taxonomy = 'category';
|
188 |
+
// Add filter to change the default taxonomy
|
189 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
190 |
+
|
191 |
+
$category = $atts['category'];
|
192 |
+
|
193 |
+
// category slug?
|
194 |
+
if ( ! is_numeric( $category ) ) {
|
195 |
+
|
196 |
+
if ( $taxonomy != 'category' ) {
|
197 |
+
|
198 |
+
$term = get_term_by( 'slug', $category, $taxonomy );
|
199 |
+
if ( false !== $term ) {
|
200 |
+
$category = $term->term_id;
|
201 |
+
} else {
|
202 |
+
// not existing category slug
|
203 |
+
$category = '';
|
204 |
+
}
|
205 |
+
|
206 |
+
} else {
|
207 |
+
|
208 |
+
$categoryObject = get_category_by_slug( $category );
|
209 |
+
if ( false !== $categoryObject ) {
|
210 |
+
$category = $categoryObject->term_id;
|
211 |
+
} else {
|
212 |
+
// not existing category slug
|
213 |
+
$category = '';
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
}
|
218 |
+
|
219 |
+
if ( $category != '' ) {
|
220 |
+
|
221 |
+
$ids_new = array();
|
222 |
+
|
223 |
+
if ( $taxonomy != 'category' ) {
|
224 |
+
|
225 |
+
$args = array(
|
226 |
+
'post_type' => 'attachment',
|
227 |
+
'numberposts' => -1,
|
228 |
+
'post_status' => null,
|
229 |
+
'tax_query' => array(
|
230 |
+
array(
|
231 |
+
'taxonomy' => $taxonomy,
|
232 |
+
'field' => 'id',
|
233 |
+
'terms' => $category
|
234 |
+
)
|
235 |
+
)
|
236 |
+
);
|
237 |
+
|
238 |
+
} else {
|
239 |
+
|
240 |
+
$args = array(
|
241 |
+
'post_type' => 'attachment',
|
242 |
+
'numberposts' => -1,
|
243 |
+
'post_status' => null,
|
244 |
+
'category' => $category
|
245 |
+
);
|
246 |
+
|
247 |
+
}
|
248 |
+
|
249 |
+
// use id attribute and show attachments in selected category and uploaded to post ID
|
250 |
+
if ( isset( $atts['id'] ) ) {
|
251 |
+
if ( empty( $atts['id'] ) ) {
|
252 |
+
$args['post_parent'] = get_the_ID(); // get ID of the current post if id attribute is empty
|
253 |
+
} else {
|
254 |
+
$args['post_parent'] = $atts['id'];
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
$attachments = get_posts( $args );
|
259 |
+
|
260 |
+
if ( ! empty( $attachments ) ) {
|
261 |
+
|
262 |
+
// ids attribute already present?
|
263 |
+
if ( isset( $atts['ids'] ) ) {
|
264 |
+
$ids_old = explode( ',', $atts['ids'] );
|
265 |
+
foreach ( $attachments as $attachment ) {
|
266 |
+
// preserve id if in the selected category
|
267 |
+
if ( in_array( $attachment->ID, $ids_old ) ) {
|
268 |
+
$ids_new[] = $attachment->ID;
|
269 |
+
}
|
270 |
+
}
|
271 |
+
} else {
|
272 |
+
foreach ( $attachments as $attachment ) {
|
273 |
+
$ids_new[] = $attachment->ID;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
$atts['ids'] = $ids_new;
|
278 |
+
} else {
|
279 |
+
$atts['ids'] = array(-1); // don't display images if category is empty
|
280 |
+
}
|
281 |
+
|
282 |
+
}
|
283 |
+
if ( isset( $atts['ids'] ) ) {
|
284 |
+
$result['include'] = implode( ',', $atts['ids'] );
|
285 |
+
}
|
286 |
+
$result['category'] = $atts['category'];
|
287 |
+
|
288 |
+
}
|
289 |
+
|
290 |
+
return $result;
|
291 |
+
|
292 |
+
}
|
293 |
+
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Handle default category of attachments without category
|
297 |
+
* @action add_attachment
|
298 |
+
* @param array $post_ID
|
299 |
+
*/
|
300 |
+
public function wpmediacategory_set_attachment_category( $post_ID ) {
|
301 |
+
|
302 |
+
// default taxonomy
|
303 |
+
$taxonomy = 'category';
|
304 |
+
// add filter to change the default taxonomy
|
305 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
306 |
+
|
307 |
+
// if attachment already have categories, stop here
|
308 |
+
if ( wp_get_object_terms( $post_ID, $taxonomy ) ) {
|
309 |
+
return;
|
310 |
+
}
|
311 |
+
|
312 |
+
// no, then get the default one
|
313 |
+
$post_category = array( get_option( 'default_category' ) );
|
314 |
+
|
315 |
+
// then set category if default category is set on writting page
|
316 |
+
if ( $post_category ) {
|
317 |
+
wp_set_post_categories( $post_ID, $post_category );
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Add a category filter
|
324 |
+
* @action restrict_manage_posts
|
325 |
+
*/
|
326 |
+
public function wpmediacategory_add_category_filter() {
|
327 |
+
global $pagenow;
|
328 |
+
if ( 'upload.php' == $pagenow ) {
|
329 |
+
// Default taxonomy
|
330 |
+
$taxonomy = 'category';
|
331 |
+
// Add filter to change the default taxonomy
|
332 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
333 |
+
if ( $taxonomy != 'category' ) {
|
334 |
+
$dropdown_options = array(
|
335 |
+
'taxonomy' => $taxonomy,
|
336 |
+
'name' => $taxonomy,
|
337 |
+
'show_option_all' => __( 'View all categories', 'wp-media-library-categories' ),
|
338 |
+
'hide_empty' => false,
|
339 |
+
'hierarchical' => true,
|
340 |
+
'orderby' => 'name',
|
341 |
+
'show_count' => true,
|
342 |
+
'walker' => new wpmediacategory_walker_category_filter(),
|
343 |
+
'value' => 'slug'
|
344 |
+
);
|
345 |
+
} else {
|
346 |
+
$dropdown_options = array(
|
347 |
+
'taxonomy' => $taxonomy,
|
348 |
+
'show_option_all' => __( 'View all categories', 'wp-media-library-categories' ),
|
349 |
+
'hide_empty' => false,
|
350 |
+
'hierarchical' => true,
|
351 |
+
'orderby' => 'name',
|
352 |
+
'show_count' => false,
|
353 |
+
'walker' => new wpmediacategory_walker_category_filter(),
|
354 |
+
'value' => 'id'
|
355 |
+
);
|
356 |
+
}
|
357 |
+
wp_dropdown_categories( $dropdown_options );
|
358 |
+
}
|
359 |
+
}
|
360 |
+
|
361 |
+
|
362 |
+
/**
|
363 |
+
* Add custom Bulk Action to the select menus
|
364 |
+
* @action admin_footer-upload.php
|
365 |
+
*/
|
366 |
+
public function wpmediacategory_custom_bulk_admin_footer() {
|
367 |
+
// default taxonomy
|
368 |
+
$taxonomy = 'category';
|
369 |
+
// add filter to change the default taxonomy
|
370 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
371 |
+
$terms = get_terms( $taxonomy, 'hide_empty=0' );
|
372 |
+
if ( $terms && ! is_wp_error( $terms ) ) :
|
373 |
+
|
374 |
+
echo '<script type="text/javascript">';
|
375 |
+
echo 'jQuery(window).load(function() {';
|
376 |
+
echo 'jQuery(\'<optgroup id="wpmediacategory_optgroup1" label="' . html_entity_decode( __( 'Categories', 'wp-media-library-categories' ), ENT_QUOTES, 'UTF-8' ) . '">\').appendTo("select[name=\'action\']");';
|
377 |
+
echo 'jQuery(\'<optgroup id="wpmediacategory_optgroup2" label="' . html_entity_decode( __( 'Categories', 'wp-media-library-categories' ), ENT_QUOTES, 'UTF-8' ) . '">\').appendTo("select[name=\'action2\']");';
|
378 |
+
|
379 |
+
// add categories
|
380 |
+
foreach ( $terms as $term ) {
|
381 |
+
$sTxtAdd = esc_js( __( 'Add', 'wp-media-library-categories' ) . ': ' . $term->name );
|
382 |
+
echo "jQuery('<option>').val('wpmediacategory_add_" . $term->term_taxonomy_id . "').text('" . $sTxtAdd . "').appendTo('#wpmediacategory_optgroup1');";
|
383 |
+
echo "jQuery('<option>').val('wpmediacategory_add_" . $term->term_taxonomy_id . "').text('" . $sTxtAdd . "').appendTo('#wpmediacategory_optgroup2');";
|
384 |
+
}
|
385 |
+
// remove categories
|
386 |
+
foreach ( $terms as $term ) {
|
387 |
+
$sTxtRemove = esc_js( __( 'Remove', 'wp-media-library-categories' ) . ': ' . $term->name );
|
388 |
+
echo "jQuery('<option>').val('wpmediacategory_remove_" . $term->term_taxonomy_id . "').text('" . $sTxtRemove . "').appendTo('#wpmediacategory_optgroup1');";
|
389 |
+
echo "jQuery('<option>').val('wpmediacategory_remove_" . $term->term_taxonomy_id . "').text('" . $sTxtRemove . "').appendTo('#wpmediacategory_optgroup2');";
|
390 |
+
}
|
391 |
+
// remove all categories
|
392 |
+
echo "jQuery('<option>').val('wpmediacategory_remove_0').text('" . esc_js( __( 'Remove all categories', 'wp-media-library-categories' ) ) . "').appendTo('#wpmediacategory_optgroup1');";
|
393 |
+
echo "jQuery('<option>').val('wpmediacategory_remove_0').text('" . esc_js( __( 'Remove all categories', 'wp-media-library-categories' ) ) . "').appendTo('#wpmediacategory_optgroup2');";
|
394 |
+
echo "});";
|
395 |
+
echo "</script>";
|
396 |
+
|
397 |
+
endif;
|
398 |
+
}
|
399 |
+
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Handle the custom Bulk Action
|
403 |
+
* @action load-upload.php
|
404 |
+
*/
|
405 |
+
public function wpmediacategory_custom_bulk_action() {
|
406 |
+
global $wpdb;
|
407 |
+
|
408 |
+
if ( ! isset( $_REQUEST['action'] ) ) {
|
409 |
+
return;
|
410 |
+
}
|
411 |
+
|
412 |
+
// is it a category?
|
413 |
+
$sAction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
|
414 |
+
if ( substr( $sAction, 0, 16 ) != 'wpmediacategory_' ) {
|
415 |
+
return;
|
416 |
+
}
|
417 |
+
|
418 |
+
// security check
|
419 |
+
check_admin_referer( 'bulk-media' );
|
420 |
+
|
421 |
+
// make sure ids are submitted. depending on the resource type, this may be 'media' or 'post'
|
422 |
+
if( isset( $_REQUEST['media'] ) ) {
|
423 |
+
$post_ids = array_map( 'intval', $_REQUEST['media'] );
|
424 |
+
}
|
425 |
+
|
426 |
+
if( empty( $post_ids ) ) {
|
427 |
+
return;
|
428 |
+
}
|
429 |
+
|
430 |
+
$sendback = admin_url( "upload.php?editCategory=1" );
|
431 |
+
|
432 |
+
// remember pagenumber
|
433 |
+
$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
|
434 |
+
$sendback = add_query_arg( 'paged', $pagenum, $sendback );
|
435 |
+
|
436 |
+
// remember orderby
|
437 |
+
if ( isset( $_REQUEST['orderby'] ) ) {
|
438 |
+
$sOrderby = $_REQUEST['orderby'];
|
439 |
+
$sendback = esc_url( add_query_arg( 'orderby', $sOrderby, $sendback ) );
|
440 |
+
}
|
441 |
+
// remember order
|
442 |
+
if ( isset( $_REQUEST['order'] ) ) {
|
443 |
+
$sOrder = $_REQUEST['order'];
|
444 |
+
$sendback = esc_url( add_query_arg( 'order', $sOrder, $sendback ) );
|
445 |
+
}
|
446 |
+
// remember author
|
447 |
+
if ( isset( $_REQUEST['author'] ) ) {
|
448 |
+
$sOrderby = $_REQUEST['author'];
|
449 |
+
$sendback = esc_url( add_query_arg( 'author', $sOrderby, $sendback ) );
|
450 |
+
}
|
451 |
+
|
452 |
+
foreach( $post_ids as $post_id ) {
|
453 |
+
|
454 |
+
if ( is_numeric( str_replace( 'wpmediacategory_add_', '', $sAction ) ) ) {
|
455 |
+
$nCategory = str_replace( 'wpmediacategory_add_', '', $sAction );
|
456 |
+
|
457 |
+
// update or insert category
|
458 |
+
$wpdb->replace( $wpdb->term_relationships,
|
459 |
+
array(
|
460 |
+
'object_id' => $post_id,
|
461 |
+
'term_taxonomy_id' => $nCategory
|
462 |
+
),
|
463 |
+
array(
|
464 |
+
'%d',
|
465 |
+
'%d'
|
466 |
+
)
|
467 |
+
);
|
468 |
+
|
469 |
+
} else if ( is_numeric( str_replace( 'wpmediacategory_remove_', '', $sAction ) ) ) {
|
470 |
+
$nCategory = str_replace( 'wpmediacategory_remove_', '', $sAction );
|
471 |
+
|
472 |
+
// remove all categories
|
473 |
+
if ( $nCategory == 0 ) {
|
474 |
+
$wpdb->delete( $wpdb->term_relationships,
|
475 |
+
array(
|
476 |
+
'object_id' => $post_id
|
477 |
+
),
|
478 |
+
array(
|
479 |
+
'%d'
|
480 |
+
)
|
481 |
+
);
|
482 |
+
// remove category
|
483 |
+
} else {
|
484 |
+
$wpdb->delete( $wpdb->term_relationships,
|
485 |
+
array(
|
486 |
+
'object_id' => $post_id,
|
487 |
+
'term_taxonomy_id' => $nCategory
|
488 |
+
),
|
489 |
+
array(
|
490 |
+
'%d',
|
491 |
+
'%d'
|
492 |
+
)
|
493 |
+
);
|
494 |
+
}
|
495 |
+
|
496 |
+
}
|
497 |
+
}
|
498 |
+
|
499 |
+
$this->wpmediacategory_update_count_callback();
|
500 |
+
|
501 |
+
wp_safe_redirect( $sendback ); // perform a safe (local) redirect
|
502 |
+
exit();
|
503 |
+
}
|
504 |
+
|
505 |
+
|
506 |
+
/**
|
507 |
+
* Display an admin notice on the page after changing category
|
508 |
+
* @action admin_notices
|
509 |
+
*/
|
510 |
+
public function wpmediacategory_custom_bulk_admin_notices() {
|
511 |
+
global $post_type, $pagenow;
|
512 |
+
|
513 |
+
if ( $pagenow == 'upload.php' && $post_type == 'attachment' && isset( $_GET['editCategory'] ) ) {
|
514 |
+
echo '<div class="updated"><p>' . __( 'Category changes are saved.', 'wp-media-library-categories' ) . '</p></div>';
|
515 |
+
}
|
516 |
+
}
|
517 |
+
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Add a link to media categories on the plugin page
|
521 |
+
* @action plugin_action_links_*
|
522 |
+
*/
|
523 |
+
public function wpmediacategory_add_plugin_action_links( $links ) {
|
524 |
+
// default taxonomy
|
525 |
+
$taxonomy = 'category';
|
526 |
+
// add filter to change the default taxonomy
|
527 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
528 |
+
return array_merge(
|
529 |
+
array(
|
530 |
+
'settings' => '<a href="' . get_bloginfo( 'wpurl' ) . '/wp-admin/edit-tags.php?taxonomy=' . $taxonomy . '&post_type=attachment">' . __( 'Categories', 'wp-media-library-categories' ) . '</a>',
|
531 |
+
'premium' => '<a href="https://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp" style="color:#60a559;" target="_blank" title="Try Try Media Library Categories Premium today for just $20 - 100% money back guarantee">' . __( 'Try Premium Version', 'wp-media-library-categories' ) . '</a>'
|
532 |
+
),
|
533 |
+
$links
|
534 |
+
);
|
535 |
+
}
|
536 |
+
|
537 |
+
|
538 |
+
/**
|
539 |
+
* Changing categories in the 'grid view'
|
540 |
+
* @action ajax_query_attachments_args
|
541 |
+
* @param array $query
|
542 |
+
*/
|
543 |
+
public function wpmediacategory_ajax_query_attachments_args( $query = array() ) {
|
544 |
+
// grab original query, the given query has already been filtered by WordPress
|
545 |
+
$taxquery = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
|
546 |
+
|
547 |
+
$taxonomies = get_object_taxonomies( 'attachment', 'names' );
|
548 |
+
$taxquery = array_intersect_key( $taxquery, array_flip( $taxonomies ) );
|
549 |
+
|
550 |
+
// merge our query into the WordPress query
|
551 |
+
$query = array_merge( $query, $taxquery );
|
552 |
+
|
553 |
+
$query['tax_query'] = array( 'relation' => 'AND' );
|
554 |
+
|
555 |
+
foreach ( $taxonomies as $taxonomy ) {
|
556 |
+
if ( isset( $query[$taxonomy] ) && is_numeric( $query[$taxonomy] ) ) {
|
557 |
+
array_push( $query['tax_query'], array(
|
558 |
+
'taxonomy' => $taxonomy,
|
559 |
+
'field' => 'id',
|
560 |
+
'terms' => $query[$taxonomy]
|
561 |
+
) );
|
562 |
+
}
|
563 |
+
unset( $query[$taxonomy] );
|
564 |
+
}
|
565 |
+
|
566 |
+
return $query;
|
567 |
+
}
|
568 |
+
|
569 |
+
|
570 |
+
/**
|
571 |
+
* Enqueue admin scripts and styles
|
572 |
+
* @action admin_enqueue_scripts
|
573 |
+
*/
|
574 |
+
public function wpmediacategory_enqueue_media_action() {
|
575 |
+
|
576 |
+
global $pagenow;
|
577 |
+
if ( wp_script_is( 'media-editor' ) && 'upload.php' == $pagenow ) {
|
578 |
+
|
579 |
+
// Default taxonomy
|
580 |
+
$taxonomy = 'category';
|
581 |
+
// Add filter to change the default taxonomy
|
582 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
583 |
+
|
584 |
+
if ( $taxonomy != 'category' ) {
|
585 |
+
$dropdown_options = array(
|
586 |
+
'taxonomy' => $taxonomy,
|
587 |
+
'hide_empty' => false,
|
588 |
+
'hierarchical' => true,
|
589 |
+
'orderby' => 'name',
|
590 |
+
'show_count' => true,
|
591 |
+
'walker' => new wpmediacategory_walker_category_mediagridfilter(),
|
592 |
+
'value' => 'id',
|
593 |
+
'echo' => false
|
594 |
+
);
|
595 |
+
} else {
|
596 |
+
$dropdown_options = array(
|
597 |
+
'taxonomy' => $taxonomy,
|
598 |
+
'hide_empty' => false,
|
599 |
+
'hierarchical' => true,
|
600 |
+
'orderby' => 'name',
|
601 |
+
'show_count' => false,
|
602 |
+
'walker' => new wpmediacategory_walker_category_mediagridfilter(),
|
603 |
+
'value' => 'id',
|
604 |
+
'echo' => false
|
605 |
+
);
|
606 |
+
}
|
607 |
+
$attachment_terms = wp_dropdown_categories( $dropdown_options );
|
608 |
+
$attachment_terms = preg_replace( array( "/<select([^>]*)>/", "/<\/select>/" ), "", $attachment_terms );
|
609 |
+
|
610 |
+
echo '<script type="text/javascript">';
|
611 |
+
echo '/* <![CDATA[ */';
|
612 |
+
echo 'var wpmediacategory_taxonomies = {"' . $taxonomy . '":{"list_title":"' . html_entity_decode( __( 'View all categories', 'wp-media-library-categories' ), ENT_QUOTES, 'UTF-8' ) . '","term_list":[' . substr( $attachment_terms, 2 ) . ']}};';
|
613 |
+
echo '/* ]]> */';
|
614 |
+
echo '</script>';
|
615 |
+
|
616 |
+
wp_enqueue_script( 'wpmediacategory-media-views', plugins_url( 'js/wpmediacategory-media-views.min.js', __FILE__ ), array( 'media-views' ), '1.6', true );
|
617 |
+
}
|
618 |
+
wp_enqueue_style( 'wpmediacategory', plugins_url( 'css/wpmediacategory.min.css', __FILE__ ), array(), '1.6' );
|
619 |
+
}
|
620 |
+
|
621 |
+
|
622 |
+
/**
|
623 |
+
* Save categories from attachment details on insert media popup
|
624 |
+
* @action wp_ajax_save-attachment-compat
|
625 |
+
*/
|
626 |
+
public function wpmediacategory_save_attachment_compat() {
|
627 |
+
|
628 |
+
if ( ! isset( $_REQUEST['id'] ) ) {
|
629 |
+
wp_send_json_error();
|
630 |
+
}
|
631 |
+
|
632 |
+
if ( ! $id = absint( $_REQUEST['id'] ) ) {
|
633 |
+
wp_send_json_error();
|
634 |
+
}
|
635 |
+
|
636 |
+
if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
|
637 |
+
wp_send_json_error();
|
638 |
+
}
|
639 |
+
$attachment_data = $_REQUEST['attachments'][ $id ];
|
640 |
+
|
641 |
+
check_ajax_referer( 'update-post_' . $id, 'nonce' );
|
642 |
+
|
643 |
+
if ( ! current_user_can( 'edit_post', $id ) ) {
|
644 |
+
wp_send_json_error();
|
645 |
+
}
|
646 |
+
|
647 |
+
$post = get_post( $id, ARRAY_A );
|
648 |
+
|
649 |
+
if ( 'attachment' != $post['post_type'] ) {
|
650 |
+
wp_send_json_error();
|
651 |
+
}
|
652 |
+
|
653 |
+
/** This filter is documented in wp-admin/includes/media.php */
|
654 |
+
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
|
655 |
+
|
656 |
+
if ( isset( $post['errors'] ) ) {
|
657 |
+
$errors = $post['errors']; // @todo return me and display me!
|
658 |
+
unset( $post['errors'] );
|
659 |
+
}
|
660 |
+
|
661 |
+
wp_update_post( $post );
|
662 |
+
|
663 |
+
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
|
664 |
+
if ( isset( $attachment_data[ $taxonomy ] ) ) {
|
665 |
+
wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
|
666 |
+
} else if ( isset($_REQUEST['tax_input']) && isset( $_REQUEST['tax_input'][ $taxonomy ] ) ) {
|
667 |
+
wp_set_object_terms( $id, $_REQUEST['tax_input'][ $taxonomy ], $taxonomy, false );
|
668 |
+
} else {
|
669 |
+
wp_set_object_terms( $id, '', $taxonomy, false );
|
670 |
+
}
|
671 |
+
}
|
672 |
+
|
673 |
+
if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) {
|
674 |
+
wp_send_json_error();
|
675 |
+
}
|
676 |
+
|
677 |
+
wp_send_json_success( $attachment );
|
678 |
+
}
|
679 |
+
|
680 |
+
|
681 |
+
/**
|
682 |
+
* Add category checkboxes to attachment details on insert media popup
|
683 |
+
* @action attachment_fields_to_edit
|
684 |
+
*/
|
685 |
+
public function wpmediacategory_attachment_fields_to_edit( $form_fields, $post ) {
|
686 |
+
|
687 |
+
foreach ( get_attachment_taxonomies( $post->ID ) as $taxonomy ) {
|
688 |
+
$terms = get_object_term_cache( $post->ID, $taxonomy );
|
689 |
+
|
690 |
+
$t = (array)get_taxonomy( $taxonomy );
|
691 |
+
if ( ! $t['public'] || ! $t['show_ui'] ) {
|
692 |
+
continue;
|
693 |
+
}
|
694 |
+
if ( empty($t['label']) ) {
|
695 |
+
$t['label'] = $taxonomy;
|
696 |
+
}
|
697 |
+
if ( empty($t['args']) ) {
|
698 |
+
$t['args'] = array();
|
699 |
+
}
|
700 |
+
|
701 |
+
if ( false === $terms ) {
|
702 |
+
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
|
703 |
+
}
|
704 |
|
705 |
+
$values = array();
|
706 |
|
707 |
+
foreach ( $terms as $term ) {
|
708 |
+
$values[] = $term->slug;
|
709 |
+
}
|
710 |
|
711 |
+
$t['value'] = join(', ', $values);
|
712 |
+
$t['show_in_edit'] = false;
|
|
|
|
|
713 |
|
714 |
+
if ( $t['hierarchical'] ) {
|
715 |
+
ob_start();
|
|
|
716 |
|
717 |
+
wp_terms_checklist( $post->ID, array( 'taxonomy' => $taxonomy, 'checked_ontop' => false, 'walker' => new wpmediacategory_walker_media_taxonomy_checklist() ) );
|
718 |
+
|
719 |
+
if ( ob_get_contents() != false ) {
|
720 |
+
$html = '<ul class="term-list">' . ob_get_contents() . '</ul>';
|
721 |
+
} else {
|
722 |
+
$html = '<ul class="term-list"><li>No ' . $t['label'] . '</li></ul>';
|
723 |
+
}
|
724 |
+
|
725 |
+
ob_end_clean();
|
726 |
+
|
727 |
+
$t['input'] = 'html';
|
728 |
+
$t['html'] = $html;
|
729 |
+
}
|
730 |
+
|
731 |
+
$form_fields[$taxonomy] = $t;
|
732 |
+
}
|
733 |
+
|
734 |
+
return $form_fields;
|
735 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
736 |
|
737 |
}
|
738 |
+
$wpmedialibrarycategories = new wpMediaLibraryCategories();
|
739 |
+
|
740 |
+
include_once( 'include/walkers.php' );
|
741 |
+
|
742 |
+
register_activation_hook( __FILE__, array( 'wpMediaLibraryCategories', 'plugin_activation' ) );
|
languages/wp-media-library-categories-de_DE.mo
DELETED
Binary file
|
languages/wp-media-library-categories-de_DE.po
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
# Copyright (C) 2016 Media Library Categories
|
2 |
-
# This file is distributed under the same license as the Media Library Categories package.
|
3 |
-
msgid ""
|
4 |
-
msgstr ""
|
5 |
-
"Project-Id-Version: Media Library Categories\n"
|
6 |
-
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-media-library-categories\n"
|
7 |
-
"POT-Creation-Date: 2016-07-18 18:51:21+00:00\n"
|
8 |
-
"MIME-Version: 1.0\n"
|
9 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
-
"Content-Transfer-Encoding: 8bit\n"
|
11 |
-
"PO-Revision-Date: 2016-07-18 21:16+0100\n"
|
12 |
-
"Last-Translator: \n"
|
13 |
-
"Language-Team: \n"
|
14 |
-
"X-Generator: Poedit 1.7.6\n"
|
15 |
-
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
16 |
-
"Language: de_DE\n"
|
17 |
-
"X-Poedit-SourceCharset: UTF-8\n"
|
18 |
-
|
19 |
-
#: index.php:250 index.php:261 index.php:529
|
20 |
-
msgid "View all categories"
|
21 |
-
msgstr "Alle Kategorien anzeigen"
|
22 |
-
|
23 |
-
#: index.php:287 index.php:288 index.php:435
|
24 |
-
msgid "Categories"
|
25 |
-
msgstr "Kategorien"
|
26 |
-
|
27 |
-
#: index.php:292
|
28 |
-
msgid "Add"
|
29 |
-
msgstr "Hinzufügen"
|
30 |
-
|
31 |
-
#: index.php:298
|
32 |
-
msgid "Remove"
|
33 |
-
msgstr "Löschen"
|
34 |
-
|
35 |
-
#: index.php:303 index.php:304
|
36 |
-
msgid "Remove all categories"
|
37 |
-
msgstr "Alle Kategorien löschen"
|
38 |
-
|
39 |
-
#: index.php:421
|
40 |
-
msgid "Category changes are saved."
|
41 |
-
msgstr "Kategorie Änderungen werden gespeichert."
|
42 |
-
|
43 |
-
#: index.php:436
|
44 |
-
msgid "Get Premium Version"
|
45 |
-
msgstr "Get Premium Version"
|
46 |
-
|
47 |
-
#. Plugin Name of the plugin/theme
|
48 |
-
msgid "Media Library Categories"
|
49 |
-
msgstr "Media Library Categories"
|
50 |
-
|
51 |
-
#. Description of the plugin/theme
|
52 |
-
msgid "Adds the ability to use categories in the media library."
|
53 |
-
msgstr "Fügt die Fähigkeit, die Kategorien in der Medienbibliothek zu verwenden."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/wp-media-library-categories-en_US.mo
DELETED
Binary file
|
languages/wp-media-library-categories-en_US.po
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
# Copyright (C) 2016 Media Library Categories
|
2 |
-
# This file is distributed under the same license as the Media Library Categories package.
|
3 |
-
msgid ""
|
4 |
-
msgstr ""
|
5 |
-
"Project-Id-Version: Media Library Categories\n"
|
6 |
-
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-media-library-categories\n"
|
7 |
-
"POT-Creation-Date: 2016-07-18 18:51:21+00:00\n"
|
8 |
-
"MIME-Version: 1.0\n"
|
9 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
-
"Content-Transfer-Encoding: 8bit\n"
|
11 |
-
"PO-Revision-Date: 2016-07-18 21:06+0100\n"
|
12 |
-
"Last-Translator: \n"
|
13 |
-
"Language-Team: \n"
|
14 |
-
"X-Generator: Poedit 1.7.6\n"
|
15 |
-
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
16 |
-
"Language: en_US\n"
|
17 |
-
"X-Poedit-SourceCharset: UTF-8\n"
|
18 |
-
|
19 |
-
#: index.php:250 index.php:261 index.php:529
|
20 |
-
msgid "View all categories"
|
21 |
-
msgstr "View all categories"
|
22 |
-
|
23 |
-
#: index.php:287 index.php:288 index.php:435
|
24 |
-
msgid "Categories"
|
25 |
-
msgstr "Categories"
|
26 |
-
|
27 |
-
#: index.php:292
|
28 |
-
msgid "Add"
|
29 |
-
msgstr "Add"
|
30 |
-
|
31 |
-
#: index.php:298
|
32 |
-
msgid "Remove"
|
33 |
-
msgstr "Remove"
|
34 |
-
|
35 |
-
#: index.php:303 index.php:304
|
36 |
-
msgid "Remove all categories"
|
37 |
-
msgstr "Remove all categories"
|
38 |
-
|
39 |
-
#: index.php:421
|
40 |
-
msgid "Category changes are saved."
|
41 |
-
msgstr "Category changes are saved."
|
42 |
-
|
43 |
-
#: index.php:436
|
44 |
-
msgid "Get Premium Version"
|
45 |
-
msgstr "Get Premium Version"
|
46 |
-
|
47 |
-
#. Plugin Name of the plugin/theme
|
48 |
-
msgid "Media Library Categories"
|
49 |
-
msgstr "Media Library Categories"
|
50 |
-
|
51 |
-
#. Description of the plugin/theme
|
52 |
-
msgid "Adds the ability to use categories in the media library."
|
53 |
-
msgstr "Adds the ability to use categories in the media library."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/wp-media-library-categories-nl_NL.mo
DELETED
Binary file
|
languages/wp-media-library-categories-nl_NL.po
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
# Copyright (C) 2016 Media Library Categories
|
2 |
-
# This file is distributed under the same license as the Media Library Categories package.
|
3 |
-
msgid ""
|
4 |
-
msgstr ""
|
5 |
-
"Project-Id-Version: Media Library Categories\n"
|
6 |
-
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-media-library-categories\n"
|
7 |
-
"POT-Creation-Date: 2016-07-18 18:51:21+00:00\n"
|
8 |
-
"MIME-Version: 1.0\n"
|
9 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
-
"Content-Transfer-Encoding: 8bit\n"
|
11 |
-
"PO-Revision-Date: 2016-07-18 22:34+0100\n"
|
12 |
-
"Last-Translator: \n"
|
13 |
-
"Language-Team: \n"
|
14 |
-
"X-Generator: Poedit 1.7.6\n"
|
15 |
-
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
16 |
-
"Language: nl_NL\n"
|
17 |
-
"X-Poedit-SourceCharset: UTF-8\n"
|
18 |
-
|
19 |
-
#: index.php:250 index.php:261 index.php:529
|
20 |
-
msgid "View all categories"
|
21 |
-
msgstr "Bekijk alle categorieën"
|
22 |
-
|
23 |
-
#: index.php:287 index.php:288 index.php:435
|
24 |
-
msgid "Categories"
|
25 |
-
msgstr "Categorieën"
|
26 |
-
|
27 |
-
#: index.php:292
|
28 |
-
msgid "Add"
|
29 |
-
msgstr "Toevoegen"
|
30 |
-
|
31 |
-
#: index.php:298
|
32 |
-
msgid "Remove"
|
33 |
-
msgstr "Verwijder"
|
34 |
-
|
35 |
-
#: index.php:303 index.php:304
|
36 |
-
msgid "Remove all categories"
|
37 |
-
msgstr "Verwijder alle categorieën"
|
38 |
-
|
39 |
-
#: index.php:421
|
40 |
-
msgid "Category changes are saved."
|
41 |
-
msgstr "Categoriewijzigingen zijn opgeslagen."
|
42 |
-
|
43 |
-
#: index.php:436
|
44 |
-
msgid "Get Premium Version"
|
45 |
-
msgstr "Opwaarderen naar Premium"
|
46 |
-
|
47 |
-
#. Plugin Name of the plugin/theme
|
48 |
-
msgid "Media Library Categories"
|
49 |
-
msgstr "Media Library Categories"
|
50 |
-
|
51 |
-
#. Description of the plugin/theme
|
52 |
-
msgid "Adds the ability to use categories in the media library."
|
53 |
-
msgstr "Voegt de mogelijkheid toe om categorieën in de mediabibliotheek te gebruiken."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/wp-media-library-categories.pot
CHANGED
@@ -1,50 +1,50 @@
|
|
1 |
-
# Copyright (C) 2016 Media Library Categories
|
2 |
-
# This file is distributed under the same license as the Media Library Categories package.
|
3 |
-
msgid ""
|
4 |
-
msgstr ""
|
5 |
-
"Project-Id-Version: Media Library Categories 1.5.3\n"
|
6 |
-
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-media-library-"
|
7 |
-
"categories\n"
|
8 |
-
"POT-Creation-Date: 2016-07-18 18:51:21+00:00\n"
|
9 |
-
"MIME-Version: 1.0\n"
|
10 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
-
"Content-Transfer-Encoding: 8bit\n"
|
12 |
-
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
|
13 |
-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
-
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
-
|
16 |
-
#: index.php:250 index.php:261 index.php:529
|
17 |
-
msgid "View all categories"
|
18 |
-
msgstr ""
|
19 |
-
|
20 |
-
#: index.php:287 index.php:288 index.php:435
|
21 |
-
msgid "Categories"
|
22 |
-
msgstr ""
|
23 |
-
|
24 |
-
#: index.php:292
|
25 |
-
msgid "Add"
|
26 |
-
msgstr ""
|
27 |
-
|
28 |
-
#: index.php:298
|
29 |
-
msgid "Remove"
|
30 |
-
msgstr ""
|
31 |
-
|
32 |
-
#: index.php:303 index.php:304
|
33 |
-
msgid "Remove all categories"
|
34 |
-
msgstr ""
|
35 |
-
|
36 |
-
#: index.php:421
|
37 |
-
msgid "Category changes are saved."
|
38 |
-
msgstr ""
|
39 |
-
|
40 |
-
#: index.php:436
|
41 |
-
msgid "Get Premium Version"
|
42 |
-
msgstr ""
|
43 |
-
|
44 |
-
#. Plugin Name of the plugin/theme
|
45 |
-
msgid "Media Library Categories"
|
46 |
-
msgstr ""
|
47 |
-
|
48 |
-
#. Description of the plugin/theme
|
49 |
-
msgid "Adds the ability to use categories in the media library."
|
50 |
-
msgstr ""
|
1 |
+
# Copyright (C) 2016 Media Library Categories
|
2 |
+
# This file is distributed under the same license as the Media Library Categories package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Media Library Categories 1.5.3\n"
|
6 |
+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-media-library-"
|
7 |
+
"categories\n"
|
8 |
+
"POT-Creation-Date: 2016-07-18 18:51:21+00:00\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
|
13 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
+
|
16 |
+
#: index.php:250 index.php:261 index.php:529
|
17 |
+
msgid "View all categories"
|
18 |
+
msgstr ""
|
19 |
+
|
20 |
+
#: index.php:287 index.php:288 index.php:435
|
21 |
+
msgid "Categories"
|
22 |
+
msgstr ""
|
23 |
+
|
24 |
+
#: index.php:292
|
25 |
+
msgid "Add"
|
26 |
+
msgstr ""
|
27 |
+
|
28 |
+
#: index.php:298
|
29 |
+
msgid "Remove"
|
30 |
+
msgstr ""
|
31 |
+
|
32 |
+
#: index.php:303 index.php:304
|
33 |
+
msgid "Remove all categories"
|
34 |
+
msgstr ""
|
35 |
+
|
36 |
+
#: index.php:421
|
37 |
+
msgid "Category changes are saved."
|
38 |
+
msgstr ""
|
39 |
+
|
40 |
+
#: index.php:436
|
41 |
+
msgid "Get Premium Version"
|
42 |
+
msgstr ""
|
43 |
+
|
44 |
+
#. Plugin Name of the plugin/theme
|
45 |
+
msgid "Media Library Categories"
|
46 |
+
msgstr ""
|
47 |
+
|
48 |
+
#. Description of the plugin/theme
|
49 |
+
msgid "Adds the ability to use categories in the media library."
|
50 |
+
msgstr ""
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: jeffrey-wp
|
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSNQMST6R28Q2
|
4 |
Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
|
5 |
Requires at least: 3.1
|
6 |
-
Tested up to: 4.9
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -13,7 +13,21 @@ Adds the ability to use categories in the media library.
|
|
13 |
== Description ==
|
14 |
|
15 |
Adds the ability to use categories in the WordPress Media Library. When activated a dropdown of categories will show up in the media library.
|
16 |
-
You can change the category of multiple items at once with bulk actions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
== Installation ==
|
19 |
|
@@ -81,6 +95,11 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
|
|
81 |
|
82 |
== Changelog ==
|
83 |
|
|
|
|
|
|
|
|
|
|
|
84 |
= 1.5.6 =
|
85 |
* Remember pagenumber when using bulk actions
|
86 |
* Only use wp_safe_redirect instead of wp_redirect
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSNQMST6R28Q2
|
4 |
Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
|
5 |
Requires at least: 3.1
|
6 |
+
Tested up to: 4.9.3
|
7 |
+
Stable tag: 1.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
13 |
== Description ==
|
14 |
|
15 |
Adds the ability to use categories in the WordPress Media Library. When activated a dropdown of categories will show up in the media library.
|
16 |
+
You can change / add / remove the category of multiple items at once with bulk actions.
|
17 |
+
There is even an option to filter on categories when using the gallery shortcode.
|
18 |
+
|
19 |
+
= Features WordPress Media Library Categories =
|
20 |
+
* add / edit / remove categories from media items
|
21 |
+
* change the category of multiple items at once with bulk actions
|
22 |
+
* category options & management in the Media Library
|
23 |
+
* filter on categories in the media library
|
24 |
+
* filter on categories in the gallery shortcode
|
25 |
+
* taxonomy filter
|
26 |
+
* support for WordPress 3.1 – 4.9
|
27 |
+
|
28 |
+
> <strong>Try Premium version - 100% money back guarantee</strong>
|
29 |
+
> WordPress Media Library Categories Premium adds the option to filter on categories when inserting media into a post or page.
|
30 |
+
> [Try now - 100% money back guarantee](https://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
31 |
|
32 |
== Installation ==
|
33 |
|
95 |
|
96 |
== Changelog ==
|
97 |
|
98 |
+
= 1.6 =
|
99 |
+
* Notice for first time users how to separate media categories.
|
100 |
+
* Rewrite entire plugin to improve quality and make it ready for future development.
|
101 |
+
* Move language files to GlotPress.
|
102 |
+
|
103 |
= 1.5.6 =
|
104 |
* Remember pagenumber when using bulk actions
|
105 |
* Only use wp_safe_redirect instead of wp_redirect
|