Media Library Categories - Version 1.4.4

Version Description

  • 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
Download this release

Release Info

Developer jeffrey-wp
Plugin Icon 128x128 Media Library Categories
Version 1.4.4
Comparing to
See all releases

Code changes from version 1.4.1 to 1.4.4

Files changed (2) hide show
  1. index.php +45 -3
  2. readme.txt +27 -8
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.4.1
7
  * Author: Jeffrey-WP
8
  * Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
9
  */
@@ -14,13 +14,46 @@ function wpmediacategory_init() {
14
  $taxonomy = 'category';
15
  // Add filter to change the default taxonomy
16
  $taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
17
- register_taxonomy_for_object_type( $taxonomy, 'attachment' );
 
 
 
 
 
18
  }
19
  add_action( 'init', 'wpmediacategory_init' );
20
 
21
  // load code that is only needed in the admin section
22
  if( is_admin() ) {
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  /** Add a category filter */
25
  function wpmediacategory_add_category_filter() {
26
  $screen = get_current_screen();
@@ -29,7 +62,16 @@ if( is_admin() ) {
29
  $taxonomy = 'category';
30
  // Add filter to change the default taxonomy
31
  $taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
32
- $dropdown_options = array( 'taxonomy' => $taxonomy, 'show_option_all' => __( 'View all categories' ), 'hide_empty' => false, 'hierarchical' => true, 'orderby' => 'name', );
 
 
 
 
 
 
 
 
 
33
  wp_dropdown_categories( $dropdown_options );
34
  }
35
  }
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.4
7
  * Author: Jeffrey-WP
8
  * Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
9
  */
14
  $taxonomy = 'category';
15
  // Add filter to change the default taxonomy
16
  $taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
17
+
18
+ $args = array(
19
+ 'hierarchical' => true, // hierarchical: true = display as categories, false = display as tags
20
+ 'show_admin_column' => true
21
+ );
22
+ register_taxonomy( $taxonomy, array( 'attachment' ), $args );
23
  }
24
  add_action( 'init', 'wpmediacategory_init' );
25
 
26
  // load code that is only needed in the admin section
27
  if( is_admin() ) {
28
 
29
+ /** Custom walker for wp_dropdown_categories, based on https://gist.github.com/stephenh1988/2902509 */
30
+ class wpmediacategory_walker_category_filter extends Walker_CategoryDropdown{
31
+
32
+ function start_el(&$output, $category, $depth, $args) {
33
+ $pad = str_repeat(' ', $depth * 3);
34
+ $cat_name = apply_filters('list_cats', $category->name, $category);
35
+
36
+ if( !isset($args['value']) ) {
37
+ $args['value'] = ( $category->taxonomy != 'category' ? 'slug' : 'id' );
38
+ }
39
+
40
+ $value = ($args['value']=='slug' ? $category->slug : $category->term_id );
41
+
42
+ $output .= "\t<option class=\"level-$depth\" value=\"".$value."\"";
43
+ if ( $value === (string) $args['selected'] ) {
44
+ $output .= ' selected="selected"';
45
+ }
46
+ $output .= '>';
47
+ $output .= $pad.$cat_name;
48
+ if ( $args['show_count'] )
49
+ $output .= '&nbsp;&nbsp;('. $category->count .')';
50
+
51
+ $output .= "</option>\n";
52
+ }
53
+
54
+ }
55
+
56
+
57
  /** Add a category filter */
58
  function wpmediacategory_add_category_filter() {
59
  $screen = get_current_screen();
62
  $taxonomy = 'category';
63
  // Add filter to change the default taxonomy
64
  $taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
65
+ $dropdown_options = array(
66
+ 'taxonomy' => $taxonomy,
67
+ 'name' => $taxonomy,
68
+ 'show_option_all' => __( 'View all categories' ),
69
+ 'hide_empty' => false,
70
+ 'hierarchical' => true,
71
+ 'orderby' => 'name',
72
+ 'walker' => new wpmediacategory_walker_category_filter(),
73
+ 'value' => 'slug'
74
+ );
75
  wp_dropdown_categories( $dropdown_options );
76
  }
77
  }
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
5
  Requires at least: 3.1
6
  Tested up to: 3.8.1
