um_admin_do_action__mass_role_sync

The Ultimate Member um admin do action mass role sync function.

Description

um_admin_do_action__mass_role_sync( $action ); 

Parameters (1)

0. $action
The action.

Usage

  1. if ( !function_exists( 'um_admin_do_action__mass_role_sync' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ultimate-member/admin/core/um-admin-actions.php'; 
  3.  
  4. // The action. 
  5. $action = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = um_admin_do_action__mass_role_sync($action); 
  9.  

Defined (1)

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

/admin/core/um-admin-actions.php  
  1. function um_admin_do_action__mass_role_sync( $action ) { 
  2. global $ultimatemember; 
  3. if ( !is_admin() || !current_user_can( 'edit_user' ) ) wp_die('You don\'t have permissions to access this page.'); 
  4.  
  5. if ( !isset($_REQUEST['post']) || !is_numeric( $_REQUEST['post'] ) ) wp_die('You\'re not allowed to do this.'); 
  6.  
  7. $post_id = (int) $_REQUEST['post']; 
  8.  
  9. $post = get_post( $post_id ); 
  10. $slug = $post->post_name; 
  11.  
  12. if ( $slug != $_REQUEST['um_role'] ) 
  13. wp_die('Invalid community role.'); 
  14.  
  15. $um_synced_role = get_post_meta( $post_id, '_um_synced_role', true ); 
  16.  
  17. if ( $slug == 'admin' ) { 
  18. $_REQUEST[wp_role] = 'administrator'; 
  19. update_post_meta( $post_id, '_um_synced_role', 'administrator' ); 
  20. }else{ 
  21. update_post_meta( $post_id, '_um_synced_role', $_REQUEST[wp_role] ); 
  22.  
  23. $wp_role = ( $_REQUEST[wp_role] ) ? $_REQUEST[wp_role] : 'subscriber'; 
  24.  
  25. $users = get_users( array( 'fields' => array( 'ID' ), 'meta_key' => 'role', 'meta_value' => $slug ) ); 
  26. foreach( $users as $user_id ) { 
  27. $wp_user_object = new WP_User( $user_id ); 
  28. $wp_user_object->set_role( $wp_role ); 
  29.  
  30. exit( wp_redirect( admin_url( 'post.php?post=' . $post_id ) . '&action=edit&message=1' ) ); 
  31.