Created
February 16, 2013 18:13
-
-
Save gabssnake/4967996 to your computer and use it in GitHub Desktop.
functions to modify the behaviour of Media Library in Wordpress
This file contains 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
// à mettre dans le fichier functions.php | |
// create a new category in Media Library for PDF file type | |
function modify_post_mime_types( $post_mime_types ) { | |
// select the mime type, here: 'application/pdf' | |
// then we define an array with the label values | |
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) ); | |
// then we return the $post_mime_types variable | |
return $post_mime_types; | |
} | |
add_filter( 'post_mime_types', 'modify_post_mime_types' ); | |
// ---------------- | |
// s'il s'agit pas d'un administrateur | |
// montrer seulement les images à lui | |
add_action('pre_get_posts','users_own_attachments'); | |
function users_own_attachments( $wp_query_obj ) { | |
global $current_user, $pagenow; | |
if( !is_a( $current_user, 'WP_User') ) | |
return; | |
if( 'upload.php' != $pagenow ) | |
return; | |
if( !current_user_can('delete_pages') ) | |
$wp_query_obj->set('author', $current_user->id ); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment