um_access_category_settings

The Ultimate Member um access category settings function.

Description

um_access_category_settings(); 

Usage

  1. if ( !function_exists( 'um_access_category_settings' ) ) { 
  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_category_settings(); 
  7.  

Defined (1)

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

/core/um-actions-access.php  
  1. function um_access_category_settings() { 
  2. global $post, $wp_query, $ultimatemember; 
  3.  
  4. if ( is_front_page() ||  
  5. is_home() ||  
  6. is_feed() ||  
  7. is_page() || 
  8. is_404()  
  9. ) { 
  10.  
  11. return; 
  12.  
  13.  
  14. $access = um_get_option('accessible'); 
  15. $current_page_type = um_get_current_page_type(); 
  16.  
  17.  
  18. if( is_category() && ! in_array( $current_page_type , array( 'day', 'month', 'year', 'author', 'archive' ) ) ) { 
  19.  
  20. $um_category = get_the_category();  
  21. $um_category = current( $um_category ); 
  22. $term_id = ''; 
  23.  
  24. if( isset( $um_category->term_id ) ) { 
  25. $term_id = $um_category->term_id; 
  26.  
  27. if( isset( $term_id ) && ! empty( $term_id ) ) { 
  28.  
  29. $opt = get_option("category_$term_id"); 
  30.  
  31. if ( isset( $opt['_um_accessible'] ) ) { 
  32.  
  33. $redirect = false; 
  34.  
  35. switch( $opt['_um_accessible'] ) { 
  36.  
  37. case 0: 
  38.  
  39. $ultimatemember->access->allow_access = true; 
  40. $ultimatemember->access->redirect_handler = ''; // open to everyone 
  41.  
  42. break; 
  43.  
  44. case 1: 
  45.  
  46. if ( is_user_logged_in() ) { 
  47.  
  48. if( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) { 
  49. $redirect = $opt['_um_redirect']; 
  50. }else{  
  51. $redirect = site_url(); 
  52.  
  53. $ultimatemember->access->allow_access = false; 
  54.  
  55. $redirect = $ultimatemember->access->set_referer( $redirect, "category_1" ); 
  56.  
  57. $ultimatemember->access->redirect_handler = esc_url( $redirect ); 
  58.  
  59. if ( ! is_user_logged_in() && ! empty( $redirect ) ) { 
  60. $ultimatemember->access->allow_access = true; 
  61.  
  62. break; 
  63.  
  64. case 2: 
  65.  
  66. if ( ! is_user_logged_in() ) { 
  67.  
  68. if( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) { 
  69. $redirect = $opt['_um_redirect']; 
  70. }else{ 
  71. $redirect = um_get_core_page('login'); 
  72.  
  73. $ultimatemember->access->allow_access = false; 
  74.  
  75. $redirect = $ultimatemember->access->set_referer( $redirect, "category_2a" ); 
  76.  
  77. $ultimatemember->access->redirect_handler = esc_url( $redirect ); 
  78.  
  79. if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ) { 
  80. if ( ! in_array(um_user'role'), $opt['_um_roles'] ) ) { 
  81.  
  82.  
  83. if( isset( $opt['_um_redirect'] ) ) { 
  84. $redirect = $opt['_um_redirect']; 
  85. $redirect = $ultimatemember->access->set_referer( $redirect, "category_2b" ); 
  86.  
  87. $ultimatemember->access->redirect_handler = esc_url( $redirect ); 
  88.  
  89.  
  90.  
  91. } else if ( $access == 2 && ! is_user_logged_in() && is_archive() ) { 
  92.  
  93. $ultimatemember->access->allow_access = false; 
  94. $redirect = um_get_core_page('login'); 
  95. $redirect = $ultimatemember->access->set_referer( $redirect, "category_archive" ); 
  96.  
  97. $ultimatemember->access->redirect_handler = $redirect; 
  98.  
  99. } else if ( is_tax() && get_post_taxonomies( $post ) ) { 
  100.  
  101. $taxonomies = get_post_taxonomies( $post ); 
  102. $categories_ids = array(); 
  103.  
  104. foreach ($taxonomies as $key => $value) { 
  105. $term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids")); 
  106. foreach( $term_list as $term_id ) { 
  107. array_push( $categories_ids , $term_id); 
  108.  
  109. foreach( $categories_ids as $term => $term_id ) { 
  110.  
  111. $opt = get_option("category_$term_id"); 
  112.  
  113. if ( isset( $opt['_um_accessible'] ) ) { 
  114. switch( $opt['_um_accessible'] ) { 
  115.  
  116. case 0: 
  117. $ultimatemember->access->allow_access = true; 
  118. $ultimatemember->access->redirect_handler = false; // open to everyone 
  119. break; 
  120.  
  121. case 1: 
  122.  
  123. if ( is_user_logged_in() ) 
  124. $redirect = ( isset( $opt['_um_redirect'] ) && !empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  125. $redirect = $ultimatemember->access->set_referer( $redirect, "categories_1" ); 
  126. $ultimatemember->access->redirect_handler = $redirect; 
  127. if ( !is_user_logged_in() ) 
  128. $ultimatemember->access->allow_access = true; 
  129.  
  130. break; 
  131.  
  132. case 2: 
  133.  
  134. if ( ! is_user_logged_in() ) { 
  135.  
  136. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : um_get_core_page('login'); 
  137. $redirect = $ultimatemember->access->set_referer( $redirect, "categories_2a" ); 
  138.  
  139. $ultimatemember->access->redirect_handler = $redirect; 
  140.  
  141. if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ) { 
  142. if ( !in_array(um_user'role'), $opt['_um_roles'] ) ) { 
  143. $redirect = null; 
  144. if ( is_user_logged_in() ) { 
  145. $redirect = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  146.  
  147. if ( !is_user_logged_in() ) { 
  148. $redirect = um_get_core_page('login'); 
  149.  
  150. $redirect = $ultimatemember->access->set_referer( $redirect, "categories_2b" ); 
  151. $ultimatemember->access->redirect_handler = $redirect; 
  152.  
  153.  
  154.