um_access_homepage_per_role

The Ultimate Member um access homepage per role function.

Description

um_access_homepage_per_role(); 

Usage

  1. if ( !function_exists( 'um_access_homepage_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_homepage_per_role(); 
  7.  

Defined (1)

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

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