/core/um-actions-access.php

  1. <?php 
  2.  
  3.  
  4. /*** 
  5. *** @Global Access Settings 
  6. ***/ 
  7. add_action('um_access_global_settings', 'um_access_global_settings'); 
  8. function um_access_global_settings() { 
  9. global $post, $ultimatemember; 
  10.  
  11. $access = um_get_option('accessible'); 
  12.  
  13. if ( $access == 2 && ! is_user_logged_in() ) { 
  14.  
  15. $redirect = um_get_option('access_redirect'); 
  16. if ( !$redirect ) { 
  17. $redirect = um_get_core_page('login'); 
  18.  
  19. $redirects[] = untrailingslashit( um_get_core_page('login') ); 
  20. $redirects[] = untrailingslashit( um_get_option('access_redirect') ); 
  21.  
  22. $exclude_uris = um_get_option('access_exclude_uris'); 
  23.  
  24. if ( $exclude_uris ) { 
  25. $redirects = array_merge( $redirects, $exclude_uris ); 
  26.  
  27. $redirects = array_unique( $redirects ); 
  28.  
  29. $current_url = $ultimatemember->permalinks->get_current_url( get_option('permalink_structure') ); 
  30. $current_url = untrailingslashit( $current_url ); 
  31. $current_url_slash = trailingslashit( $current_url ); 
  32.  
  33. if ( ( isset( $post->ID ) ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) { 
  34. // allow 
  35. }else { 
  36. $ultimatemember->access->redirect_handler = $ultimatemember->access->set_referer( $redirect, "global" ); 
  37.  
  38. // Disallow access in homepage 
  39. if( is_front_page() || is_home() ) { 
  40. $home_page_accessible = um_get_option("home_page_accessible"); 
  41. if( $home_page_accessible == 0 ) { 
  42. $ultimatemember->access->redirect_handler = $ultimatemember->access->set_referer( $redirect, "global" ); 
  43.  
  44. wp_redirect( $ultimatemember->access->redirect_handler ); exit; 
  45.  
  46.  
  47. // Disallow access in category pages 
  48. if( is_category() ) { 
  49. $category_page_accessible = um_get_option("category_page_accessible"); 
  50. if( $category_page_accessible == 0 ) { 
  51. $ultimatemember->access->redirect_handler = $ultimatemember->access->set_referer( $redirect, "global" ); 
  52. wp_redirect( $ultimatemember->access->redirect_handler ); exit; 
  53.  
  54.  
  55. $current_page_type = um_get_current_page_type(); 
  56.  
  57. do_action("um_access_post_type", $current_page_type); 
  58. do_action("um_access_post_type_{$current_page_type}"); 
  59.  
  60.  
  61.  
  62. /*** 
  63. *** @Custom User homepage redirection 
  64. ***/ 
  65. add_action("um_access_user_custom_homepage", "um_access_user_custom_homepage"); 
  66. function um_access_user_custom_homepage() { 
  67. global $ultimatemember; 
  68.  
  69. if( ! is_user_logged_in() ) return; 
  70. if( ! is_front_page() ) return; 
  71.  
  72. $role_meta = $ultimatemember->query->role_data( um_user('role') ); 
  73.  
  74. if( isset( $role_meta['default_homepage'] ) && $role_meta['default_homepage'] == 0 ) { 
  75. $redirect_to = null; 
  76.  
  77. if( ! empty( $role_meta['redirect_homepage'] ) ) { 
  78. $redirect_to = $role_meta['redirect_homepage']; 
  79. }else{ 
  80. $redirect_to = um_get_core_page('user'); 
  81.  
  82. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "custom_homepage" ); 
  83. wp_redirect( $redirect_to ); exit; 
  84.  
  85.  
  86.  
  87.  
  88. /*** 
  89. *** @Front page access settings 
  90. ***/ 
  91. add_action('um_access_frontpage_per_role', 'um_access_frontpage_per_role'); 
  92. function um_access_frontpage_per_role() { 
  93. global $ultimatemember, $post; 
  94.  
  95. if ( is_admin() ) return; 
  96. if ( ! is_front_page() ) return; 
  97. if( is_404() ) return; 
  98.  
  99. if ( ! isset( $um_post_id ) && isset( $post->ID ) ) { 
  100. $um_post_id = $post->ID; 
  101.  
  102. if( ! isset( $um_post_id ) ) { 
  103. return; 
  104.  
  105. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  106. extract( $args ); 
  107.  
  108. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  109.  
  110. $um_post_id = apply_filters('um_access_control_for_parent_posts', $um_post_id ); 
  111.  
  112. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  113. extract( $args ); 
  114.  
  115. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  116. return; 
  117.  
  118.  
  119. $redirect_to = null; 
  120.  
  121. if ( !isset( $accessible ) ) return; 
  122.  
  123. switch( $accessible ) { 
  124.  
  125. case 0: 
  126. $ultimatemember->access->allow_access = true; 
  127. $ultimatemember->access->redirect_handler = false; // open to everyone 
  128.  
  129. break; 
  130.  
  131. case 1: 
  132.  
  133. $redirect_to = $access_redirect2; 
  134.  
  135. if ( is_user_logged_in() ) { 
  136. $ultimatemember->access->allow_access = false; 
  137.  
  138. if ( ! is_user_logged_in() ) { 
  139. $ultimatemember->access->allow_access = true; 
  140.  
  141. if( ! empty( $redirect_to ) ) { 
  142. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_1a" ); 
  143. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  144. }else{ 
  145. if ( ! is_user_logged_in() ) { 
  146. $redirect_to = um_get_core_page("login"); 
  147. }else{ 
  148. $redirect_to = um_get_core_page("user"); 
  149.  
  150. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_1b" ); 
  151. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  152.  
  153.  
  154. break; 
  155.  
  156. case 2: 
  157.  
  158. if ( ! is_user_logged_in() ) { 
  159.  
  160. if ( empty( $access_redirect ) ) { 
  161. $access_redirect = um_get_core_page('login'); 
  162.  
  163. $redirect_to = $access_redirect; 
  164. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_2a" ); 
  165.  
  166.  
  167. if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ) { 
  168. $access_roles = unserialize( $access_roles ); 
  169. $access_roles = array_filter($access_roles); 
  170.  
  171. if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) { 
  172. if ( empty( $access_redirect ) ) { 
  173. if ( is_user_logged_in() ) { 
  174. $access_redirect = site_url(); 
  175. } else { 
  176. $access_redirect = um_get_core_page('login'); 
  177. $redirect_to = esc_url( $access_redirect ); 
  178. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "frontpage_per_role_2b" ); 
  179.  
  180.  
  181.  
  182. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  183.  
  184. break; 
  185.  
  186.  
  187.  
  188. /*** 
  189. *** @Posts page access settings 
  190. ***/ 
  191. add_action('um_access_homepage_per_role', 'um_access_homepage_per_role'); 
  192. function um_access_homepage_per_role() { 
  193. global $ultimatemember, $post; 
  194.  
  195. if ( is_admin() ) return; 
  196. if ( ! is_home() ) return; 
  197. if ( is_404() ) return; 
  198.  
  199. $access = um_get_option('accessible'); 
  200.  
  201. $show_on_front = get_option( 'show_on_front' ); 
  202.  
  203. if( $show_on_front == "page" ) { 
  204.  
  205. $um_post_id = get_option( 'page_for_posts' ); 
  206.  
  207. if ( $access == 2 && ! is_user_logged_in() ) { 
  208. $ultimatemember->access->allow_access = false; 
  209. }else{ 
  210. $ultimatemember->access->allow_access = true; 
  211.  
  212. }else if( $show_on_front == "posts" ) { 
  213. $ultimatemember->access->allow_access = true; 
  214.  
  215.  
  216.  
  217. if ( isset( $um_post_id ) ) { 
  218.  
  219. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  220. extract( $args ); 
  221.  
  222. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  223.  
  224. $um_post_id = apply_filters('um_access_control_for_parent_posts', $um_post_id ); 
  225.  
  226. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  227. extract( $args ); 
  228.  
  229. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  230. return; 
  231.  
  232.  
  233. $redirect_to = null; 
  234.  
  235. if ( !isset( $accessible ) ) return; 
  236.  
  237. switch( $accessible ) { 
  238.  
  239. case 0: 
  240. $ultimatemember->access->allow_access = true; 
  241. $ultimatemember->access->redirect_handler = false; // open to everyone 
  242.  
  243. break; 
  244.  
  245. case 1: 
  246.  
  247. $redirect_to = esc_url( $access_redirect2 ); 
  248.  
  249. if ( is_user_logged_in() ) { 
  250. $ultimatemember->access->allow_access = false; 
  251.  
  252. if ( ! is_user_logged_in() ) { 
  253. $ultimatemember->access->allow_access = true; 
  254.  
  255. if( ! empty( $redirect_to ) ) { 
  256. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "homepage_per_role_1a" ); 
  257. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  258. }else{ 
  259. $redirect_to = null; 
  260. if ( ! is_user_logged_in() ) { 
  261. $redirect_to = um_get_core_page("login"); 
  262. }else{ 
  263. $redirect_to = um_get_core_page("user"); 
  264. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "homepage_per_role_1b" ); 
  265. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  266.  
  267.  
  268. break; 
  269.  
  270. case 2: 
  271.  
  272. if ( ! is_user_logged_in() ) { 
  273.  
  274. if ( empty( $access_redirect ) ) { 
  275. $access_redirect = um_get_core_page('login'); 
  276.  
  277. $redirect_to = $access_redirect; 
  278. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "homepage_per_role_2a" ); 
  279.  
  280. if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ) { 
  281. $access_roles = unserialize( $access_roles ); 
  282. $access_roles = array_filter($access_roles); 
  283.  
  284. if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) { 
  285. if ( !$access_redirect ) { 
  286. if ( is_user_logged_in() ) { 
  287. $access_redirect = site_url(); 
  288. } else { 
  289. $access_redirect = um_get_core_page('login'); 
  290.  
  291. $redirect_to = $access_redirect; 
  292. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "homepage_per_role_2b" ); 
  293.  
  294. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  295.  
  296. break; 
  297.  
  298.  
  299.  
  300. /*** 
  301. *** @Archieves/Taxonomies/Categories access settings 
  302. ***/ 
  303. add_action('um_access_category_settings', 'um_access_category_settings'); 
  304. function um_access_category_settings() { 
  305. global $post, $wp_query, $ultimatemember; 
  306.  
  307. if ( is_front_page() ||  
  308. is_home() ||  
  309. is_feed() ||  
  310. is_page() || 
  311. is_404()  
  312. ) { 
  313.  
  314. return; 
  315.  
  316.  
  317. $access = um_get_option('accessible'); 
  318. $current_page_type = um_get_current_page_type(); 
  319.  
  320.  
  321. if( is_category() && ! in_array( $current_page_type , array( 'day', 'month', 'year', 'author', 'archive' ) ) ) { 
  322.  
  323. $um_category = get_the_category();  
  324. $um_category = current( $um_category ); 
  325. $term_id = ''; 
  326.  
  327. if( isset( $um_category->term_id ) ) { 
  328. $term_id = $um_category->term_id; 
  329.  
  330. if( isset( $term_id ) && ! empty( $term_id ) ) { 
  331.  
  332. $opt = get_option("category_$term_id"); 
  333.  
  334. if ( isset( $opt['_um_accessible'] ) ) { 
  335.  
  336. $redirect = false; 
  337.  
  338. switch( $opt['_um_accessible'] ) { 
  339.  
  340. case 0: 
  341.  
  342. $ultimatemember->access->allow_access = true; 
  343. $ultimatemember->access->redirect_handler = ''; // open to everyone 
  344.  
  345. break; 
  346.  
  347. case 1: 
  348.  
  349. if ( is_user_logged_in() ) { 
  350.  
  351. if( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) { 
  352. $redirect = $opt['_um_redirect']; 
  353. }else{  
  354. $redirect = site_url(); 
  355.  
  356. $ultimatemember->access->allow_access = false; 
  357.  
  358. $redirect = $ultimatemember->access->set_referer( $redirect, "category_1" ); 
  359.  
  360. $ultimatemember->access->redirect_handler = esc_url( $redirect ); 
  361.  
  362. if ( ! is_user_logged_in() && ! empty( $redirect ) ) { 
  363. $ultimatemember->access->allow_access = true; 
  364.  
  365. break; 
  366.  
  367. case 2: 
  368.  
  369. if ( ! is_user_logged_in() ) { 
  370.  
  371. if( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) { 
  372. $redirect = $opt['_um_redirect']; 
  373. }else{ 
  374. $redirect = um_get_core_page('login'); 
  375.  
  376. $ultimatemember->access->allow_access = false; 
  377.  
  378. $redirect = $ultimatemember->access->set_referer( $redirect, "category_2a" ); 
  379.  
  380. $ultimatemember->access->redirect_handler = esc_url( $redirect ); 
  381.  
  382. if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ) { 
  383. if ( ! in_array( um_user('role'), $opt['_um_roles'] ) ) { 
  384.  
  385.  
  386. if( isset( $opt['_um_redirect'] ) ) { 
  387. $redirect = $opt['_um_redirect']; 
  388. $redirect = $ultimatemember->access->set_referer( $redirect, "category_2b" ); 
  389.  
  390. $ultimatemember->access->redirect_handler = esc_url( $redirect ); 
  391.  
  392.  
  393.  
  394. } else if ( $access == 2 && ! is_user_logged_in() && is_archive() ) { 
  395.  
  396. $ultimatemember->access->allow_access = false; 
  397. $redirect = um_get_core_page('login'); 
  398. $redirect = $ultimatemember->access->set_referer( $redirect, "category_archive" ); 
  399.  
  400. $ultimatemember->access->redirect_handler = $redirect; 
  401.  
  402. } else if ( is_tax() && get_post_taxonomies( $post ) ) { 
  403.  
  404. $taxonomies = get_post_taxonomies( $post ); 
  405. $categories_ids = array(); 
  406.  
  407. foreach ($taxonomies as $key => $value) { 
  408. $term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids")); 
  409. foreach( $term_list as $term_id ) { 
  410. array_push( $categories_ids , $term_id); 
  411.  
  412. foreach( $categories_ids as $term => $term_id ) { 
  413.  
  414. $opt = get_option("category_$term_id"); 
  415.  
  416. if ( isset( $opt['_um_accessible'] ) ) { 
  417. switch( $opt['_um_accessible'] ) { 
  418.  
  419. case 0: 
  420. $ultimatemember->access->allow_access = true; 
  421. $ultimatemember->access->redirect_handler = false; // open to everyone 
  422. break; 
  423.  
  424. case 1: 
  425.  
  426. if ( is_user_logged_in() ) 
  427. $redirect = ( isset( $opt['_um_redirect'] ) && !empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  428. $redirect = $ultimatemember->access->set_referer( $redirect, "categories_1" ); 
  429. $ultimatemember->access->redirect_handler = $redirect; 
  430. if ( !is_user_logged_in() ) 
  431. $ultimatemember->access->allow_access = true; 
  432.  
  433. break; 
  434.  
  435. case 2: 
  436.  
  437. if ( ! is_user_logged_in() ) { 
  438.  
  439. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : um_get_core_page('login'); 
  440. $redirect = $ultimatemember->access->set_referer( $redirect, "categories_2a" ); 
  441.  
  442. $ultimatemember->access->redirect_handler = $redirect; 
  443.  
  444. if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ) { 
  445. if ( !in_array( um_user('role'), $opt['_um_roles'] ) ) { 
  446. $redirect = null; 
  447. if ( is_user_logged_in() ) { 
  448. $redirect = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  449.  
  450. if ( !is_user_logged_in() ) { 
  451. $redirect = um_get_core_page('login'); 
  452.  
  453. $redirect = $ultimatemember->access->set_referer( $redirect, "categories_2b" ); 
  454. $ultimatemember->access->redirect_handler = $redirect; 
  455.  
  456.  
  457.  
  458.  
  459. /*** 
  460. *** @Posts/Page access settings 
  461. ***/ 
  462. add_action('um_access_post_settings', 'um_access_post_settings'); 
  463. function um_access_post_settings() { 
  464. global $post, $ultimatemember; 
  465.  
  466. // woo commerce shop ID 
  467. if( function_exists('is_shop') && is_shop() ) { 
  468.  
  469. $um_post_id = get_option('woocommerce_shop_page_id'); 
  470.  
  471. } else if (  
  472. is_category() ||  
  473. is_archive() ||  
  474. is_search() ||  
  475. in_the_loop() ||  
  476. is_feed() ||  
  477. is_tax() || 
  478. ! get_post_type() || 
  479. ! isset( $post->ID ) || 
  480. is_home() || 
  481. is_front_page() || 
  482. is_404()  
  483. ) { 
  484.  
  485. return; 
  486.  
  487. }  
  488.  
  489. if ( !isset( $um_post_id ) ) { 
  490. $um_post_id = $post->ID; 
  491.  
  492. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  493.  
  494.  
  495. extract( $args ); 
  496.  
  497. // Check for parent page's custom access settings 
  498. if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { 
  499.  
  500. $um_post_id = apply_filters('um_access_control_for_parent_posts', $um_post_id ); 
  501.  
  502. $args = $ultimatemember->access->get_meta( $um_post_id ); 
  503. extract( $args ); 
  504.  
  505.  
  506. if( isset( $post->ID ) ) { 
  507. $post_type = get_post_type( $post->ID ); 
  508.  
  509. // post's category restriction 
  510. if ( $post_type != 'page' && isset( $args['custom_access_settings'] ) && $args['custom_access_settings'] == 0 ) { 
  511.  
  512. $categories = get_the_category( $post->ID ); 
  513. foreach( $categories as $cat ) { 
  514.  
  515. $opt = get_option("category_{$cat->term_id}"); 
  516.  
  517. if ( isset( $opt['_um_accessible'] ) ) { 
  518. switch( $opt['_um_accessible'] ) { 
  519.  
  520. case 0: // Open to everyone 
  521. $ultimatemember->access->allow_access = true; 
  522. $ultimatemember->access->redirect_handler = false; // open to everyone 
  523. break; 
  524.  
  525. case 1: // Logged out users only 
  526.  
  527. if ( is_user_logged_in() ) { 
  528. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  529. $redirect = $ultimatemember->access->set_referer( $redirect, "page_cat_1a_t{$cat->term_id}_pt{$post_type}" ); 
  530. $ultimatemember->access->redirect_handler = $redirect; 
  531. $ultimatemember->access->allow_access = false; 
  532.  
  533. if ( !is_user_logged_in() ) { 
  534. $ultimatemember->access->allow_access = true; 
  535.  
  536. break; 
  537.  
  538. case 2: // Logged in users only 
  539.  
  540. if ( ! is_user_logged_in() ) { 
  541.  
  542. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : um_get_core_page('login'); 
  543.  
  544. $redirect = $ultimatemember->access->set_referer( $redirect, "page_cat_2a_t{$cat->term_id}_pt{$post_type}" ); 
  545. $ultimatemember->access->redirect_handler = $redirect; 
  546.  
  547. $ultimatemember->access->allow_access = false; 
  548.  
  549. if ( is_user_logged_in() ) { 
  550.  
  551. if( isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ) { 
  552.  
  553. if ( in_array( um_user('role'), $opt['_um_roles'] ) ) { 
  554.  
  555. $ultimatemember->access->allow_access = true; 
  556.  
  557. }else{ 
  558.  
  559. $redirect = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); 
  560. $redirect = $ultimatemember->access->set_referer( $redirect, "page_cat_2b_t{$cat->term_id}_pt{$post_type}" ); 
  561. $ultimatemember->access->redirect_handler = $redirect; 
  562.  
  563. $ultimatemember->access->allow_access = false; 
  564.  
  565.  
  566. }else{ // if allowed all roles 
  567. $ultimatemember->access->allow_access = true; 
  568.  
  569.  
  570.  
  571.  
  572. } // end if isset( $opt['_um_accessible'] ) 
  573.  
  574. // if one of the categories has enabled restriction, apply its settings to the current post 
  575. if( $ultimatemember->access->allow_access == false ) { 
  576. return; 
  577.  
  578. } // end foreach 
  579.  
  580. // post restriction 
  581. if ( isset( $args['custom_access_settings'] ) && $args['custom_access_settings'] == 1 ) { 
  582.  
  583. $redirect_to = null; 
  584.  
  585. if ( !isset( $accessible ) ) return; 
  586.  
  587. switch( $accessible ) { 
  588.  
  589. case 0: 
  590. $ultimatemember->access->allow_access = true; 
  591. $ultimatemember->access->redirect_handler = false; // open to everyone 
  592.  
  593. break; 
  594.  
  595. case 1: 
  596.  
  597. $redirect_to = esc_url( $access_redirect2 ); 
  598.  
  599. if ( is_user_logged_in() ) { 
  600. $ultimatemember->access->allow_access = false; 
  601.  
  602. if ( ! is_user_logged_in() ) { 
  603. $ultimatemember->access->allow_access = true; 
  604.  
  605. if( ! empty( $redirect_to ) ) { 
  606. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "post_1a" ); 
  607. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  608. }else{ 
  609. if ( ! is_user_logged_in() ) { 
  610. $redirect_to = um_get_core_page("login"); 
  611. }else{ 
  612. $redirect_to = um_get_core_page("user"); 
  613.  
  614. $redirect_to = $ultimatemember->access->set_referer( $redirect_to, "post_1b" ); 
  615. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  616.  
  617.  
  618. break; 
  619.  
  620. case 2: 
  621.  
  622. if ( ! is_user_logged_in() ) { 
  623.  
  624. if ( empty( $access_redirect ) ) { 
  625. $access_redirect = um_get_core_page('login'); 
  626.  
  627. $access_redirect = $ultimatemember->access->set_referer( $access_redirect, "post_2a" ); 
  628.  
  629. $redirect_to = esc_url( $access_redirect ); 
  630.  
  631. if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ) { 
  632. $access_roles = unserialize( $access_roles ); 
  633. $access_roles = array_filter($access_roles); 
  634.  
  635. if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) { 
  636. if ( !$access_redirect ) { 
  637. if ( is_user_logged_in() ) { 
  638. $access_redirect = esc_url( site_url() ); 
  639. } else { 
  640. $access_redirect = esc_url( um_get_core_page('login') ); 
  641. $access_redirect = $ultimatemember->access->set_referer( $access_redirect, "post_2b" ); 
  642. $redirect_to = esc_url( $access_redirect ); 
  643.  
  644. $ultimatemember->access->redirect_handler = esc_url( $redirect_to ); 
  645.  
  646. break; 
  647.  
  648.  
  649. if( um_is_core_page('user') && ! is_user_logged_in() && ! empty( $access_redirect ) && isset( $args['custom_access_settings'] ) && $args['custom_access_settings'] != 0 ) { 
  650. $ultimatemember->access->allow_access = false; 
  651. $access_redirect = $ultimatemember->access->set_referer( $access_redirect, "user_page" ); 
  652. $ultimatemember->access->redirect_handler = esc_url( $access_redirect ); 
  653. wp_redirect( $ultimatemember->access->redirect_handler ); 
  654. exit; 
  655.  
  656.  
  657. /*** 
  658. *** @Profile Access 
  659. ***/ 
  660. add_action('um_access_profile', 'um_access_profile'); 
  661. function um_access_profile( $user_id ) { 
  662.  
  663. if( ! um_is_myprofile() && um_is_core_page('user') && ! current_user_can('edit_users') ) { 
  664.  
  665. um_fetch_user( $user_id ); 
  666.  
  667. if( ! in_array( um_user('account_status'), array('approved') ) ) { 
  668. um_redirect_home(); 
  669.  
  670. um_reset_user(); 
  671.  
  672.  
.