pods_permission

Check if a user has permission to be doing something based on standard permission options.

Description

pods_permission( (array) $options ); 

Parameters (1)

0. $options (array)
The options.

Usage

  1. if ( !function_exists( 'pods_permission' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/general.php'; 
  3.  
  4. // The options. 
  5. $options = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pods_permission($options); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/general.php  
  1. function pods_permission ( $options ) { 
  2. global $current_user; 
  3.  
  4. get_currentuserinfo(); 
  5.  
  6. $permission = false; 
  7.  
  8. if ( isset( $options[ 'options' ] ) ) 
  9. $options = $options[ 'options' ]; 
  10.  
  11. if ( pods_is_admin() ) 
  12. $permission = true; 
  13. elseif ( 0 == pods_v( 'restrict_role', $options, 0 ) && 0 == pods_v( 'restrict_capability', $options, 0 ) && 0 == pods_v( 'admin_only', $options, 0 ) ) 
  14. $permission = true; 
  15.  
  16. if ( !$permission && 1 == pods_v( 'restrict_role', $options, 0 ) ) { 
  17. $roles = pods_v( 'roles_allowed', $options ); 
  18.  
  19. if ( !is_array( $roles ) ) 
  20. $roles = explode( ', ', $roles ); 
  21.  
  22. $roles = array_unique( array_filter( $roles ) ); 
  23.  
  24. foreach( $roles as $role ) { 
  25. if ( is_user_logged_in() && in_array( $role, $current_user->roles ) ) { 
  26. $permission = true; 
  27.  
  28. break; 
  29.  
  30. if ( !$permission && 1 == pods_v( 'restrict_capability', $options, 0 ) ) { 
  31. $capabilities = pods_v( 'capability_allowed', $options ); 
  32.  
  33. if ( !is_array( $capabilities ) ) 
  34. $capabilities = explode( ', ', $capabilities ); 
  35.  
  36. $capabilities = array_unique( array_filter( $capabilities ) ); 
  37.  
  38. foreach( $capabilities as $capability ) { 
  39. $must_have_capabilities = explode( '&&', $capability ); 
  40. $must_have_capabilities = array_unique( array_filter( $must_have_capabilities ) ); 
  41.  
  42. $must_have_permission = true; 
  43.  
  44. foreach ( $must_have_capabilities as $must_have_capability ) { 
  45. if ( !current_user_can( $must_have_capability ) ) { 
  46. $must_have_permission = false; 
  47.  
  48. break; 
  49.  
  50. if ( $must_have_permission && is_user_logged_in() ) { 
  51. $permission = true; 
  52.  
  53. break; 
  54.  
  55. return $permission;