diff --git a/includes/common.php b/includes/common.php index 3c9fdc3..7108458 100644 --- a/includes/common.php +++ b/includes/common.php @@ -27,15 +27,8 @@ function pmpro_bp_get_level_options( $level_id ) { // defaults $options = $default_options; } elseif ( $level_id == 0 ) { - // non-member users $options = get_option( 'pmpro_bp_options_users', $default_options ); - - // Non-members might be locked down. - if ( PMPROBP_LOCK_ALL_ACCESS == $options['pmpro_bp_restrictions'] ) { - $options = $default_options; - } - } else { // level options $options = get_option( 'pmpro_bp_options_' . $level_id, $default_options ); @@ -43,6 +36,7 @@ function pmpro_bp_get_level_options( $level_id ) { // might be set to mirror non-member users if ( $options['pmpro_bp_restrictions'] == PMPROBP_USE_NON_MEMBER_SETTINGS ) { $non_member_user_options = pmpro_bp_get_level_options( 0 ); + $options['pmpro_bp_restrictions'] = $non_member_user_options['pmpro_bp_restrictions']; $options['pmpro_bp_group_creation'] = $non_member_user_options['pmpro_bp_group_creation']; $options['pmpro_bp_group_single_viewing'] = $non_member_user_options['pmpro_bp_group_single_viewing']; $options['pmpro_bp_groups_page_viewing'] = $non_member_user_options['pmpro_bp_groups_page_viewing']; diff --git a/includes/directory.php b/includes/directory.php index 2ba90ce..3ca17f7 100644 --- a/includes/directory.php +++ b/includes/directory.php @@ -1,97 +1,102 @@ -query_vars['include'] ) && !is_array( $query_array->query_vars['include']) ) { - $query_array->query_vars['include'] = explode( ',', $query_array->query_vars['include'] ); - } - - if( is_array( $query_array->query_vars['include'] ) ) { - // Compute the intersect of members and include value. - $query_array->query_vars['include'] = array_intersect( $query_array->query_vars['include'], $pmpro_bp_members_in_directory ); - } else { - // Only include members in the directory. - $query_array->query_vars['include'] = $pmpro_bp_members_in_directory; - } - } else { - // No members, block the directory. - $query_array->query_vars['include'] = array(0); - } -} - -function pmpro_bp_bp_get_total_member_count($count) { - global $pmpro_bp_members_in_directory; - - $count = count($pmpro_bp_members_in_directory); - return $count; -} - -function pmpro_bp_get_members_in_directory() { - global $wpdb, $pmpro_levels; - - if( !function_exists( 'pmpro_getAllLevels' ) ) { - return array(); - } - - $pmpro_levels = pmpro_getAllLevels(true, true); - - if ( empty( $pmpro_levels ) ) { - return array(); - } - - //see if we should include them in the member directory. - $include_levels = array(); - - foreach($pmpro_levels as $level) { - $pmpro_bp_options = pmpro_bp_get_level_options( $level->id ); - - if( $pmpro_bp_options['pmpro_bp_member_directory'] == 1 || $pmpro_bp_options['pmpro_bp_restrictions'] == PMPROBP_GIVE_ALL_ACCESS) { - $include_levels[] = $level->id; - } - } - - $sql = "SELECT DISTINCT user_id FROM $wpdb->pmpro_memberships_users WHERE membership_id IN (" . implode(",", array_map("intval", $include_levels)) . ") AND status = 'active'"; - - $wpdb->flush(); - $include_users = $wpdb->get_col($sql); - - return $include_users; -} - -function pmpro_bp_is_member_directory_locked() { - $non_user_options = pmpro_bp_get_level_options( 0 ); - - if( !$non_user_options['pmpro_bp_member_directory'] ) { - return true; - } else { - return false; - } -} +query_vars['include'] ) && !is_array( $query_array->query_vars['include']) ) { + $query_array->query_vars['include'] = explode( ',', $query_array->query_vars['include'] ); + } + + if( is_array( $query_array->query_vars['include'] ) ) { + // Compute the intersect of members and include value. + $query_array->query_vars['include'] = array_intersect( $query_array->query_vars['include'], $pmpro_bp_members_in_directory ); + } else { + // Only include members in the directory. + $query_array->query_vars['include'] = $pmpro_bp_members_in_directory; + } + } else { + // No members, block the directory. + $query_array->query_vars['include'] = array(0); + } +} + +function pmpro_bp_bp_get_total_member_count($count) { + global $pmpro_bp_members_in_directory; + + $count = count($pmpro_bp_members_in_directory); + return $count; +} + +function pmpro_bp_get_members_in_directory() { + global $wpdb, $pmpro_levels; + + if( !function_exists( 'pmpro_getAllLevels' ) ) { + return array(); + } + + $pmpro_levels = pmpro_getAllLevels(true, true); + + if ( empty( $pmpro_levels ) ) { + return array(); + } + + //see if we should include them in the member directory. + $include_levels = array(); + + foreach($pmpro_levels as $level) { + $pmpro_bp_options = pmpro_bp_get_level_options( $level->id ); + + if( $pmpro_bp_options['pmpro_bp_member_directory'] == 1 || $pmpro_bp_options['pmpro_bp_restrictions'] == PMPROBP_GIVE_ALL_ACCESS) { + $include_levels[] = $level->id; + } + } + + if ( empty( $include_levels ) ) { + return array(); + } + + $sql = "SELECT DISTINCT user_id FROM $wpdb->pmpro_memberships_users WHERE membership_id IN (" . implode(",", array_map("intval", $include_levels)) . ") AND status = 'active'"; + + $wpdb->flush(); + $include_users = $wpdb->get_col($sql); + + return $include_users; +} + +function pmpro_bp_is_member_directory_locked() { + $non_user_options = pmpro_bp_get_level_options( 0 ); + + if( $non_user_options['pmpro_bp_restrictions'] != PMPROBP_GIVE_ALL_ACCESS + && ! $non_user_options['pmpro_bp_member_directory'] ) { + return true; + } else { + return false; + } +} diff --git a/includes/profiles.php b/includes/profiles.php index 654f2f0..32c1af9 100644 --- a/includes/profiles.php +++ b/includes/profiles.php @@ -65,4 +65,40 @@ function pmpro_bp_xprofile_updated_profile( $user_id, $posted_field_ids, $errors } } } -add_action( 'xprofile_updated_profile', 'pmpro_bp_xprofile_updated_profile', 1, 5 ); \ No newline at end of file +add_action( 'xprofile_updated_profile', 'pmpro_bp_xprofile_updated_profile', 1, 5 ); + +/** + * Filter edit profile link based on user's BuddyPress access. + * + * @since 1.2.4 + */ +function pmpro_bp_init_edit_profile_url() { + + global $current_user; + + $user_options = pmpro_bp_get_user_options( $current_user->ID ); + + if ( PMPROBP_LOCK_ALL_ACCESS == $user_options['pmpro_bp_restrictions'] ) { + remove_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 ); + } +} +add_action( 'init', 'pmpro_bp_init_edit_profile_url' ); + +/** + * Remove "Extended Profile" tab based on user's BuddyPress access. + * + * @since 1.2.4 + */ +function pmpro_bp_profile_nav() { + + global $current_user, $bp; + + $user_options = pmpro_bp_get_user_options( $current_user->ID ); + + if ( PMPROBP_LOCK_ALL_ACCESS == $user_options['pmpro_bp_restrictions'] ) { + remove_action( 'edit_user_profile', array( $bp->members->admin, 'profile_nav' ), 99, 1 ); + remove_action( 'show_user_profile', array( $bp->members->admin, 'profile_nav' ), 99, 1 ); + } +} +add_action( 'edit_user_profile', 'pmpro_bp_profile_nav' ); +add_action( 'show_user_profile', 'pmpro_bp_profile_nav' ); diff --git a/includes/restrictions.php b/includes/restrictions.php index fd24472..5d1e1bb 100644 --- a/includes/restrictions.php +++ b/includes/restrictions.php @@ -195,7 +195,7 @@ function pmpro_bp_buddypress_or_pmpro_registration() { $pmpro_bp_register = get_option( 'pmpro_bp_registration_page' ); - if( !empty( $pmpro_bp_register ) && $pmpro_bp_register == 'buddypress' && ( $post->ID == $pmpro_pages['levels'] ) && !is_user_logged_in() ) { + if( !empty( $pmpro_bp_register ) && $pmpro_bp_register == 'buddypress' && $post->ID != 0 && $post->ID == $pmpro_pages['levels'] && !is_user_logged_in() ) { //Use BuddyPress Register page wp_redirect( get_permalink( $bp_pages['register'] ) ); exit; diff --git a/pmpro-buddypress.php b/pmpro-buddypress.php index 4c5deda..6bd1a1d 100755 --- a/pmpro-buddypress.php +++ b/pmpro-buddypress.php @@ -3,7 +3,7 @@ Plugin Name: Paid Memberships Pro - BuddyPress Add On Plugin URI: https://www.paidmembershipspro.com/add-ons/buddypress-integration Description: Manage access to your BuddyPress Community using Paid Memberships Pro. - Version: 1.2.3 + Version: 1.2.4 Author: Paid Memberships Pro Author URI: https://www.paidmembershipspro.com Text Domain: pmpro-buddypress diff --git a/readme.txt b/readme.txt index 72bc3ab..e178984 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: strangerstudios, great-h-master Tags: paid memberships pro, pmpro, buddypress Requires at least: 4 -Tested up to: 5.1.1 -Stable tag: 1.2.3 +Tested up to: 5.2.2 +Stable tag: 1.2.4 Manage access to your BuddyPress Community using Paid Memberships Pro @@ -99,6 +99,10 @@ This plugin also allows you to use the BuddyPress user registration process (in == Changelog == += 1.2.4 - 2019-06-28 = +* BUG FIX: Fixed issue where the WP profile was still being restricted from users without access to BP. +* BUG FIX: Fixed issue where the 'restrict all of BuddyPress' setting wasn't being applied correctly when levels were set to use non-member settings. + = 1.2.3 = * BUG FIX: Only getting members in directory if levels exist. * BUG FIX: Now locking down all of BuddyPress when a level's settings are set to use non-member settings and BuddyPress is locked down for non-members.