pods_access

See if the current user has a certain privilege.

Description

pods_access( (mixed) $privs, (string) $method = 'OR' ); 

Parameters (2)

0. $privs (mixed)
The privilege name or names (array if multiple)
1. $method — Optional. (string) => 'OR'
The access method ("AND", OR)

Usage

  1. if ( !function_exists( 'pods_access' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/general.php'; 
  3.  
  4. // The privilege name or names (array if multiple) 
  5. $privs = null; 
  6.  
  7. // The access method ("AND", "OR") 
  8. $method = 'OR'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pods_access($privs, $method); 
  12.  

Defined (1)

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

/includes/general.php  
  1. function pods_access ( $privs, $method = 'OR' ) { 
  2. // Convert $privs to an array 
  3. $privs = (array) $privs; 
  4.  
  5. // Convert $method to uppercase 
  6. $method = strtoupper( $method ); 
  7.  
  8. $check = apply_filters( 'pods_access', null, $privs, $method ); 
  9. if ( null !== $check && is_bool( $check ) ) 
  10. return $check; 
  11.  
  12. if ( !is_user_logged_in() ) 
  13. return false; 
  14.  
  15. if ( pods_is_admin( array( pods, 'pods_content' ) ) ) 
  16. return true; 
  17.  
  18. // Store approved privs when using "AND" 
  19. $approved_privs = array(); 
  20.  
  21. // Loop through the user's roles 
  22. foreach ( $privs as $priv ) { 
  23. if ( 0 === strpos( $priv, 'pod_' ) ) 
  24. $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 ); 
  25.  
  26. if ( 0 === strpos( $priv, 'manage_' ) ) 
  27. $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 ); 
  28.  
  29. if ( current_user_can( $priv ) ) { 
  30. if ( 'OR' == $method ) 
  31. return true; 
  32.  
  33. $approved_privs[ $priv ] = true; 
  34. if ( 'AND' == strtoupper( $method ) ) { 
  35. foreach ( $privs as $priv ) { 
  36. if ( 0 === strpos( $priv, 'pod_' ) ) 
  37. $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 ); 
  38.  
  39. if ( 0 === strpos( $priv, 'manage_' ) ) 
  40. $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 ); 
  41.  
  42. if ( !isset( $approved_privs[ $priv ] ) ) 
  43. return false; 
  44.  
  45. return true; 
  46.  
  47. return false;