Advertisement
Guest User

User Role Restrict Shortcode

a guest
Apr 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.39 KB | None | 0 0
  1. // Add Shortcode
  2. function restrict_content( $atts , $content = null ) {
  3.  
  4.     // Attributes
  5.     $atts = shortcode_atts(
  6.         array(
  7.             'role' => 'administrator',
  8.         ),
  9.         $atts
  10.     );
  11.  
  12.     $user = wp_get_current_user();
  13.     if ( in_array( $atts['role'], (array) $user->roles ) ) {
  14.         return $content;
  15.     } else {
  16.         return false;
  17.     }
  18.    
  19.  
  20. }
  21. add_shortcode( 'restrict_content', 'restrict_content' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement