wc_modify_map_meta_cap

Modify capabiltiies to prevent non-admin users editing admin users.

Description

(array) wc_modify_map_meta_cap( (array) $caps, (string) $cap, (int) $user_id, (array) $args ); 

$args[0] will be the user being edited in this case.

Returns (array)

Parameters (4)

0. $caps (array)
Array of caps
1. $cap (string)
Name of the cap we are checking
2. $user_id (int)
ID of the user being checked against
3. $args (array)
The args.

Usage

  1. if ( !function_exists( 'wc_modify_map_meta_cap' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-user-functions.php'; 
  3.  
  4. // Array of caps 
  5. $caps = array(); 
  6.  
  7. // Name of the cap we are checking 
  8. $cap = ''; 
  9.  
  10. // ID of the user being checked against 
  11. $user_id = -1; 
  12.  
  13. // The args. 
  14. $args = array(); 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wc_modify_map_meta_cap($caps, $cap, $user_id, $args); 
  18.  

Defined (1)

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

/includes/wc-user-functions.php  
  1. function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) { 
  2. switch ( $cap ) { 
  3. case 'edit_user' : 
  4. case 'remove_user' : 
  5. case 'promote_user' : 
  6. case 'delete_user' : 
  7. if ( ! isset( $args[0] ) || $args[0] === $user_id ) { 
  8. break; 
  9. } else { 
  10. if ( user_can( $args[0], 'administrator' ) && ! current_user_can( 'administrator' ) ) { 
  11. $caps[] = 'do_not_allow'; 
  12. break; 
  13. return $caps;