Version Description
- added taxonomy filter
- don't load unnecessary code
Download this release
Release Info
Developer | jeffrey-wp |
Plugin | Media Library Categories |
Version | 1.3.2 |
Comparing to | |
See all releases |
Code changes from version 1.3.1 to 1.3.2
- index.php +115 -95
- readme.txt +12 -3
index.php
CHANGED
@@ -3,122 +3,142 @@
|
|
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.3.
|
7 |
* Author: Jeffrey-WP
|
8 |
*/
|
9 |
|
10 |
/** register taxonomy for attachments */
|
11 |
function wpmediacategory_init() {
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
add_action( 'init', 'wpmediacategory_init' );
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
$
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
function wpmediacategory_custom_bulk_admin_footer() {
|
30 |
-
$terms = get_terms( 'category', 'hide_empty=0' );
|
31 |
-
if ( $terms && ! is_wp_error( $terms ) ) :
|
32 |
-
?>
|
33 |
-
<script type="text/javascript">
|
34 |
-
jQuery(document).ready(function() {
|
35 |
-
<?php
|
36 |
-
foreach ( $terms as $term ) {
|
37 |
-
echo 'jQuery(\'<option>\').val(\'cat_' . $term->term_taxonomy_id . '\').text(\''. esc_js( __( 'Category' ) ) . ': ' . esc_js( $term->name ) . '\').appendTo("select[name=\'action\']");';
|
38 |
-
echo 'jQuery(\'<option>\').val(\'cat_' . $term->term_taxonomy_id . '\').text(\''. esc_js( __( 'Category' ) ) . ': ' . esc_js( $term->name ) . '\').appendTo("select[name=\'action2\']");';
|
39 |
}
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
/** Handle the custom Bulk Action */
|
51 |
-
function wpmediacategory_custom_bulk_action() {
|
52 |
-
global $wpdb;
|
53 |
|
54 |
-
|
55 |
-
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
if ( substr( $sAction, 0, 4 ) != 'cat_' )
|
60 |
-
return;
|
61 |
|
62 |
-
|
63 |
-
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
$post_ids = array_map('intval', $_REQUEST['media']);
|
68 |
-
}
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
//$pagenum = $wp_list_table->get_pagenum();
|
75 |
-
//$sendback = add_query_arg( 'paged', $pagenum, $sendback );
|
76 |
-
|
77 |
-
$newCategory = str_replace('cat_', '', $sAction);
|
78 |
-
|
79 |
-
foreach( $post_ids as $post_id ) {
|
80 |
-
if ($newCategory == 0) {
|
81 |
-
// remove category
|
82 |
-
$wpdb->delete( $wpdb->term_relationships, array( 'object_id' => $post_id ) );
|
83 |
-
} else {
|
84 |
-
// update or insert category
|
85 |
-
$wpdb->replace( $wpdb->term_relationships,
|
86 |
-
array(
|
87 |
-
'object_id' => $post_id,
|
88 |
-
'term_taxonomy_id' => $newCategory
|
89 |
-
),
|
90 |
-
array(
|
91 |
-
'%d',
|
92 |
-
'%d'
|
93 |
-
)
|
94 |
-
);
|
95 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
}
|
|
|
97 |
|
98 |
-
wp_redirect( $sendback );
|
99 |
-
exit();
|
100 |
-
}
|
101 |
-
add_action( 'load-upload.php', 'wpmediacategory_custom_bulk_action' );
|
102 |
|
103 |
-
/** Display an admin notice on the page after changing category */
|
104 |
-
function wpmediacategory_custom_bulk_admin_notices() {
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
|
|
109 |
}
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
-
/** Add a link to media categories on the plugin page */
|
115 |
-
function wpmediacategory_add_plugin_action_links( $links ) {
|
116 |
-
return array_merge(
|
117 |
-
array(
|
118 |
-
'settings' => '<a href="' . get_bloginfo( 'wpurl' ) . '/wp-admin/edit-tags.php?taxonomy=category&post_type=attachment">' . __('Categories') . '</a>'
|
119 |
-
),
|
120 |
-
$links
|
121 |
-
);
|
122 |
}
|
123 |
-
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpmediacategory_add_plugin_action_links' );
|
124 |
?>
|
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.3.2
|
7 |
* Author: Jeffrey-WP
|
8 |
*/
|
9 |
|
10 |
/** register taxonomy for attachments */
|
11 |
function wpmediacategory_init() {
|
12 |
+
// Default taxonomy
|
13 |
+
$taxonomy = 'category';
|
14 |
+
// Add filter to change the default taxonomy
|
15 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
16 |
+
register_taxonomy_for_object_type( $taxonomy, 'attachment' );
|
17 |
}
|
18 |
add_action( 'init', 'wpmediacategory_init' );
|
19 |
|
20 |
+
// load code that is only needed in the admin section
|
21 |
+
if( is_admin() ) {
|
22 |
+
|
23 |
+
/** Add a category filter */
|
24 |
+
function wpmediacategory_add_category_filter() {
|
25 |
+
$screen = get_current_screen();
|
26 |
+
if ( 'upload' == $screen->id ) {
|
27 |
+
// Default taxonomy
|
28 |
+
$taxonomy = 'category';
|
29 |
+
// Add filter to change the default taxonomy
|
30 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
31 |
+
$dropdown_options = array( 'taxonomy' => $taxonomy, 'show_option_all' => __( 'View all categories' ), 'hide_empty' => false, 'hierarchical' => true, 'orderby' => 'name', );
|
32 |
+
wp_dropdown_categories( $dropdown_options );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
+
}
|
35 |
+
add_action( 'restrict_manage_posts', 'wpmediacategory_add_category_filter' );
|
36 |
+
|
37 |
+
|
38 |
+
/** Add custom Bulk Action to the select menus */
|
39 |
+
function wpmediacategory_custom_bulk_admin_footer() {
|
40 |
+
// default taxonomy
|
41 |
+
$taxonomy = 'category';
|
42 |
+
// add filter to change the default taxonomy
|
43 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
44 |
+
$terms = get_terms( $taxonomy, 'hide_empty=0' );
|
45 |
+
if ( $terms && ! is_wp_error( $terms ) ) :
|
46 |
+
|
47 |
+
echo '<script type="text/javascript">';
|
48 |
+
echo 'jQuery(document).ready(function() {';
|
49 |
+
foreach ( $terms as $term ) {
|
50 |
+
echo 'jQuery(\'<option>\').val(\'cat_' . $term->term_taxonomy_id . '\').text(\''. esc_js( __( 'Category' ) ) . ': ' . esc_js( $term->name ) . '\').appendTo("select[name=\'action\']");';
|
51 |
+
echo 'jQuery(\'<option>\').val(\'cat_' . $term->term_taxonomy_id . '\').text(\''. esc_js( __( 'Category' ) ) . ': ' . esc_js( $term->name ) . '\').appendTo("select[name=\'action2\']");';
|
52 |
+
}
|
53 |
+
echo 'jQuery(\'<option>\').val(\'cat_0\').text(\'' . esc_js( _e( 'Category' ) ) . ' ' . esc_js( strtolower( __( 'Remove' ) ) ) . '\').appendTo("select[name=\'action\']");';
|
54 |
+
echo 'jQuery(\'<option>\').val(\'cat_0\').text(\'' . esc_js( _e( 'Category' ) ) . ' ' . esc_js( strtolower( __( 'Remove' ) ) ) . '\').appendTo("select[name=\'action2\']");';
|
55 |
+
echo '});';
|
56 |
+
echo '</script>';
|
57 |
+
|
58 |
+
endif;
|
59 |
+
}
|
60 |
+
add_action( 'admin_footer-upload.php', 'wpmediacategory_custom_bulk_admin_footer' );
|
61 |
|
|
|
|
|
|
|
62 |
|
63 |
+
/** Handle the custom Bulk Action */
|
64 |
+
function wpmediacategory_custom_bulk_action() {
|
65 |
+
global $wpdb;
|
66 |
|
67 |
+
if ( ! isset( $_REQUEST['action'] ) )
|
68 |
+
return;
|
|
|
|
|
69 |
|
70 |
+
// is it a category?
|
71 |
+
$sAction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
|
72 |
+
if ( substr( $sAction, 0, 4 ) != 'cat_' )
|
73 |
+
return;
|
74 |
|
75 |
+
// security check
|
76 |
+
check_admin_referer('bulk-media');
|
|
|
|
|
77 |
|
78 |
+
// make sure ids are submitted. depending on the resource type, this may be 'media' or 'post'
|
79 |
+
if(isset($_REQUEST['media'])) {
|
80 |
+
$post_ids = array_map('intval', $_REQUEST['media']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
+
|
83 |
+
if(empty($post_ids)) return;
|
84 |
+
|
85 |
+
$sendback = admin_url( "upload.php?editCategory=1" );
|
86 |
+
|
87 |
+
//$pagenum = $wp_list_table->get_pagenum();
|
88 |
+
//$sendback = add_query_arg( 'paged', $pagenum, $sendback );
|
89 |
+
|
90 |
+
$newCategory = str_replace('cat_', '', $sAction);
|
91 |
+
|
92 |
+
foreach( $post_ids as $post_id ) {
|
93 |
+
if ($newCategory == 0) {
|
94 |
+
// remove category
|
95 |
+
$wpdb->delete( $wpdb->term_relationships, array( 'object_id' => $post_id ) );
|
96 |
+
} else {
|
97 |
+
// update or insert category
|
98 |
+
$wpdb->replace( $wpdb->term_relationships,
|
99 |
+
array(
|
100 |
+
'object_id' => $post_id,
|
101 |
+
'term_taxonomy_id' => $newCategory
|
102 |
+
),
|
103 |
+
array(
|
104 |
+
'%d',
|
105 |
+
'%d'
|
106 |
+
)
|
107 |
+
);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
wp_redirect( $sendback );
|
112 |
+
exit();
|
113 |
}
|
114 |
+
add_action( 'load-upload.php', 'wpmediacategory_custom_bulk_action' );
|
115 |
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
/** Display an admin notice on the page after changing category */
|
118 |
+
function wpmediacategory_custom_bulk_admin_notices() {
|
119 |
+
global $post_type, $pagenow;
|
120 |
|
121 |
+
if($pagenow == 'upload.php' && $post_type == 'attachment' && isset($_GET['editCategory'])) {
|
122 |
+
echo '<div class="updated"><p>' . __('Settings saved.') . '</p></div>';
|
123 |
+
}
|
124 |
}
|
125 |
+
add_action( 'admin_notices', 'wpmediacategory_custom_bulk_admin_notices' );
|
126 |
+
|
127 |
+
|
128 |
+
/** Add a link to media categories on the plugin page */
|
129 |
+
function wpmediacategory_add_plugin_action_links( $links ) {
|
130 |
+
// default taxonomy
|
131 |
+
$taxonomy = 'category';
|
132 |
+
// add filter to change the default taxonomy
|
133 |
+
$taxonomy = apply_filters( 'wpmediacategory_taxonomy', $taxonomy );
|
134 |
+
return array_merge(
|
135 |
+
array(
|
136 |
+
'settings' => '<a href="' . get_bloginfo( 'wpurl' ) . '/wp-admin/edit-tags.php?taxonomy=' . $taxonomy . '&post_type=attachment">' . __('Categories') . '</a>'
|
137 |
+
),
|
138 |
+
$links
|
139 |
+
);
|
140 |
+
}
|
141 |
+
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpmediacategory_add_plugin_action_links' );
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
|
|
144 |
?>
|
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.8
|
7 |
-
Stable tag: 1.3.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,7 +12,7 @@ Adds the ability to use categories in the media library.
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
Adds the ability to use categories in the
|
16 |
|
17 |
== Installation ==
|
18 |
|
@@ -46,13 +46,22 @@ You can request new features on the [support page](http://wordpress.org/support/
|
|
46 |
Maintaining a plugin and keeping it up to date is hard work. Please support me by making a donation. Thank you.
|
47 |
[Please donate here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSNQMST6R28Q2)
|
48 |
|
|
|
|
|
|
|
|
|
49 |
== Screenshots ==
|
50 |
|
51 |
1. Filter by category in the media library
|
52 |
2. Manage categories in the media library
|
|
|
53 |
|
54 |
== Changelog ==
|
55 |
|
|
|
|
|
|
|
|
|
56 |
= 1.3.1 =
|
57 |
* fixed bug (when having a category with apostrophe)
|
58 |
|
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.8.1
|
7 |
+
Stable tag: 1.3.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
Adds the ability to use categories in the WordPress Media Library. When activated a dropdown of categories will show up in the media library. You can change the category of multiple items at once with bulk actions.
|
16 |
|
17 |
== Installation ==
|
18 |
|
46 |
Maintaining a plugin and keeping it up to date is hard work. Please support me by making a donation. Thank you.
|
47 |
[Please donate here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SSNQMST6R28Q2)
|
48 |
|
49 |
+
= How can I filter on categories when inserting media into a post or page? =
|
50 |
+
This feature is only available in the [premium version](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
51 |
+
|
52 |
+
|
53 |
== Screenshots ==
|
54 |
|
55 |
1. Filter by category in the media library
|
56 |
2. Manage categories in the media library
|
57 |
+
3. Filter by category when inserting media [(premium version)](http://codecanyon.net/item/media-library-categories-premium/6691290?ref=jeffrey-wp)
|
58 |
|
59 |
== Changelog ==
|
60 |
|
61 |
+
= 1.3.2 =
|
62 |
+
* [added taxonomy filter](http://wordpress.org/support/topic/added-taxonomy-filter)
|
63 |
+
* [don't load unnecessary code](http://dannyvankooten.com/3882/wordpress-plugin-structure-dont-load-unnecessary-code/)
|
64 |
+
|
65 |
= 1.3.1 =
|
66 |
* fixed bug (when having a category with apostrophe)
|
67 |
|