um_access_frontpage_per_role

The Ultimate Member um access frontpage per role function.

Description

um_access_frontpage_per_role(); 

Usage

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

Defined (1)

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

/core/um-actions-access.php  
  1. function um_access_frontpage_per_role() { 
  2. global $ultimatemember, $post; 
  3.  
  4. if ( is_admin() ) return; 
  5. if ( ! is_front_page() ) return; 
  6. if( is_404() ) return; 
  7.  
  8. if ( ! isset( $um_post_id ) && isset( $post->ID ) ) { 
  9. $um_post_id = $post->ID; 
  10.  
  11. if( ! isset( $um_post_id ) ) { 
  12. return; 
  13.  
  14. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  15. extract( $args ); 
  16.  
  17. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  18.  
  19. $um_post_id = apply_filters('um_access_control_for_parent_posts', $um_post_id ); 
  20.  
  21. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  22. extract( $args ); 
  23.  
  24. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  25. return; 
  26.  
  27.  
  28. $redirect_to = null; 
  29.  
  30. if ( !isset( $accessible ) ) return; 
  31.  
  32. switch( $accessible ) { 
  33.  
  34. case 0: 
  35. $ultimatemember->access->allow_access = true; 
  36. $ultimatemember->access->redirect_handler = false; // open to everyone 
  37.  
  38. break; 
  39.  
  40. case 1: 
  41.  
  42. $redirect_to = $access_redirect2; 
  43.  
  44. if ( is_user_logged_in() ) { 
  45. $ultimatemember->access->allow_access = false; 
  46.  
  47. if ( ! is_user_logged_in() ) { 
  48. $ultimatemember->access->allow_access = true; 
  49.  
  50. if( ! empty( $redirect_to ) ) { 
  51. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_1a" ); 
  52. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  53. }else{ 
  54. if ( ! is_user_logged_in() ) { 
  55. $redirect_to = um_get_core_page("login"); 
  56. }else{ 
  57. $redirect_to = um_get_core_page("user"); 
  58.  
  59. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_1b" ); 
  60. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  61.  
  62.  
  63. break; 
  64.  
  65. case 2: 
  66.  
  67. if ( ! is_user_logged_in() ) { 
  68.  
  69. if ( empty( $access_redirect ) ) { 
  70. $access_redirect = um_get_core_page('login'); 
  71.  
  72. $redirect_to = $access_redirect; 
  73. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_2a" ); 
  74.  
  75.  
  76. if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ) { 
  77. $access_roles = unserialize( $access_roles ); 
  78. $access_roles = array_filter($access_roles); 
  79.  
  80. if ( !empty( $access_roles ) && !in_array(um_user'role'), $access_roles ) ) { 
  81. if ( empty( $access_redirect ) ) { 
  82. if ( is_user_logged_in() ) { 
  83. $access_redirect = site_url(); 
  84. } else { 
  85. $access_redirect = um_get_core_page('login'); 
  86. $redirect_to = esc_url( $access_redirect ); 
  87. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_2b" ); 
  88.  
  89.  
  90.  
  91. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  92.  
  93. break; 
  94.  
  95.