Version Description
- Fixed media count on the categories page.
- Add item count in the category filter dropdown when using separate categories for the WordPress Media Library.
- Support for WordPress 3.9
Download this release
Release Info
Developer | jeffrey-wp |
Plugin | Media Library Categories |
Version | 1.4.8 |
Comparing to | |
See all releases |
Code changes from version 1.4.7 to 1.4.8
- index.php +60 -9
- readme.txt +22 -17
index.php
CHANGED
@@ -3,11 +3,34 @@
|
|
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.4.
|
7 |
* Author: Jeffrey-WP
|
8 |
* Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
|
9 |
*/
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
/** register taxonomy for attachments */
|
12 |
function wpmediacategory_init() {
|
13 |
// Default taxonomy
|
@@ -18,7 +41,8 @@ function wpmediacategory_init() {
|
|
18 |
if ( $taxonomy != 'category' ) {
|
19 |
$args = array(
|
20 |
'hierarchical' => true, // hierarchical: true = display as categories, false = display as tags
|
21 |
-
'show_admin_column' => true
|
|
|
22 |
);
|
23 |
register_taxonomy( $taxonomy, array( 'attachment' ), $args );
|
24 |
} else {
|
@@ -27,8 +51,28 @@ function wpmediacategory_init() {
|
|
27 |
}
|
28 |
add_action( 'init', 'wpmediacategory_init' );
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
// load code that is only needed in the admin section
|
31 |
-
if( is_admin() ) {
|
32 |
|
33 |
/** Handle default category of attachments without category */
|
34 |
function wpmediacategory_set_attachment_category( $post_ID ) {
|
@@ -39,19 +83,20 @@ if( is_admin() ) {
|
|
39 |
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
40 |
|
41 |
// if attachment already have categories, stop here
|
42 |
-
if( wp_get_object_terms( $post_ID, $taxonomy ) )
|
43 |
return;
|
44 |
|
45 |
// no, then get the default one
|
46 |
$post_category = array( get_option('default_category') );
|
47 |
|
48 |
// then set category if default category is set on writting page
|
49 |
-
if( $post_category )
|
50 |
wp_set_post_categories( $post_ID, $post_category );
|
51 |
}
|
52 |
add_action( 'add_attachment', 'wpmediacategory_set_attachment_category' );
|
53 |
add_action( 'edit_attachment', 'wpmediacategory_set_attachment_category' );
|
54 |
|
|
|
55 |
/** Custom walker for wp_dropdown_categories, based on https://gist.github.com/stephenh1988/2902509 */
|
56 |
class wpmediacategory_walker_category_filter extends Walker_CategoryDropdown{
|
57 |
|
@@ -96,16 +141,20 @@ if( is_admin() ) {
|
|
96 |
'hide_empty' => false,
|
97 |
'hierarchical' => true,
|
98 |
'orderby' => 'name',
|
|
|
99 |
'walker' => new wpmediacategory_walker_category_filter(),
|
100 |
'value' => 'slug'
|
101 |
);
|
102 |
} else {
|
103 |
$dropdown_options = array(
|
104 |
-
'taxonomy'
|
105 |
'show_option_all' => __( 'View all categories' ),
|
106 |
-
'hide_empty'
|
107 |
-
'hierarchical'
|
108 |
-
'orderby'
|
|
|
|
|
|
|
109 |
);
|
110 |
}
|
111 |
wp_dropdown_categories( $dropdown_options );
|
@@ -225,6 +274,8 @@ if( is_admin() ) {
|
|
225 |
}
|
226 |
}
|
227 |
|
|
|
|
|
228 |
wp_redirect( $sendback );
|
229 |
exit();
|
230 |
}
|
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.4.8
|
7 |
* Author: Jeffrey-WP
|
8 |
* Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
|
9 |
*/
|
10 |
|
11 |
+
/** Custom update_count_callback */
|
12 |
+
function wpmediacategory_update_count_callback( $terms, $taxonomy ) {
|
13 |
+
global $wpdb;
|
14 |
+
|
15 |
+
// default taxonomy
|
16 |
+
$taxonomy = 'category';
|
17 |
+
// add filter to change the default taxonomy
|
18 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
19 |
+
|
20 |
+
// select id & count from taxonomy
|
21 |
+
$rsCount = $wpdb->get_results("SELECT term_taxonomy_id, MAX(total) AS total FROM ((
|
22 |
+
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 = '" . $taxonomy . "' GROUP BY tt.term_taxonomy_id
|
23 |
+
) UNION ALL (
|
24 |
+
SELECT term_taxonomy_id, 0 AS total FROM $wpdb->term_taxonomy WHERE taxonomy = '" . $taxonomy . "'
|
25 |
+
)) AS unioncount GROUP BY term_taxonomy_id");
|
26 |
+
// update all count values from taxonomy
|
27 |
+
foreach ( $rsCount as $rowCount ) {
|
28 |
+
$wpdb->update( $wpdb->term_taxonomy, array( 'count' => $rowCount->total ), array( 'term_taxonomy_id' => $rowCount->term_taxonomy_id ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
/** register taxonomy for attachments */
|
35 |
function wpmediacategory_init() {
|
36 |
// Default taxonomy
|
41 |
if ( $taxonomy != 'category' ) {
|
42 |
$args = array(
|
43 |
'hierarchical' => true, // hierarchical: true = display as categories, false = display as tags
|
44 |
+
'show_admin_column' => true,
|
45 |
+
'update_count_callback' => 'wpmediacategory_update_count_callback'
|
46 |
);
|
47 |
register_taxonomy( $taxonomy, array( 'attachment' ), $args );
|
48 |
} else {
|
51 |
}
|
52 |
add_action( 'init', 'wpmediacategory_init' );
|
53 |
|
54 |
+
|
55 |
+
/** change default update_count_callback for category taxonomy */
|
56 |
+
function wpmediacategory_change_category_update_count_callback() {
|
57 |
+
global $wp_taxonomies;
|
58 |
+
|
59 |
+
// Default taxonomy
|
60 |
+
$taxonomy = 'category';
|
61 |
+
// Add filter to change the default taxonomy
|
62 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
63 |
+
|
64 |
+
if ( $taxonomy == 'category' ) {
|
65 |
+
if ( ! taxonomy_exists( 'category' ) )
|
66 |
+
return false;
|
67 |
+
|
68 |
+
$new_arg = &$wp_taxonomies['category']->update_count_callback;
|
69 |
+
$new_arg = 'wpmediacategory_update_count_callback';
|
70 |
+
}
|
71 |
+
}
|
72 |
+
add_action( 'init', 'wpmediacategory_change_category_update_count_callback', 100 );
|
73 |
+
|
74 |
// load code that is only needed in the admin section
|
75 |
+
if ( is_admin() ) {
|
76 |
|
77 |
/** Handle default category of attachments without category */
|
78 |
function wpmediacategory_set_attachment_category( $post_ID ) {
|
83 |
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
84 |
|
85 |
// if attachment already have categories, stop here
|
86 |
+
if ( wp_get_object_terms( $post_ID, $taxonomy ) )
|
87 |
return;
|
88 |
|
89 |
// no, then get the default one
|
90 |
$post_category = array( get_option('default_category') );
|
91 |
|
92 |
// then set category if default category is set on writting page
|
93 |
+
if ( $post_category )
|
94 |
wp_set_post_categories( $post_ID, $post_category );
|
95 |
}
|
96 |
add_action( 'add_attachment', 'wpmediacategory_set_attachment_category' );
|
97 |
add_action( 'edit_attachment', 'wpmediacategory_set_attachment_category' );
|
98 |
|
99 |
+
|
100 |
/** Custom walker for wp_dropdown_categories, based on https://gist.github.com/stephenh1988/2902509 */
|
101 |
class wpmediacategory_walker_category_filter extends Walker_CategoryDropdown{
|
102 |
|
141 |
'hide_empty' => false,
|
142 |
'hierarchical' => true,
|
143 |
'orderby' => 'name',
|
144 |
+
'show_count' => true,
|
145 |
'walker' => new wpmediacategory_walker_category_filter(),
|
146 |
'value' => 'slug'
|
147 |
);
|
148 |
} else {
|
149 |
$dropdown_options = array(
|
150 |
+
'taxonomy' => $taxonomy,
|
151 |
'show_option_all' => __( 'View all categories' ),
|
152 |
+
'hide_empty' => false,
|
153 |
+
'hierarchical' => true,
|
154 |
+
'orderby' => 'name',
|
155 |
+
'show_count' => false,
|
156 |
+
'walker' => new wpmediacategory_walker_category_filter(),
|
157 |
+
'value' => 'id'
|
158 |
);
|
159 |
}
|
160 |
wp_dropdown_categories( $dropdown_options );
|
274 |
}
|
275 |
}
|
276 |
|
277 |
+
wpmediacategory_update_count_callback();
|
278 |
+
|
279 |
wp_redirect( $sendback );
|
280 |
exit();
|
281 |
}
|
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
|
5 |
Requires at least: 3.1
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 1.4.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -68,44 +68,49 @@ add_filter( 'wpmediacategory_taxonomy', function(){ return 'category_media'; },
|
|
68 |
|
69 |
== Changelog ==
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
= 1.4.7 =
|
72 |
-
*
|
73 |
|
74 |
= 1.4.6 =
|
75 |
-
*
|
76 |
|
77 |
= 1.4.5 =
|
78 |
-
*
|
79 |
|
80 |
= 1.4.4 =
|
81 |
* By default the WordPress Media Library uses the same categories as WordPress does (such as posts & pages). Now you can use separate categories for the WordPress Media Library. [see the FAQ for howto](http://wordpress.org/plugins/wp-media-library-categories/faq/)
|
82 |
|
83 |
= 1.4.2 & 1.4.3 =
|
84 |
-
* [(
|
85 |
|
86 |
= 1.4.1 =
|
87 |
-
*
|
88 |
-
*
|
89 |
|
90 |
= 1.4 =
|
91 |
-
*
|
92 |
|
93 |
= 1.3.2 =
|
94 |
-
* [
|
95 |
-
* [
|
96 |
|
97 |
= 1.3.1 =
|
98 |
-
*
|
99 |
|
100 |
= 1.3 =
|
101 |
-
*
|
102 |
-
*
|
103 |
|
104 |
= 1.2 =
|
105 |
-
*
|
106 |
|
107 |
= 1.1 =
|
108 |
-
*
|
109 |
|
110 |
= 1.0 =
|
111 |
-
*
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSNQMST6R28Q2
|
4 |
Tags: category, categories, media, library, medialibrary
|
5 |
Requires at least: 3.1
|
6 |
+
Tested up to: 3.9
|
7 |
+
Stable tag: 1.4.8
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
68 |
|
69 |
== Changelog ==
|
70 |
|
71 |
+
= 1.4.8 =
|
72 |
+
* Fixed media count on the categories page.
|
73 |
+
* Add item count in the category filter dropdown when using separate categories for the WordPress Media Library.
|
74 |
+
* Support for WordPress 3.9
|
75 |
+
|
76 |
= 1.4.7 =
|
77 |
+
* New images are now added to the default category (if a default category exists). I most cases the default category is "Uncategorized".(http://wordpress.org/support/topic/new-images-arent-automatically-in-uncategorized)
|
78 |
|
79 |
= 1.4.6 =
|
80 |
+
* Fixed bug where in some rare cases the filter by category didn't work
|
81 |
|
82 |
= 1.4.5 =
|
83 |
+
* Fixed bug in version 1.4.4 that made default categories in WordPress invisible
|
84 |
|
85 |
= 1.4.4 =
|
86 |
* By default the WordPress Media Library uses the same categories as WordPress does (such as posts & pages). Now you can use separate categories for the WordPress Media Library. [see the FAQ for howto](http://wordpress.org/plugins/wp-media-library-categories/faq/)
|
87 |
|
88 |
= 1.4.2 & 1.4.3 =
|
89 |
+
* [(Premium only)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
90 |
|
91 |
= 1.4.1 =
|
92 |
+
* Improved bulk actions: added option to remove category from multiple media items at once
|
93 |
+
* Improved bulk actions: arranged options in option group
|
94 |
|
95 |
= 1.4 =
|
96 |
+
* Filter on categories when inserting media [(premium only)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
97 |
|
98 |
= 1.3.2 =
|
99 |
+
* [Added taxonomy filter](http://wordpress.org/support/topic/added-taxonomy-filter)
|
100 |
+
* [Don't load unnecessary code](http://dannyvankooten.com/3882/wordpress-plugin-structure-dont-load-unnecessary-code/)
|
101 |
|
102 |
= 1.3.1 =
|
103 |
+
* Fixed bug (when having a category with apostrophe)
|
104 |
|
105 |
= 1.3 =
|
106 |
+
* Add support for bulk actions (to change category from multiple media items at once)
|
107 |
+
* Support for WordPress 3.8
|
108 |
|
109 |
= 1.2 =
|
110 |
+
* Better internationalisation
|
111 |
|
112 |
= 1.1 =
|
113 |
+
* Add a link to media categories on the plugin page
|
114 |
|
115 |
= 1.0 =
|
116 |
+
* Initial release.
|