function buatp_update_option_on_delete_fields($field) { $settings = get_option('buatp_basic_setting', false); $field_name = $settings['buatp_type_field_selection']; $settings_profile_data = get_option('buatp_profile_data_setting', false); $types = buatp_get_all_types(buatp_get_field_id_by_name($field_name)); $field_id = (int) $field->id; $field_name = $field->name; foreach ((array) $types as $type) { if (in_array($field_name, (array) $settings_profile_data['buatp_exclude_fields_for_' . $type['id']])) { unset($settings_profile_data['buatp_exclude_fields_for_' . $type['id']][$field_name]); } if (in_array($field_name, (array) $settings_profile_data['buatp_include_fields_at_registration_for_' . $type['id']])) { unset($settings_profile_data['buatp_include_fields_at_registration_for_' . $type['id']][$field_name]); } } update_option('buatp_profile_data_setting', $settings_profile_data); }
function buatp_page_restriction() { global $bp; $page_id = get_the_ID(); $current_url = buatp_prepare_url('current'); if (!$page_id) { return; } $access = get_option('buatp_access_setting', true); $current_basic_setting = get_option('buatp_basic_setting', true); $field_name = $current_basic_setting['buatp_type_field_selection']; $field_id = buatp_get_field_id_by_name($field_name); $type_names = buatp_get_all_types($field_id); if (!$field_name) { return; } if (!isset($access['buatp_restrict_redirect_general']) || $access['buatp_restrict_redirect_general'] == false) { return; } foreach ((array) $type_names as $val) { $user_type = $val['id']; $restricted_pages = isset($access['buatp_restrict_page_for_' . $user_type]) ? $access['buatp_restrict_page_for_' . $user_type] : ''; $pages = explode(',', trim($restricted_pages)); $url = preg_split('/[\\r\\n]+/', buatp_prepare_url(trim($restricted_pages)), -1, PREG_SPLIT_NO_EMPTY); $urls = array_merge((array) $urls, (array) $url); $all_restricted_pages = array_merge((array) $all_restricted_pages, (array) $pages, (array) $urls); if (isset($access['buatp_restrict_page_for_' . $val['id']]) || count($urls)) { $resricted = true; } } if ($current_url && in_array($current_url, $all_restricted_pages)) { $url_redirect = true; } if (!in_array($page_id, $all_restricted_pages) && !$url_redirect) { return; } if (!is_user_logged_in() && $resricted) { wp_redirect(get_permalink($access['buatp_restrict_redirect_general']), 302); return; } $do_redirect = false; $user_id = $bp->loggedin_user->id; $current_user_type = buatp_get_field_id_by_name(buatp_get_field_data($field_name, $user_id)); if (current_user_can('create_users') || is_super_admin($user_id)) { return; } foreach ((array) $type_names as $val) { $user_type = $val['id']; $restricted_pages = isset($access['buatp_restrict_page_for_' . $user_type]) ? $access['buatp_restrict_page_for_' . $user_type] : ''; $page_arr = explode(',', trim($restricted_pages)); $url = (array) preg_split('/[\\r\\n]+/', buatp_prepare_url(trim($restricted_pages)), -1, PREG_SPLIT_NO_EMPTY); if (in_array($current_url, $url) && $user_type == $current_user_type) { $do_redirect = true; $redirect_to = isset($access['buatp_restrict_redirect_for_' . $user_type]) ? $access['buatp_restrict_redirect_for_' . $user_type] : false; break; } if (in_array($page_id, $page_arr) && $user_type == $current_user_type) { $do_redirect = true; $redirect_to = isset($access['buatp_restrict_redirect_for_' . $user_type]) ? $access['buatp_restrict_redirect_for_' . $user_type] : false; break; } } if ($do_redirect) { bp_core_redirect(get_permalink($redirect_to), 302); } return; }
function buatp_set_all_type_info() { $this->all_type_info = buatp_get_all_types(buatp_get_field_id_by_name($this->buatp_type_field)); $this->buatp_type_field_id = buatp_get_field_id_by_name($this->buatp_type_field); }