Version Description
- Before creating custom taxonomy check if taxonomy exists. Thanks @drpratten
- Use filter instead of action for the displayed attachments. Thanks @clearsite
- Japanese translations. Thanks @katsushi-kawamori
- On some servers the active category was not selected in the dropdown in media list view.
- Support PHP 7.1
Download this release
Release Info
Developer | jeffrey-wp |
Plugin | Media Library Categories |
Version | 1.5.4 |
Comparing to | |
See all releases |
Code changes from version 1.5.3 to 1.5.4
- index.php +19 -36
- readme.txt +10 -3
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.
|
7 |
* Author: Jeffrey-WP
|
8 |
* Text Domain: wp-media-library-categories
|
9 |
* Domain Path: /languages
|
@@ -47,15 +47,15 @@ function wpmediacategory_init() {
|
|
47 |
// Add filter to change the default taxonomy
|
48 |
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
49 |
|
50 |
-
if ( $taxonomy
|
|
|
|
|
51 |
$args = array(
|
52 |
'hierarchical' => true, // hierarchical: true = display as categories, false = display as tags
|
53 |
'show_admin_column' => true,
|
54 |
'update_count_callback' => 'wpmediacategory_update_count_callback'
|
55 |
);
|
56 |
register_taxonomy( $taxonomy, array( 'attachment' ), $args );
|
57 |
-
} else {
|
58 |
-
register_taxonomy_for_object_type( $taxonomy, 'attachment' );
|
59 |
}
|
60 |
}
|
61 |
add_action( 'init', 'wpmediacategory_init' );
|
@@ -224,12 +224,12 @@ if ( is_admin() ) {
|
|
224 |
}
|
225 |
|
226 |
$value = ( $args['value']=='slug' ? $category->slug : $category->term_id );
|
227 |
-
if ( 0 == $args['selected'] && isset( $_GET['category_media'] ) && '' != $_GET['category_media'] ) {
|
228 |
$args['selected'] = $_GET['category_media'];
|
229 |
}
|
230 |
|
231 |
$output .= '<option class="level-' . $depth . '" value="' . $value . '"';
|
232 |
-
if ( $value === (string) $args['selected'] ) {
|
233 |
$output .= ' selected="selected"';
|
234 |
}
|
235 |
$output .= '>';
|
@@ -450,49 +450,32 @@ if ( is_admin() ) {
|
|
450 |
|
451 |
|
452 |
/** Changing categories in the 'grid view' */
|
453 |
-
function
|
454 |
-
|
455 |
-
|
456 |
-
wp_send_json_error();
|
457 |
-
}
|
458 |
|
459 |
$taxonomies = get_object_taxonomies( 'attachment', 'names' );
|
|
|
460 |
|
461 |
-
|
462 |
-
|
463 |
-
$defaults = array(
|
464 |
-
's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
|
465 |
-
'post_parent', 'post__in', 'post__not_in'
|
466 |
-
);
|
467 |
-
$query = array_intersect_key( $query, array_flip( array_merge( $defaults, $taxonomies ) ) );
|
468 |
|
469 |
-
$query['post_type'] = 'attachment';
|
470 |
-
$query['post_status'] = 'inherit';
|
471 |
-
if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) )
|
472 |
-
$query['post_status'] .= ',private';
|
473 |
-
|
474 |
$query['tax_query'] = array( 'relation' => 'AND' );
|
475 |
|
476 |
-
foreach ( $taxonomies as $taxonomy ) {
|
477 |
if ( isset( $query[$taxonomy] ) && is_numeric( $query[$taxonomy] ) ) {
|
478 |
array_push( $query['tax_query'], array(
|
479 |
'taxonomy' => $taxonomy,
|
480 |
'field' => 'id',
|
481 |
'terms' => $query[$taxonomy]
|
482 |
-
));
|
483 |
}
|
484 |
-
unset
|
485 |
}
|
486 |
|
487 |
-
|
488 |
-
$query = new WP_Query( $query );
|
489 |
-
|
490 |
-
$posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
|
491 |
-
$posts = array_filter( $posts );
|
492 |
-
|
493 |
-
wp_send_json_success( $posts );
|
494 |
}
|
495 |
-
|
496 |
|
497 |
|
498 |
/** Enqueue admin scripts and styles */
|
@@ -538,9 +521,9 @@ if ( is_admin() ) {
|
|
538 |
echo '/* ]]> */';
|
539 |
echo '</script>';
|
540 |
|
541 |
-
wp_enqueue_script( 'wpmediacategory-media-views', plugins_url( 'js/wpmediacategory-media-views.min.js', __FILE__ ), array( 'media-views' ), '1.5.
|
542 |
}
|
543 |
-
wp_enqueue_style( 'wpmediacategory', plugins_url( 'css/wpmediacategory.min.css', __FILE__ ), array(), '1.5.
|
544 |
}
|
545 |
add_action( 'admin_enqueue_scripts', 'wpmediacategory_enqueue_media_action' );
|
546 |
|
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
|
47 |
// Add filter to change the default taxonomy
|
48 |
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
49 |
|
50 |
+
if ( taxonomy_exists( $taxonomy ) ) {
|
51 |
+
register_taxonomy_for_object_type( $taxonomy, 'attachment' );
|
52 |
+
} else {
|
53 |
$args = array(
|
54 |
'hierarchical' => true, // hierarchical: true = display as categories, false = display as tags
|
55 |
'show_admin_column' => true,
|
56 |
'update_count_callback' => 'wpmediacategory_update_count_callback'
|
57 |
);
|
58 |
register_taxonomy( $taxonomy, array( 'attachment' ), $args );
|
|
|
|
|
59 |
}
|
60 |
}
|
61 |
add_action( 'init', 'wpmediacategory_init' );
|
224 |
}
|
225 |
|
226 |
$value = ( $args['value']=='slug' ? $category->slug : $category->term_id );
|
227 |
+
if ( 0 == $args['selected'] && isset( $_GET['category_media'] ) && '' != $_GET['category_media'] ) { // custom taxonomy
|
228 |
$args['selected'] = $_GET['category_media'];
|
229 |
}
|
230 |
|
231 |
$output .= '<option class="level-' . $depth . '" value="' . $value . '"';
|
232 |
+
if ( (string) $value === (string) $args['selected'] ) {
|
233 |
$output .= ' selected="selected"';
|
234 |
}
|
235 |
$output .= '>';
|
450 |
|
451 |
|
452 |
/** Changing categories in the 'grid view' */
|
453 |
+
function wpmediacategory_ajax_query_attachments_args( $query = array() ) {
|
454 |
+
// grab original query, the given query has already been filtered by WordPress
|
455 |
+
$taxquery = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
|
|
|
|
|
456 |
|
457 |
$taxonomies = get_object_taxonomies( 'attachment', 'names' );
|
458 |
+
$taxquery = array_intersect_key( $taxquery, array_flip( $taxonomies ) );
|
459 |
|
460 |
+
// merge our query into the WordPress query
|
461 |
+
$query = array_merge( $query, $taxquery );
|
|
|
|
|
|
|
|
|
|
|
462 |
|
|
|
|
|
|
|
|
|
|
|
463 |
$query['tax_query'] = array( 'relation' => 'AND' );
|
464 |
|
465 |
+
foreach ( $taxonomies as $taxonomy ) {
|
466 |
if ( isset( $query[$taxonomy] ) && is_numeric( $query[$taxonomy] ) ) {
|
467 |
array_push( $query['tax_query'], array(
|
468 |
'taxonomy' => $taxonomy,
|
469 |
'field' => 'id',
|
470 |
'terms' => $query[$taxonomy]
|
471 |
+
) );
|
472 |
}
|
473 |
+
unset( $query[$taxonomy] );
|
474 |
}
|
475 |
|
476 |
+
return $query;
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
}
|
478 |
+
add_filter( 'ajax_query_attachments_args', 'wpmediacategory_ajax_query_attachments_args' );
|
479 |
|
480 |
|
481 |
/** Enqueue admin scripts and styles */
|
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 |
|
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.7.
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GPLv2 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -78,6 +78,13 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
|
|
78 |
|
79 |
== Changelog ==
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
= 1.5.3 =
|
82 |
* Added some default languages en_US, nl_NL, de_DE
|
83 |
* Updated all links to use https://
|
@@ -89,7 +96,7 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
|
|
89 |
= 1.5.1 =
|
90 |
* Support for WordPress 4.2
|
91 |
* Security enhancement for add_query_arg
|
92 |
-
*
|
93 |
|
94 |
= 1.5 =
|
95 |
* Support for WordPress 4.1
|
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.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 |
|
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
|
84 |
+
* Japanese translations. Thanks @katsushi-kawamori
|
85 |
+
* On some servers the active category was not selected in the dropdown in media list view.
|
86 |
+
* Support PHP 7.1
|
87 |
+
|
88 |
= 1.5.3 =
|
89 |
* Added some default languages en_US, nl_NL, de_DE
|
90 |
* Updated all links to use https://
|
96 |
= 1.5.1 =
|
97 |
* Support for WordPress 4.2
|
98 |
* Security enhancement for add_query_arg
|
99 |
+
* Remember selected category
|
100 |
|
101 |
= 1.5 =
|
102 |
* Support for WordPress 4.1
|