Advertisement
fauzanjeg

Give Selected Role to Access All Media

Jul 29th, 2021 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. /** Give Selected Role to Access All Media */
  2. function give_selected_role_to_access_all_media() {
  3.     $allowed_role = array( 'editor', 'author' ); /* allowed role to access all media */
  4.     $user_role = wp_get_current_user()->roles; /* current user role */
  5.     if ( in_array( $user_role[0], $allowed_role ) && ! current_user_can( 'manage_options' ) ) {
  6.         /* For Show ALl Media in Grid View */
  7.         add_filter( 'ajax_query_attachments_args', 'show_all_media_for_editor_child', 99 );
  8.  
  9.         /** Grid View */
  10.         function show_all_media_for_editor_child( $query ) {
  11.             $query['author'] = '';
  12.             return $query;
  13.         }
  14.  
  15.         /* For Show ALl Media in List View */
  16.         remove_action( 'pre_get_posts', array( JNews\AccountPage::getInstance(), 'users_own_attachments' ) );
  17.     }
  18. }
  19. add_action( 'init', 'give_selected_role_to_access_all_media' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement