Last active
December 15, 2015 10:28
-
-
Save sagarjadhav/5245392 to your computer and use it in GitHub Desktop.
Media Taxonomy Support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Registers Taxonomies | |
* | |
* @since rtPanelChild 1.0 | |
*/ | |
function rtp_create_taxonomies() { | |
/* Post Custom Taxonomy */ | |
register_taxonomy( 'media-categories', 'attachment', array( | |
'hierarchical' => true, | |
'update_count_callback' => '', | |
'rewrite' => true, | |
'query_var' => 'media-categories', | |
'public' => true, | |
'show_ui' => null, | |
'show_tagcloud' => null, | |
'_builtin' => false, | |
'labels' => array( | |
'name' => _x( 'Media Categories', 'taxonomy general name', 'rtPanel' ), | |
'singular_name' => _x( 'Media Category', 'taxonomy singular name', 'rtPanel' ), | |
'search_items' => __( 'Search Media Categories', 'rtPanel' ), | |
'all_items' => __( 'All Media Categories', 'rtPanel' ), | |
'parent_item' => array( null, __( 'Parent Media Category', 'rtPanel' ) ), | |
'parent_item_colon' => array( null, __( 'Parent Media Category:', 'rtPanel' ) ), | |
'edit_item' => __( 'Edit Media Category', 'rtPanel' ), | |
'view_item' => __( 'View Media Category', 'rtPanel' ), | |
'update_item' => __( 'Update Media Category', 'rtPanel' ), | |
'add_new_item' => __( 'Add New Media Category', 'rtPanel' ), | |
'new_item_name' => __( 'New Media Category Name', 'rtPanel' ) ), | |
'capabilities' => array(), | |
'show_in_nav_menus' => null, | |
'label' => __( 'Media Categories', 'rtPanel' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ) ) | |
); | |
} | |
add_action( 'init', 'rtp_create_taxonomies' ); | |
/* Add Taxonomy Column In Media */ | |
/* Add a new column */ | |
function rtp_add_topic_column($posts_columns) { | |
$posts_columns['media_cat'] = _x('Media Category', 'column name', 'rtPanel'); | |
return $posts_columns; | |
} | |
add_filter('manage_media_columns', 'rtp_add_topic_column'); | |
/* Register the column as sortable */ | |
function rtp_topic_column_register_sortable( $columns ) { | |
$columns['media_cat'] = 'media_cat'; | |
return $columns; | |
} | |
add_filter( 'manage_upload_sortable_columns', 'rtp_topic_column_register_sortable' ); | |
/* Manage media custom column */ | |
function rtp_manage_attachment_topic_column($column_name, $id) { | |
switch( $column_name ) { | |
case 'media_cat': | |
$tags = wp_get_object_terms( $id, 'media-categories', '' ); | |
if ( !empty( $tags ) ) { | |
$media_category_list_items = ''; | |
foreach ( $tags as $c ) { | |
if ( strlen( $media_category_list_items ) ) $media_category_list_items .= ', '; | |
$media_category_list_items .= '<a href="'. rtp_get_mediacat_admin_library_link( $c->term_id). '">'. $c->name. '</a>'; | |
} | |
echo $media_category_list_items; | |
} else { | |
_e('Uncategorized', 'rtPanel'); | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
add_action('manage_media_custom_column', 'rtp_manage_attachment_topic_column', 10, 2); | |
/* Get mediacat admin library link */ | |
function rtp_get_mediacat_admin_library_link( $mediacat_id ) { | |
$base_url = "upload.php?"; | |
$media_cat = &get_term( $mediacat_id, 'media-categories' ); | |
if ( is_wp_error( $media_cat ) ) | |
return; | |
$edit_href = $base_url . 'media-categories' ."=".$media_cat->slug; | |
return $edit_href; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment