Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 14 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Showing with 289 additions and 49 deletions.
  1. +61 −0 media-categories-script-3.4.js
  2. +63 −13 media-categories-script.js
  3. +12 −0 media-categories-style-3.4.css
  4. +61 −5 media-categories-style.css
  5. +75 −25 media-categories.php
  6. +17 −6 readme.txt
View
61 media-categories-script-3.4.js
@@ -0,0 +1,61 @@
+/**
+ * jQuery for Media Categories plugin
+ *
+ * @author Eddie Moya
+ * @since 1.1
+ *
+ */
+
+jQuery(document).ready(function($){
+ $.each(taxonomy, function(index, tax){
+
+ $('.media-upload-form tr.'+ tax + '').hide();
+ $('.media-upload-form tr.' + tax + '_metabox input').live('click', function(){
+
+ var form_fields = $(this).closest("tbody");
+
+ var checked = form_fields.find("." + tax + "_metabox input:checked");
+ var slug_list = '';
+
+ checked.each(function(index){
+
+ if(slug_list.length > 0)
+ slug_list += ',' + $(this).val();
+ else
+ slug_list += $(this).val();
+ });
+
+ form_fields.find("tr."+ tax +" > td.field > input.text").val(slug_list);
+ })
+
+ $.extend($.expr[":"], {
+ "icontains": function(elem, i, match, array) {
+ return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
+ }
+ });
+ /**
+ * The following javascript is borrowed (with few modifications) from Jason Corradino's
+ * 'Searchable Categories' plugin. It allows the category metabox to be filtered
+ * as the user types. To do this with your category meta boxes on pages and posts,
+ * download his plugin.
+ *
+ * http://wordpress.org/extend/plugins/searchable-categories/
+ */
+
+ $('#' + tax + '-search').keyup(function() {
+ var val = $('#' + tax + '-search').val();
+ var lis = $("#"+ tax +"checklist li");
+
+ if(val.length > 0){
+ lis.hide();
+ } else {
+ lis.show();
+ }
+
+ // find li labels's containing term, then back to parent li
+ var containingLabels = $("#"+ tax +"checklist label:icontains('" + val + "')");
+ containingLabels.closest('li').find('li').andSelf().show();
+ containingLabels.parents('#'+ tax +'checklist li').show();
+ });
+ });
+})
View
76 media-categories-script.js
@@ -2,22 +2,66 @@
* jQuery for Media Categories plugin
*
* @author Eddie Moya
- * @since 1.1
+ * @since 1.5
*
*/
+
+
+
jQuery(document).ready(function($){
-
+
+ /**
+ * This modifies the settings for the AttachmentCompat object in media-views.js.
+ * This is needed because saving on change of checkboxes is glitchy when the person clicks multiple checkboxes in a row.
+ */
+ delete wp.media.view.AttachmentCompat.prototype.events['change input'];
+ wp.media.view.AttachmentCompat.prototype.events['change input[type!="checkbox"]'] = 'save';
+
$.each(taxonomy, function(index, tax){
+
+ var metabox_class = '.compat-field-'+tax+'_metabox';
+
+ // Trigger the 'change' event when the mouse leaves the metabox.
+ $(metabox_class).live('mouseleave', function(){
+ $('.compat-item input:first').trigger('change');
+ });
+
+ // Toggle the visiblity of the metabox on clicking the label
+ $(metabox_class + ' th').live('click', function(){
+
+ /*
+ * .categorydiv and .help are hidden by css to start with - to make it start from a closed position.
+ * This is different from the normal toggling of the td.field. This fixes it so that it bhaves normally after
+ * the first click.
+ */
+ if($('.media-sidebar .categorydiv, .media-sidebar .categorydiv + .help').css('display') == 'none'){
+ $(this).parent().find('td.field').hide();
+ $('.media-sidebar .categorydiv, .media-sidebar .categorydiv + .help').show();
+ }
- $('.media-upload-form tr.'+ tax + '').hide();
- $('.media-upload-form tr.' + tax + '_metabox input').live('click', function(){
+ var field_container = $(this).parent().find('td.field');
+ // Depending on the current state of td.field, hide or show it, and flip the arrow indicator.
+ if(field_container.is(":visible")){
+ field_container.slideUp();
+ $(this).parent().find('.arrow-up').attr('class', 'arrow-down');
+
+
+ } else {
+ field_container.slideDown();
+ $(this).parent().find('.arrow-down').attr('class', 'arrow-up');
+
+ }
+ });
+
+ $('.media-sidebar input').live('click', function(){
+
var form_fields = $(this).closest("tbody");
- var checked = form_fields.find("." + tax + "_metabox input:checked");
+ var checked = form_fields.find(".compat-field-" + tax + "_metabox input:checked");
var slug_list = '';
-
+
checked.each(function(index){
if(slug_list.length > 0)
@@ -26,7 +70,8 @@ jQuery(document).ready(function($){
slug_list += $(this).val();
});
- form_fields.find("tr."+ tax +" > td.field > input.text").val(slug_list);
+ form_fields.find("tr.compat-field-"+ tax +" > td.field > input.text").val(slug_list);
+ //$('.compat-item input:first').trigger('change');
})
$.extend($.expr[":"], {
@@ -43,15 +88,20 @@ jQuery(document).ready(function($){
* http://wordpress.org/extend/plugins/searchable-categories/
*/
- $('#' + tax + '-search').keyup(function() {
- var val = $('#' + tax + '-search').val();
- var lis = $("#"+ tax +"checklist li");
- lis.hide();
+ $('#' + tax + '-search').live('keyup', function() {
+ var val = $('.media-sidebar #' + tax + '-search').val();
+ var lis = $(".media-sidebar #"+ tax +"checklist li");
+ if(val.length > 0){
+ lis.hide();
+ } else {
+ lis.show();
+ }
// find li labels's containing term, then back to parent li
- var containingLabels = $("#"+ tax +"checklist label:icontains('" + val + "')");
+ var containingLabels = $(".media-sidebar #"+ tax +"checklist label:icontains('" + val + "')");
+
containingLabels.closest('li').find('li').andSelf().show();
- containingLabels.parents('#'+ tax +'checklist li').show();
+ containingLabels.parents('.media-sidebar #'+ tax +'checklist li').show();
});
});
})
View
12 media-categories-style-3.4.css
@@ -0,0 +1,12 @@
+.media-upload-form .category-tabs,
+.media-upload-form tr.category,
+.media-upload-form #category-adder,
+.media-upload-form .wp-hidden-children{
+ display:none;
+}
+
+.media-upload-form .category-filter {
+ font-size: 12px;
+ font-style: italic;
+ font-family: sans-serif;
+}
View
66 media-categories-style.css
@@ -1,12 +1,68 @@
-.media-upload-form .category-tabs,
-.media-upload-form tr.category,
-.media-upload-form #category-adder,
-.media-upload-form .wp-hidden-children{
+.media-sidebar .category-tabs,
+.media-sidebar tr.compat-field-category,
+.media-sidebar .categorydiv,
+.media-sidebar .categorydiv + .help,
+.media-sidebar #category-adder,
+.media-sidebar .wp-hidden-children{
display:none;
}
-.media-upload-form .category-filter {
+.media-sidebar .category-filter {
font-size: 12px;
font-style: italic;
font-family: sans-serif;
+}
+
+/*.media-sidebar .categorydiv {
+ width:225px;
+ margin-left:-85px;
+}*/
+
+.compat-field-category_metabox td.field {
+ width: 99%;
+}
+.compat-field-category_metabox input[type="checkbox"] {
+ width: auto;
+}
+
+tr.compat-field-category_metabox th.label span {
+ font-weight: bold;
+ text-transform: uppercase;
+ font-size: 12px;
+ color: #777;
+ text-shadow: 0 1px 0 white;
+ margin: 0 0 8px;
+}
+
+.compat-field-category_metabox, .attachment-details.save-ready {
+ overflow: hidden;
+ box-shadow: 0 1px 0 white;
+ border-bottom: 1px solid #E5E5E5;
+ margin-bottom: 16px;
+ padding-bottom: 11px;
+}
+
+div.attachment-details.save-ready {
+ padding-bottom: 24px;
+ margin-bottom: 10px;
+}
+
+.arrow-down {
+ width: 0;
+ height: 0;
+ border-left: 6px solid transparent;
+ border-right: 6px solid transparent;
+ border-top: 10px solid black;
+ display: inline-block;
+ margin-left: 10px;
+}
+
+.arrow-up {
+ width: 0;
+ height: 0;
+ border-left: 6px solid transparent;
+ border-right: 6px solid transparent;
+ border-bottom: 10px solid black;
+ display: inline-block;
+ margin-left: 10px;
}
View
100 media-categories.php
@@ -2,13 +2,13 @@
Plugin Name: Media Categories
Plugin URI: http://wordpress.org/extend/plugins/media-categories-2
Description: Allows users to assign categories to media with a clean and simplified, filterable category meta box and use shortcodes to display category galleries
-Version: 1.4.1
+Version: 1.5
Author: Eddie Moya
Author URL: http://eddiemoya.com
*/
class Media_Categories {
-
+ public static $version = 1.5;
public static $instances;
public $taxonomy;
@@ -17,20 +17,32 @@ class Media_Categories {
* @param type $taxonomy
*/
public function __construct($taxonomy) {
-
+ global $wp_version;
// Store each instance of this class (for use when localizing scripts)
$this->taxonomy = $taxonomy;
self::$instances[] = $this;
add_action('init', array(&$this, 'register_media_categories'));
add_action('init', array(&$this, 'custom_gallery_shortcode'));
+
add_filter('attachment_fields_to_edit', array(&$this, 'add_media_categories_metabox'), null, 2);
+
+ /* Only before WordPress 3.5 */
+ if( $wp_version <= 3.4 ){
+
+ // Patch to solve this in 3.5 was accepted @see http://core.trac.wordpress.org/ticket/20765
+ add_filter('attachment_fields_to_edit', array(__CLASS__, 'get_attachment_fields_to_edit'), 11, 2);
+
+ // Loading these in this fashion no longer applies in 3.5 because of new built-in support for taxonomy metaboxes on the editor page.
+ add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts'));
+ add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') );
+ } else {
+
+ add_action('wp_enqueue_media', array(__CLASS__, 'enqueue_media_categories_scripts'));
+ add_action('wp_enqueue_media', array(__CLASS__, 'enqueue_media_categories_styles') );
+ }
- /* These only need to occur once */
- add_filter('attachment_fields_to_edit', array(__CLASS__, 'get_attachment_fields_to_edit'), 11, 2);
- add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts'));
- add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') );
-
+
}
@@ -39,15 +51,18 @@ public function __construct($taxonomy) {
* Enqueue javascript
*/
function enqueue_media_categories_scripts() {
+ global $wp_version;
+
if (is_admin()) {
// Get each instance of this class, and pass each taxonomy in to javascript
foreach (self::$instances as $instance){
$tax[] = apply_filters('mc_taxonomy', $instance->taxonomy);
}
-
- wp_register_script('media_categories_metabox_script', plugins_url('media-categories-script.js', __FILE__));
+ $filename = ($wp_version <= 3.4) ? 'media-categories-script-3.4.js' : 'media-categories-script.js';
+
+ wp_register_script('media_categories_metabox_script', plugins_url($filename, __FILE__));
wp_enqueue_script('media_categories_metabox_script');
wp_localize_script('media_categories_metabox_script', 'taxonomy', $tax);
@@ -58,9 +73,13 @@ function enqueue_media_categories_scripts() {
*
*/
function enqueue_media_categories_styles() {
+ global $wp_version;
+
if (is_admin()) {
- wp_register_style('media_categories_metabox_style', plugins_url('media-categories-style.css', __FILE__));
+ $filename = ($wp_version <= 3.4) ? 'media-categories-style-3.4.css' : 'media-categories-style.css';
+
+ wp_register_style('media_categories_metabox_style', plugins_url($filename , __FILE__));
wp_enqueue_style( 'media_categories_metabox_style');
}
}
@@ -81,7 +100,7 @@ function register_media_categories() {
* a normal textfield, I capture the output of a custom metabox and insert it.
*/
function add_media_categories_metabox($form_fields, $post) {
-
+ global $wp_version;
require_once('./includes/meta-boxes.php');
$tax_name = apply_filters('mc_taxonomy', $this->taxonomy);
@@ -95,10 +114,14 @@ function add_media_categories_metabox($form_fields, $post) {
$form_slug = $this->taxonomy . '_metabox';
- $form_fields[$form_slug]['label'] = $taxonomy->labels->name;
+ $form_fields[$form_slug]['label'] = $taxonomy->labels->name . "<div class='arrow-down'></div>";
$form_fields[$form_slug]['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name));
$form_fields[$form_slug]['input'] = 'html';
$form_fields[$form_slug]['html'] = $metabox;
+
+ // After 3.5 this will make sure the metabox only loads on the modal.
+ $form_fields[$form_slug]['show_in_edit'] = false;
+
return $form_fields;
}
@@ -126,12 +149,12 @@ function media_categories_meta_box($post, $box) {
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
$tax = get_taxonomy($taxonomy);
?>
-
- <div>
+
+ <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
+ <div class="taxonomy-metabox-field-container">
<label class='category-filter' for="category-filter">Search <?php echo $tax->labels->name; ?>:</label>
- <input id='<?php echo $taxonomy?>-search' name="category-filter" type='text' /></div>
- <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
-
+ <input id='<?php echo $taxonomy?>-search' name="category-filter" type='text' />
+ </div>
<ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
<li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
<li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e('Most Used'); ?></a></li>
@@ -207,11 +230,25 @@ function custom_gallery_shortcode(){
* @return string HTML content to display gallery.
*/
function gallery_shortcode($attr) {
- global $post;
+ global $wp_version;
+
+ // Could probably just leave it as get_post(), but i'm being lazy and don't feel like testing to be sure - so im putting in this logic to avoid any possible problem.
+ if($wp_version <= 3.4){
+ global $post;
+ } else {
+ $post = get_post();
+ }
static $instance = 0;
$instance++;
+ if ( ! empty( $attr['ids'] ) ) {
+ // 'ids' is explicitly ordered, unless you specify otherwise.
+ if ( empty( $attr['orderby'] ) )
+ $attr['orderby'] = 'post__in';
+ $attr['include'] = $attr['ids'];
+ }
+
// Allow plugins/themes to override the default gallery template.
$output = apply_filters('post_gallery', '', $attr);
if ( $output != '' )
@@ -243,28 +280,39 @@ function gallery_shortcode($attr) {
if ( 'RAND' == $order )
$orderby = 'none';
+ $tax_query = array();
+
if( !empty($$mc_tax) ){
$term = ${$mc_tax};
$term_field = (is_numeric($term)) ? 'id' : 'slug';
+ $tax_query = array(
+ 'tax_query' => array(
+ array(
+ 'taxonomy' => $mc_tax,
+ 'field' => $term_field,
+ 'terms' => $term
+ )
+ )
+ );
if(!isset($attr['id']))
$id = '';
}
if ( !empty($include) ) {
- $include = preg_replace( '/[^0-9,]+/', '', $include );
- $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) );
+ //$include = preg_replace( '/[^0-9,]+/', '', $include ); see: http://core.trac.wordpress.org/ticket/21827
+ $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) + $tax_query );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( !empty($exclude) ) {
- $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
- $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) );
+ //$exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); see: http://core.trac.wordpress.org/ticket/21827
+ $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) + $tax_query );
} else {
- $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) );
+ $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) + $tax_query );
}
if ( empty($attachments) )
@@ -346,7 +394,9 @@ function gallery_shortcode($attr) {
* and its only purpose is to change the output of terms in attachments so that they used term slugs
* rather than names.
*
- * @linkhttp://core.trac.wordpress.org/ticket/20765
+ * NOTE: This is no longer necessary in WordPress 3.5 - the patch fixing this problem was committed.
+ *
+ * @link http://core.trac.wordpress.org/ticket/20765
* @link http://wordpress.org/support/topic/media-categories-2-not-saving-correctly-when-two-categories-with-same-name
* @see /wp-admin/includes/media.php:get_attachemt_fields_to_edit()
*
View
23 readme.txt
@@ -1,9 +1,9 @@
=== Media Categories ===
Contributors: eddiemoya
Donate link: http://eddiemoya.com
-Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment, images, gallery shortcode, gallery, shortcode, gallery category, filter, media taxonomy, post tags
+Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment, images, gallery shortcode, gallery, shortcode, gallery category, filter, media taxonomy, post tags, modal, category filter
Requires at least: 3.0
-Tested up to: 3.3.2
+Tested up to: 3.5
Stable tag: 1.4.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -17,13 +17,14 @@ The "Search Categories" field allows you to narrow your search for a category as
[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts
[download his plugin here](http://wordpress.org/extend/plugins/searchable-categories/)
+Since WordPress 3.5 now supports attachment taxonomy, the work of adding a metabox to the attachment editor is happening entirely inside of WordPress. This is great, and we now have true metaboxes for taxonomy - they core team has also accepted my patches which caused several headaches for this plugin. However the new Media Modal in 3.5 leaves something to be desired. I've worked to try to make something that doesnt take up too much space, while still being functional. To be sure, there are some behavioral bugs to work out, it will be a work in progress as the kinks are worked out of the new Media Modal as well as this plugin.
= Updates =
-* **NEW! Since version 1.4 : This plugin allows for **multiple metaboxes** to be created for any number of taxonomies.
+* Since version 1.5 : Supports the new WordPress 3.5 by adding the metabox to the new Media Modal. Also fixed bugs in the gallery shorcode behavior. All while still supporting 3.0 - 3.4.x
+* Since version 1.4 : This plugin allows for **multiple metaboxes** to be created for any number of taxonomies.
* Since version 1.3 : A **filter** has been added to allow developers to modify which taxonomy is being used. See 'Other Notes' > 'Taxonomy Filter Usage' for details
* Since version 1.2 : This plugin extends the native **[gallery] shortcode** of WordPress so that it has a 'category' parameter. See the "Shortcode Usage" under "Other Notes" for more details.
-
== Shortcode Usage ==
= Normal Shortcode Usage =
@@ -154,13 +155,13 @@ this is done.
No. Currently there is no way to change the taxonomy, or create additional taxonomy metaboxes
in the Media Library without adding a little bit of PHP (preferably to you theme).
-Have no fear however, I do have intentions to add magical plugins options pages to allow
+Have no fear however, I do have intentions to add magical plugin options pages to allow
as much as possible to be done without development - sorry but I have no timeline for when this
might happen.
= Is there any way to see all the attachment/media items associated to a category/taxonomy term, the way we can with Posts? =
-Not yet. The next major effort in this plugins development is going to be the addition of taxonomy listing pages.
+In WordPress 3.5, you can now see any taxonomy enabled for attachments the same way you see Categories for Posts. For earlier versions, I'm afraid the answer is no.
= I found a bug, or I would like to suggest/request a feature, can I submit it? =
@@ -174,6 +175,13 @@ any bugs to you see. Preferably on the WordPress plugin directory, but if you fe
== Changelog ==
+= 1.5 =
+* Updated for WordPress 3.5
+* For WordPress 3.5 - Stop showing our custom metabox in the main image editor, let users use the built in metaboxes.
+* For WordPress 3.5 - Add customized metabox to the new Media Modal attachment details.
+* Bugfix: Gallery Shortcode would only work if a taxonomy and term were provided. This has been solved for all supported version of WordPress.
+* Bugfix: The search filter on the metabox - once use and all text removed, would empty out the entire list of terms, because no terms matched an empty string. This has been solved for all version of WordPress.
+
= 1.4.1 =
* Missing javascript update for the 1.4 update.
@@ -202,6 +210,9 @@ any bugs to you see. Preferably on the WordPress plugin directory, but if you fe
== Upgrade Notice ==
+= 1.5 =
+Update for WordPress 3.5 compatibility, and important bug fixes for all versions of WordPress
+
= 1.4.1 =
Bug Fix! Fixed javascript when using multiple taxonomy metaboxes.

No commit comments for this range

Something went wrong with that request. Please try again.