Guest User

Untitled

a guest
Aug 15th, 2016
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function add_role_filter_to_posts_administration(){
  2.  
  3.     //execute only on the 'post' content type
  4.     global $post_type;
  5.     if($post_type == 'post'){
  6.  
  7.         $user_role  = '';
  8.         // Get all user roles
  9.         $user_roles = array();
  10.         foreach ( get_editable_roles() as $key => $values ) :
  11.             $user_roles[ $key ] = $values['name'];
  12.         endforeach;
  13.         // Set a selected user role
  14.         if ( ! empty( $_GET['user_role'] ) ) {
  15.             $user_role  = sanitize_text_field( $_GET['user_role'] );
  16.         }
  17.  
  18.         ?><select name='user_role'>
  19.             <option value=''><?php _e( 'All Roles', 'papasemarone' ); ?></option><?php
  20.             foreach ( $user_roles as $key => $value ) :
  21.                 ?><option <?php selected( $user_role, $key ); ?> value='<?php echo $key; ?>'><?php echo $value; ?></option><?php
  22.             endforeach;
  23.         ?></select><?php
  24.  
  25.     }
  26.  
  27. }
  28. add_action('restrict_manage_posts','add_role_filter_to_posts_administration');
RAW Paste Data