7
- Stable tag: 1.4.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -35,7 +35,8 @@ For a manual installation via FTP:
35
  To upload the plugin through WordPress, instead of FTP:
36
 
37
  1. Upload the downloaded zip file on the 'Add New' plugins screen (see the 'Upload' tab) in your WordPress admin area and activate.
38
- 2. A dropdown of categories will show up in the media library
 
39
 
40
  == Frequently Asked Questions ==
41
 
@@ -50,6 +51,15 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
50
  = How can I filter on categories when inserting media into a post or page? =
51
  This feature is only available in the [premium version](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
52
 
 
 
 
 
 
 
 
 
 
53
  == Screenshots ==
54
 
55
  1. Filter by category in the media library
@@ -58,12 +68,21 @@ This feature is only available in the [premium version](http://codecanyon.net/it
58
 
59
  == Changelog ==
60
 
 
 
 
 
 
 
 
 
 
61
  = 1.4.1 =
62
- * improved bulk actions: added option to remove category from multiple media items at once.
63
  * improved bulk actions: arranged options in option group
64
 
65
  = 1.4 =
66
- * Filter on categories when inserting media [(premium only)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
67
 
68
  = 1.3.2 =
69
  * [added taxonomy filter](http://wordpress.org/support/topic/added-taxonomy-filter)
@@ -73,14 +92,14 @@ This feature is only available in the [premium version](http://codecanyon.net/it
73
  * fixed bug (when having a category with apostrophe)
74
 
75
  = 1.3 =
76
- * Add support for bulk actions (to change category from multiple media items at once)
77
  * support for WordPress 3.8
78
 
79
  = 1.2 =
80
- * Better internationalisation
81
 
82
  = 1.1 =
83
- * Add a link to media categories on the plugin page
84
 
85
  = 1.0 =
86
- * Initial release.
4
  Tags: category, categories, media, library, medialibrary
5
  Requires at least: 3.1
6
  Tested up to: 3.8.1
7
+ Stable tag: 1.4.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
35
  To upload the plugin through WordPress, instead of FTP:
36
 
37
  1. Upload the downloaded zip file on the 'Add New' plugins screen (see the 'Upload' tab) in your WordPress admin area and activate.
38
+ 2. Activate the plugin through the 'Plugins' screen in your WordPress admin area
39
+ 3. A dropdown of categories will show up in the media library
40
 
41
  == Frequently Asked Questions ==
42
 
51
  = How can I filter on categories when inserting media into a post or page? =
52
  This feature is only available in the [premium version](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
53
 
54
+ = By default the WordPress Media Library uses the same categories as WordPress does (such as in posts & pages). How do I use separate categories for the WordPress Media Library? =
55
+ Add this code to the file functions.php located in your theme or child-theme:
56
+ `/**
57
+ * separate media categories from post categories
58
+ * use a custom category called 'category_media' for the categories in the media library
59
+ */
60
+ add_filter( 'wpmediacategory_taxonomy', function(){ return 'category_media'; }, 1 ); //requires PHP 5.3 or newer
61
+ `
62
+
63
  == Screenshots ==
64
 
65
  1. Filter by category in the media library
68
 
69
  == Changelog ==
70
 
71
+ = 1.4.4 =
72
+ * 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/)
73
+
74
+ = 1.4.3 =
75
+ * [(premium only)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
76
+
77
+ = 1.4.2 =
78
+ * [(premium only)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
79
+
80
  = 1.4.1 =
81
+ * improved bulk actions: added option to remove category from multiple media items at once
82
  * improved bulk actions: arranged options in option group
83
 
84
  = 1.4 =
85
+ * filter on categories when inserting media [(premium only)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
86
 
87
  = 1.3.2 =
88
  * [added taxonomy filter](http://wordpress.org/support/topic/added-taxonomy-filter)
92
  * fixed bug (when having a category with apostrophe)
93
 
94
  = 1.3 =
95
+ * add support for bulk actions (to change category from multiple media items at once)
96
  * support for WordPress 3.8
97
 
98
  = 1.2 =
99
+ * better internationalisation
100
 
101
  = 1.1 =
102
+ * add a link to media categories on the plugin page
103
 
104
  = 1.0 =
105
+ * initial release.