Media Library Categories - Version 1.4.1

Version Description

  • improved bulk actions: added option to remove category from multiple media items at once.
  • improved bulk actions: arranged options in option group
Download this release

Release Info

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

Code changes from version 1.3.2 to 1.4.1

Files changed (2) hide show
  1. index.php +54 -16
  2. readme.txt +10 -3
index.php CHANGED
@@ -3,8 +3,9 @@
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 */
@@ -46,14 +47,26 @@ if( is_admin() ) {
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
  }
@@ -69,7 +82,7 @@ if( is_admin() ) {
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
@@ -87,24 +100,50 @@ if( is_admin() ) {
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
 
@@ -139,6 +178,5 @@ if( is_admin() ) {
139
  );
140
  }
141
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpmediacategory_add_plugin_action_links' );
142
-
143
  }
144
  ?>
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
  */
10
 
11
  /** register taxonomy for attachments */
47
 
48
  echo '<script type="text/javascript">';
49
  echo 'jQuery(document).ready(function() {';
50
+ echo 'jQuery(\'<optgroup id="wpmediacategory_optgroup1" label="' . html_entity_decode( __( 'Categories' ), ENT_QUOTES, 'UTF-8' ) . '">\').appendTo("select[name=\'action\']");';
51
+ echo 'jQuery(\'<optgroup id="wpmediacategory_optgroup2" label="' . html_entity_decode( __( 'Categories' ), ENT_QUOTES, 'UTF-8' ) . '">\').appendTo("select[name=\'action2\']");';
52
+
53
+ // add categories
54
+ foreach ( $terms as $term ) {
55
+ $sTxtAdd = esc_js( __( 'Add' ) . ': ' . $term->name );
56
+ echo "jQuery('<option>').val('wpmediacategory_add_" . $term->term_taxonomy_id . "').text('". $sTxtAdd . "').appendTo('#wpmediacategory_optgroup1');";
57
+ echo "jQuery('<option>').val('wpmediacategory_add_" . $term->term_taxonomy_id . "').text('". $sTxtAdd . "').appendTo('#wpmediacategory_optgroup2');";
58
+ }
59
+ // remove categories
60
  foreach ( $terms as $term ) {
61
+ $sTxtRemove = esc_js( __( 'Remove' ) . ': ' . $term->name );
62
+ echo "jQuery('<option>').val('wpmediacategory_remove_" . $term->term_taxonomy_id . "').text('". $sTxtRemove . "').appendTo('#wpmediacategory_optgroup1');";
63
+ echo "jQuery('<option>').val('wpmediacategory_remove_" . $term->term_taxonomy_id . "').text('". $sTxtRemove . "').appendTo('#wpmediacategory_optgroup2');";
64
  }
65
+ // remove all categories
66
+ echo "jQuery('<option>').val('wpmediacategory_remove_0').text('" . esc_js( __( 'Delete all' ) ) . "').appendTo('#wpmediacategory_optgroup1');";
67
+ echo "jQuery('<option>').val('wpmediacategory_remove_0').text('" . esc_js( __( 'Delete all' ) ) . "').appendTo('#wpmediacategory_optgroup2');";
68
+ echo "});";
69
+ echo "</script>";
70
 
71
  endif;
72
  }
82
 
83
  // is it a category?
84
  $sAction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
85
+ if ( substr( $sAction, 0, 16 ) != 'wpmediacategory_' )
86
  return;
87
 
88
  // security check
100
  //$pagenum = $wp_list_table->get_pagenum();
101
  //$sendback = add_query_arg( 'paged', $pagenum, $sendback );
102
 
 
 
103
  foreach( $post_ids as $post_id ) {
104
+
105
+ if ( is_numeric( str_replace('wpmediacategory_add_', '', $sAction) ) ) {
106
+ $nCategory = str_replace('wpmediacategory_add_', '', $sAction);
107
+
108
  // update or insert category
109
  $wpdb->replace( $wpdb->term_relationships,
110
  array(
111
  'object_id' => $post_id,
112
+ 'term_taxonomy_id' => $nCategory
113
  ),
114
  array(
115
  '%d',
116
  '%d'
117
  )
118
  );
119
+
120
+ } else if ( is_numeric( str_replace('wpmediacategory_remove_', '', $sAction) ) ) {
121
+ $nCategory = str_replace('wpmediacategory_remove_', '', $sAction);
122
+
123
+ // remove all categories
124
+ if ($nCategory == 0) {
125
+ $wpdb->delete( $wpdb->term_relationships,
126
+ array(
127
+ 'object_id' => $post_id
128
+ ),
129
+ array(
130
+ '%d'
131
+ )
132
+ );
133
+ // remove category
134
+ } else {
135
+ $wpdb->delete( $wpdb->term_relationships,
136
+ array(
137
+ 'object_id' => $post_id,
138
+ 'term_taxonomy_id' => $nCategory
139
+ ),
140
+ array(
141
+ '%d',
142
+ '%d'
143
+ )
144
+ );
145
+ }
146
+
147
  }
148
  }
149
 
178
  );
179
  }
180
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpmediacategory_add_plugin_action_links' );
 
181
  }
182
  ?>
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.3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,7 +12,8 @@ Adds the ability to use categories in the media library.
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
 
@@ -49,7 +50,6 @@ Maintaining a plugin and keeping it up to date is hard work. Please support me b
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
@@ -58,6 +58,13 @@ This feature is only available in the [premium version](http://codecanyon.net/it
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/)
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
 
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.
16
+ You can change the category of multiple items at once with bulk actions.
17
 
18
  == Installation ==
19
 
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
 
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)
70
  * [don't load unnecessary code](http://dannyvankooten.com/3882/wordpress-plugin-structure-dont-load-unnecessary-code/)