Media Library Categories - Version 1.4.13

Version Description

  • Improved compatibility with other plugins that use the [gallery] shortcode.
  • Remember author when changing categories.
  • Added example code in the FAQ for creating seperate categories with PHP 4. Read the FAQ for howto
Download this release

Release Info

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

Code changes from version 1.4.12 to 1.4.13

Files changed (2) hide show
  1. index.php +16 -8
  2. readme.txt +19 -13
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.12
7
  * Author: Jeffrey-WP
8
  * Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
9
  */
@@ -73,10 +73,9 @@ add_action( 'init', 'wpmediacategory_change_category_update_count_callback', 100
73
 
74
 
75
  /** custom gallery shortcode */
76
- add_shortcode( 'gallery', 'wpmediacategory_custom_gallery_shortcode' );
77
- function wpmediacategory_custom_gallery_shortcode( $atts ) {
78
 
79
- if ( isset( $atts['category'] ) ) {
80
 
81
  // Default taxonomy
82
  $taxonomy = 'category';
@@ -116,7 +115,7 @@ function wpmediacategory_custom_gallery_shortcode( $atts ) {
116
  $ids_new = array();
117
 
118
  if ( $taxonomy != 'category' ) {
119
-
120
  $args = array(
121
  'post_type' => 'attachment',
122
  'numberposts' => -1,
@@ -137,7 +136,7 @@ function wpmediacategory_custom_gallery_shortcode( $atts ) {
137
  'numberposts' => -1,
138
  'post_status' => null,
139
  'category' => $category
140
- );
141
 
142
  }
143
  $attachments = get_posts( $args );
@@ -166,11 +165,15 @@ function wpmediacategory_custom_gallery_shortcode( $atts ) {
166
 
167
  }
168
 
 
 
 
169
  }
170
 
171
- // call the wordpress shortcode function
172
- return gallery_shortcode( $atts );
173
  }
 
174
 
175
 
176
  // load code that is only needed in the admin section
@@ -344,6 +347,11 @@ if ( is_admin() ) {
344
  $sOrder = $_REQUEST['order'];
345
  $sendback = add_query_arg( 'order', $sOrder, $sendback );
346
  }
 
 
 
 
 
347
 
348
  foreach( $post_ids as $post_id ) {
349
 
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.13
7
  * Author: Jeffrey-WP
8
  * Author URI: http://codecanyon.net/user/jeffrey-wp/?ref=jeffrey-wp
9
  */
73
 
74
 
75
  /** custom gallery shortcode */
76
+ function wpmediacategory_gallery_atts( $result, $defaults, $atts ) {
 
77
 
78
+ if ( isset( $atts['category'] ) ) {
79
 
80
  // Default taxonomy
81
  $taxonomy = 'category';
115
  $ids_new = array();
116
 
117
  if ( $taxonomy != 'category' ) {
118
+
119
  $args = array(
120
  'post_type' => 'attachment',
121
  'numberposts' => -1,
136
  'numberposts' => -1,
137
  'post_status' => null,
138
  'category' => $category
139
+ );
140
 
141
  }
142
  $attachments = get_posts( $args );
165
 
166
  }
167
 
168
+ $result['include'] = implode( ',', $atts['ids'] );
169
+ $result['category'] = $atts['category'];
170
+
171
  }
172
 
173
+ return $result;
174
+
175
  }
176
+ add_filter( 'shortcode_atts_gallery', 'wpmediacategory_gallery_atts', 10, 3 );
177
 
178
 
179
  // load code that is only needed in the admin section
347
  $sOrder = $_REQUEST['order'];
348
  $sendback = add_query_arg( 'order', $sOrder, $sendback );
349
  }
350
+ // remember author
351
+ if ( isset( $_REQUEST['author'] ) ) {
352
+ $sOrderby = $_REQUEST['author'];
353
+ $sendback = add_query_arg( 'author', $sOrderby, $sendback );
354
+ }
355
 
356
  foreach( $post_ids as $post_id ) {
357
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
5
  Requires at least: 3.1
6
  Tested up to: 3.9.2
7
- Stable tag: 1.4.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -40,25 +40,26 @@ To upload the plugin through WordPress, instead of FTP:
40
 
41
  == Frequently Asked Questions ==
42
 
43
- = 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? =
 
44
  Add this code to the file functions.php located in your theme or child-theme:
45
  `/**
46
  * separate media categories from post categories
47
  * use a custom category called 'category_media' for the categories in the media library
48
  */
49
- add_filter( 'wpmediacategory_taxonomy', function(){ return 'category_media'; }, 1 ); //requires PHP 5.3 or newer
50
  `
 
 
51
 
52
 
53
- = Can i use category in the [gallery] shortcode, like [gallery category="my-category-slug"]? =
54
- Yes, it is possible to extend the existing WordPress default `[gallery]` to only show images from one category by adding the `'category'` parameter.
55
- The value passed to the `'category'` parameter can be either the `category slug`, or the `term_id`.
56
  `[gallery category="my-category-slug"]
57
- OR
58
  [gallery category="14"]`
59
- Aside from this behavior, the `[gallery]` shortcode works as it does by default with the built-in shortcode.
60
- If you use an incorrect slug by default WordPress shows the images that are attached to the page / post that is displayed. If you use an incorrect term_id no images are shown.
61
- For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode).
62
 
63
 
64
  = How can I filter on categories when inserting media into a post or page? =
@@ -77,9 +78,14 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
80
  = 1.4.12 =
81
- * Add category option to the default WordPress shortcode gallery [Read the FAQ for howto](http://wordpress.org/plugins/wp-media-library-categories/faq/)
82
- * Improve code styling to match WordPress code standard even more strictly
83
 
84
  = 1.4.11 =
85
  * Remember ordering when changing categories.
@@ -94,7 +100,7 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
94
 
95
  = 1.4.8 =
96
  * Fixed media count on the categories page.
97
- * Add item count in the category filter dropdown when using separate categories for the WordPress Media Library.
98
  * Support for WordPress 3.9
99
 
100
  = 1.4.7 =
4
  Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
5
  Requires at least: 3.1
6
  Tested up to: 3.9.2
7
+ Stable tag: 1.4.13
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
40
 
41
  == Frequently Asked Questions ==
42
 
43
+ = How to use separate categories for the WordPress Media Library (and don't use the same categories as in posts & pages)? =
44
+ By default the WordPress Media Library uses the same categories as WordPress does (such as in posts & pages). If you want to use separate categories for the WordPress Media Library add this code to the file functions.php located in your theme or child-theme:
45
  Add this code to the file functions.php located in your theme or child-theme:
46
  `/**
47
  * separate media categories from post categories
48
  * use a custom category called 'category_media' for the categories in the media library
49
  */
50
+ add_filter( 'wpmediacategory_taxonomy', function(){ return 'category_media'; } ); //requires PHP 5.3 or newer
51
  `
52
+ Or if you have an older PHP version:
53
+ `add_filter( 'wpmediacategory_taxonomy', create_function( '', 'return "category_media";' ) ); //requires PHP 4.0.1 or newer`
54
 
55
 
56
+ = How to use category in the [gallery] shortcode? =
57
+ To only show images from one category in the gallery you have to add the '`category`' parameter to the `[gallery]` shortcode.
58
+ The value passed to the '`category`' parameter can be either the `category slug` or the `term_id`, for example with the category slug:
59
  `[gallery category="my-category-slug"]
60
+ Or with term_id:
61
  [gallery category="14"]`
62
+ If you use an incorrect slug by default WordPress shows the images that are attached to the page / post that is displayed. If you use an incorrect term_id no images are shown. Aside from this behavior, the `[gallery]` shortcode works as it does by default with the built-in shortcode from WordPress ([see the WordPress gallery shortcode codex page](http://codex.wordpress.org/Gallery_Shortcode)). Some plugins that also use the gallery shortcode (like Jetpack) disable the category option on the gallery shortcode.
 
 
63
 
64
 
65
  = How can I filter on categories when inserting media into a post or page? =
78
 
79
  == Changelog ==
80
 
81
+ = 1.4.13 =
82
+ * Improved compatibility with other plugins that use the [gallery] shortcode.
83
+ * Remember author when changing categories.
84
+ * Added example code in the FAQ for creating seperate categories with PHP 4. [Read the FAQ for howto](http://wordpress.org/plugins/wp-media-library-categories/faq/)
85
+
86
  = 1.4.12 =
87
+ * Added category option to the default WordPress shortcode gallery. [Read the FAQ for howto](http://wordpress.org/plugins/wp-media-library-categories/faq/)
88
+ * Improved code styling to match WordPress code standard even more strictly.
89
 
90
  = 1.4.11 =
91
  * Remember ordering when changing categories.
100
 
101
  = 1.4.8 =
102
  * Fixed media count on the categories page.
103
+ * Added item count in the category filter dropdown when using separate categories for the WordPress Media Library.
104
  * Support for WordPress 3.9
105
 
106
  = 1.4.7 =