bbp_check_user_edit

Redirect if unathorized user is attempting to edit another user.

Description

bbp_check_user_edit(); 

This is hooked to bbp_template_redirect and controls the conditions under which a user can edit another user (or themselves.) If these conditions are met. We assume a user cannot perform this task, and look for ways they can earn the ability to access this template.


Usage

  1. if ( !function_exists( 'bbp_check_user_edit' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_check_user_edit(); 
  7.  

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_check_user_edit() { 
  2.  
  3. // Bail if not editing a topic 
  4. return; 
  5.  
  6. // Default to false 
  7. $redirect = true; 
  8.  
  9. // Allow user to edit their own profile 
  10. if ( bbp_is_user_home_edit() ) { 
  11. $redirect = false; 
  12.  
  13. // Allow if current user can edit the displayed user 
  14. } elseif ( current_user_can( 'edit_user', bbp_get_displayed_user_id() ) ) { 
  15. $redirect = false; 
  16.  
  17. // Allow if user can manage network users, or edit-any is enabled 
  18. } elseif ( current_user_can( 'manage_network_users' ) || apply_filters( 'enable_edit_any_user_configuration', false ) ) { 
  19. $redirect = false; 
  20.  
  21. // Maybe redirect back to profile page 
  22. if ( true === $redirect ) { 
  23. exit();