Media Library Categories - Version 1.5.5

Version Description

  • Better detection if category is empty in gallery shortcode.
  • Use id attribute in gallery shortcode and show attachments in selected category and uploaded to post ID. [gallery category="my-category-slug" id="123"]
  • Leave id attribute empty in gallery shortcode to show attachments in selected category and upload to current post. [gallery category="my-category-slug" id=""]
Download this release

Release Info

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

Code changes from version 1.5.4 to 1.5.5

Files changed (2) hide show
  1. index.php +15 -5
  2. readme.txt +13 -4
index.php CHANGED
@@ -3,7 +3,7 @@
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.5.4
7
  * Author: Jeffrey-WP
8
  * Text Domain: wp-media-library-categories
9
  * Domain Path: /languages
@@ -84,7 +84,7 @@ add_action( 'init', 'wpmediacategory_change_category_update_count_callback', 100
84
  /** custom gallery shortcode */
85
  function wpmediacategory_gallery_atts( $result, $defaults, $atts ) {
86
 
87
- if ( isset( $atts['category'] ) ) {
88
 
89
  // Default taxonomy
90
  $taxonomy = 'category';
@@ -148,6 +148,16 @@ function wpmediacategory_gallery_atts( $result, $defaults, $atts ) {
148
  );
149
 
150
  }
 
 
 
 
 
 
 
 
 
 
151
  $attachments = get_posts( $args );
152
 
153
  if ( ! empty( $attachments ) ) {
@@ -169,7 +179,7 @@ function wpmediacategory_gallery_atts( $result, $defaults, $atts ) {
169
 
170
  $atts['ids'] = $ids_new;
171
  } else {
172
- $atts['ids'] = -1; // don't display images if category is empty
173
  }
174
 
175
  }
@@ -521,9 +531,9 @@ if ( is_admin() ) {
521
  echo '/* ]]> */';
522
  echo '</script>';
523
 
524
- wp_enqueue_script( 'wpmediacategory-media-views', plugins_url( 'js/wpmediacategory-media-views.min.js', __FILE__ ), array( 'media-views' ), '1.5.4', true );
525
  }
526
- wp_enqueue_style( 'wpmediacategory', plugins_url( 'css/wpmediacategory.min.css', __FILE__ ), array(), '1.5.4' );
527
  }
528
  add_action( 'admin_enqueue_scripts', 'wpmediacategory_enqueue_media_action' );
529
 
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.5.5
7
  * Author: Jeffrey-WP
8
  * Text Domain: wp-media-library-categories
9
  * Domain Path: /languages
84
  /** custom gallery shortcode */
85
  function wpmediacategory_gallery_atts( $result, $defaults, $atts ) {
86
 
87
+ if ( isset( $atts['category'] ) ) {
88
 
89
  // Default taxonomy
90
  $taxonomy = '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 ) ) {
179
 
180
  $atts['ids'] = $ids_new;
181
  } else {
182
+ $atts['ids'] = array(-1); // don't display images if category is empty
183
  }
184
 
185
  }
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.5', true );
535
  }
536
+ wp_enqueue_style( 'wpmediacategory', plugins_url( 'css/wpmediacategory.min.css', __FILE__ ), array(), '1.5.5' );
537
  }
538
  add_action( 'admin_enqueue_scripts', 'wpmediacategory_enqueue_media_action' );
539
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
5
  Requires at least: 3.1
6
  Tested up to: 4.7.4
7
- Stable tag: 1.5.4
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -54,12 +54,16 @@ Or if you have an older PHP version:
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](https://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,6 +82,11 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
78
 
79
  == Changelog ==
80
 
 
 
 
 
 
81
  = 1.5.4 =
82
  * Before creating custom taxonomy check if taxonomy exists. Thanks @drpratten
83
  * Use filter instead of action for the displayed attachments. Thanks @clearsite
4
  Tags: category, categories, media, library, medialibrary, image, images, media category, media categories
5
  Requires at least: 3.1
6
  Tested up to: 4.7.4
7
+ Stable tag: 1.5.5
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
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`' attribute to the `[gallery]` shortcode.
58
+ The value passed to the '`category`' attribute 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](https://codex.wordpress.org/Gallery_Shortcode)). If you only want to show attachments uploaded to the page and filtered by category than use the '`id`' in combination with the '`category`' attribute. For example (the id of the post is 123):
63
+ `[gallery category="my-category-slug" id="123"]
64
+ Or leave id empty for current page / post:
65
+ [gallery category="my-category-slug" id=""]`
66
+ In this example the slug is used, but you could also use the term_id.
67
 
68
 
69
  = How can I filter on categories when inserting media into a post or page? =
82
 
83
  == Changelog ==
84
 
85
+ = 1.5.5 =
86
+ * Better detection if category is empty in gallery shortcode.
87
+ * Use id attribute in gallery shortcode and show attachments in selected category and uploaded to post ID. `[gallery category="my-category-slug" id="123"]`
88
+ * Leave id attribute empty in gallery shortcode to show attachments in selected category and upload to current post. `[gallery category="my-category-slug" id=""]`
89
+
90
  = 1.5.4 =
91
  * Before creating custom taxonomy check if taxonomy exists. Thanks @drpratten
92
  * Use filter instead of action for the displayed attachments. Thanks @clearsite