Advertisement
srikat

functions.php

Apr 27th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. /**
  2.  * Checks if a particular user has a role.
  3.  * Returns true if a match was found.
  4.  *
  5.  * @param string $role Role name.
  6.  * @param int $user_id (Optional) The ID of a user. Defaults to the current user.
  7.  * @return bool
  8.  * Source: https://docs.appthemes.com/tutorials/wordpress-check-user-role-function/
  9.  */
  10. function appthemes_check_user_role( $role, $user_id = null ) {
  11.  
  12.     if ( is_numeric( $user_id ) )
  13.         $user = get_userdata( $user_id );
  14.     else
  15.         $user = wp_get_current_user();
  16.  
  17.     if ( empty( $user ) )
  18.         return false;
  19.  
  20.     return in_array( $role, (array) $user->roles );
  21. }
  22.  
  23. add_action( 'genesis_before_entry', 'sk_access_control' );
  24. function sk_access_control() {
  25.  
  26.     if ( ! is_singular( 'portfolio' ) ) {
  27.         return;
  28.     }
  29.  
  30.     // Remove the post content
  31.     remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  32.  
  33.     if ( appthemes_check_user_role( 'client' ) ) {
  34.  
  35.         // add the post content
  36.         add_action( 'genesis_entry_content', 'genesis_do_post_content' );
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement