um_access_post_settings

The Ultimate Member um access post settings function.

Description

um_access_post_settings(); 

Usage

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

Defined (1)

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

/core/um-actions-access.php  
  1. function um_access_post_settings() { 
  2. global $post, $ultimatemember; 
  3.  
  4. // woo commerce shop ID 
  5. if( function_exists('is_shop') && is_shop() ) { 
  6.  
  7. $um_post_id = get_option('woocommerce_shop_page_id'); 
  8.  
  9. } else if (  
  10. is_category() ||  
  11. is_archive() ||  
  12. is_search() ||  
  13. in_the_loop() ||  
  14. is_feed() ||  
  15. is_tax() || 
  16. ! get_post_type() || 
  17. ! isset( $post->ID ) || 
  18. is_home() || 
  19. is_front_page() || 
  20. is_404()  
  21. ) { 
  22.  
  23. return; 
  24.  
  25. }  
  26.  
  27. if ( !isset( $um_post_id ) ) { 
  28. $um_post_id = $post->ID; 
  29.  
  30. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  31.  
  32.  
  33. extract( $args ); 
  34.  
  35. // Check for parent page's custom access settings 
  36. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  37.  
  38. $um_post_id = apply_filters('um_access_control_for_parent_posts', $um_post_id ); 
  39.  
  40. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  41. extract( $args ); 
  42.  
  43.  
  44. if( isset( $post->ID ) ) { 
  45. $post_type = get_post_type( $post->ID ); 
  46.  
  47. // post's category restriction 
  48. if ( $post_type != 'page' && isset( $args['custom_access_settings'] ) && $args['custom_access_settings'] == 0 ) { 
  49.  
  50. $categories = get_the_category( $post->ID ); 
  51. foreach( $categories as $cat ) { 
  52.  
  53. $opt = get_option("category_{$cat->term_id}"); 
  54.  
  55. if ( isset( $opt['_um_accessible'] ) ) { 
  56. switch( $opt['_um_accessible'] ) { 
  57.  
  58. case 0: // Open to everyone 
  59. $ultimatemember->access->allow_access = true; 
  60. $ultimatemember->access->redirect_handler = false; // open to everyone 
  61. break; 
  62.  
  63. case 1: // Logged out users only 
  64.  
  65. if ( is_user_logged_in() ) { 
  66. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  67. $redirect = $ultimatemember->access->set_referer( $redirect, "page_cat_1a_t{$cat->term_id}_pt{$post_type}" ); 
  68. $ultimatemember->access->redirect_handler = $redirect; 
  69. $ultimatemember->access->allow_access = false; 
  70.  
  71. if ( !is_user_logged_in() ) { 
  72. $ultimatemember->access->allow_access = true; 
  73.  
  74. break; 
  75.  
  76. case 2: // Logged in users only 
  77.  
  78. if ( ! is_user_logged_in() ) { 
  79.  
  80. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : um_get_core_page('login'); 
  81.  
  82. $redirect = $ultimatemember->access->set_referer( $redirect, "page_cat_2a_t{$cat->term_id}_pt{$post_type}" ); 
  83. $ultimatemember->access->redirect_handler = $redirect; 
  84.  
  85. $ultimatemember->access->allow_access = false; 
  86.  
  87. if ( is_user_logged_in() ) { 
  88.  
  89. if( isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ) { 
  90.  
  91. if ( in_array(um_user'role'), $opt['_um_roles'] ) ) { 
  92.  
  93. $ultimatemember->access->allow_access = true; 
  94.  
  95. }else{ 
  96.  
  97. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  98. $redirect = $ultimatemember->access->set_referer( $redirect, "page_cat_2b_t{$cat->term_id}_pt{$post_type}" ); 
  99. $ultimatemember->access->redirect_handler = $redirect; 
  100.  
  101. $ultimatemember->access->allow_access = false; 
  102.  
  103.  
  104. }else{ // if allowed all roles 
  105. $ultimatemember->access->allow_access = true; 
  106.  
  107.  
  108.  
  109.  
  110. } // end if isset( $opt['_um_accessible'] ) 
  111.  
  112. // if one of the categories has enabled restriction, apply its settings to the current post 
  113. if( $ultimatemember->access->allow_access == false ) { 
  114. return; 
  115.  
  116. } // end foreach 
  117.  
  118. // post restriction 
  119. if ( isset( $args['custom_access_settings'] ) && $args['custom_access_settings'] == 1 ) { 
  120.  
  121. $redirect_to = null; 
  122.  
  123. if ( !isset( $accessible ) ) return; 
  124.  
  125. switch( $accessible ) { 
  126.  
  127. case 0: 
  128. $ultimatemember->access->allow_access = true; 
  129. $ultimatemember->access->redirect_handler = false; // open to everyone 
  130.  
  131. break; 
  132.  
  133. case 1: 
  134.  
  135. $redirect_to = esc_url( $access_redirect2 ); 
  136.  
  137. if ( is_user_logged_in() ) { 
  138. $ultimatemember->access->allow_access = false; 
  139.  
  140. if ( ! is_user_logged_in() ) { 
  141. $ultimatemember->access->allow_access = true; 
  142.  
  143. if( ! empty( $redirect_to ) ) { 
  144. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "post_1a" ); 
  145. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  146. }else{ 
  147. if ( ! is_user_logged_in() ) { 
  148. $redirect_to = um_get_core_page("login"); 
  149. }else{ 
  150. $redirect_to = um_get_core_page("user"); 
  151.  
  152. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "post_1b" ); 
  153. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  154.  
  155.  
  156. break; 
  157.  
  158. case 2: 
  159.  
  160. if ( ! is_user_logged_in() ) { 
  161.  
  162. if ( empty( $access_redirect ) ) { 
  163. $access_redirect = um_get_core_page('login'); 
  164.  
  165. $access_redirect = $ultimatemember->access->set_referer( $access_redirect, "post_2a" ); 
  166.  
  167. $redirect_to = esc_url( $access_redirect ); 
  168.  
  169. if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ) { 
  170. $access_roles = unserialize( $access_roles ); 
  171. $access_roles = array_filter($access_roles); 
  172.  
  173. if ( !empty( $access_roles ) && !in_array(um_user'role'), $access_roles ) ) { 
  174. if ( !$access_redirect ) { 
  175. if ( is_user_logged_in() ) { 
  176. $access_redirect = esc_url( site_url() ); 
  177. } else { 
  178. $access_redirect = esc_url( um_get_core_page('login') ); 
  179. $access_redirect = $ultimatemember->access->set_referer( $access_redirect, "post_2b" ); 
  180. $redirect_to = esc_url( $access_redirect ); 
  181.  
  182. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  183.  
  184. break; 
  185.  
  186.  
  187. if( um_is_core_page('user') && ! is_user_logged_in() && ! empty( $access_redirect ) && isset( $args['custom_access_settings'] ) && $args['custom_access_settings'] != 0 ) { 
  188. $ultimatemember->access->allow_access = false; 
  189. $access_redirect = $ultimatemember->access->set_referer( $access_redirect, "user_page" ); 
  190. $ultimatemember->access->redirect_handler = esc_url( $access_redirect ); 
  191. wp_redirect( $ultimatemember->access->redirect_handler ); 
  192. exit; 
  193.