Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
messica committed Jun 29, 2019
2 parents 0fa8e33 + 31cdbb0 commit c1cfc97
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 109 deletions.
8 changes: 1 addition & 7 deletions includes/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@ 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 );

// 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'];
Expand Down
199 changes: 102 additions & 97 deletions includes/directory.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,102 @@
<?php
/*
Code to edit the BuddyPress members directory and search.
*/

function pmpro_bp_directory_init() {
// Don't do this if PMPro is deactivated
if( !defined( 'PMPRO_VERSION' ) ) {
return;
}

global $pmpro_bp_members_in_directory;
$pmpro_bp_members_in_directory = pmpro_bp_get_members_in_directory();
add_action( 'bp_pre_user_query_construct', 'pmpro_bp_bp_pre_user_query_construct', 1, 1 );
add_filter( 'bp_get_total_member_count', 'pmpro_bp_bp_get_total_member_count' );
}
add_action('init', 'pmpro_bp_directory_init', 20);

function pmpro_bp_bp_pre_user_query_construct( $query_array ) {
// If no setting is locking the member directory, let's bail.
if( !pmpro_bp_is_member_directory_locked() ) {
return;
}

// Only apply this to the directory.
if ( 'members' != bp_current_component() ) {
return;
}

global $pmpro_bp_members_in_directory;
if( !empty( $pmpro_bp_members_in_directory ) ) {
// If an include value was already set, make sure it's in array form.
if( !empty( $query_array->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;
}
}
<?php
/*
Code to edit the BuddyPress members directory and search.
*/

function pmpro_bp_directory_init() {
// Don't do this if PMPro is deactivated
if( !defined( 'PMPRO_VERSION' ) ) {
return;
}

global $pmpro_bp_members_in_directory;
$pmpro_bp_members_in_directory = pmpro_bp_get_members_in_directory();
add_action( 'bp_pre_user_query_construct', 'pmpro_bp_bp_pre_user_query_construct', 1, 1 );
add_filter( 'bp_get_total_member_count', 'pmpro_bp_bp_get_total_member_count' );
}
add_action('init', 'pmpro_bp_directory_init', 20);

function pmpro_bp_bp_pre_user_query_construct( $query_array ) {
// If no setting is locking the member directory, let's bail.
if( !pmpro_bp_is_member_directory_locked() ) {
return;
}

// Only apply this to the directory.
if ( 'members' != bp_current_component() ) {
return;
}

global $pmpro_bp_members_in_directory;
if( !empty( $pmpro_bp_members_in_directory ) ) {
// If an include value was already set, make sure it's in array form.
if( !empty( $query_array->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;
}
}
38 changes: 37 additions & 1 deletion includes/profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
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' );
2 changes: 1 addition & 1 deletion includes/restrictions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pmpro-buddypress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c1cfc97

Please sign in to comment.