Search Results for 'Hide Admin'
-
Search Results
-
Hi, I’m using the below snippet from @danbp
// deny access to admins profile. User is redirected to the homepage function bpfr_hide_admins_profile() { global $bp; if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) : wp_redirect( home_url() ); exit; endif; } add_action( 'wp', 'bpfr_hide_admins_profile', 1 );When enabling WP_DEBUG, I get the following errors:
- Use of undefined constant bp_is_profile – assumed ‘bp_is_profile’ in …/fonctions.php in line 291
- Undefined property: stdClass::$id in …/fonctions.php in line 291
Although the redirect works fine, is there any way to resolve these 2 errors?
Topic: PMPRO and Buddypress
Has anyone been successful at blocking buddypress pages until PMPRO email confirmation is complete? I seem to be getting nowhere with PMPRO folks.
I am able to block /groups/, /members/, etc., but I cannot seem to block the sub-pages (e.g. /groups/group-name/). I took the PMPRO email confirmation code and modified it as follows. Any help is greatly appreciated!
<?php
/*
Plugin Name: Paid Memberships Pro – Email Confirmation Add On
Plugin URI: http://www.paidmembershipspro.com/addons/pmpro-email-confirmation/
Description: Require email confirmation before certain levels are enabled for members.
Version: .3
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
Sample use case: You have a free level but want people to use a real email address when signing up.
*//*
[Deprecated] Set this array to the include the levels which should require email confirmation.global $pmpro_email_confirmation_levels;
$pmpro_email_confirmation_levels = array(6);Use the checkbox on the edit levels page instead.
*//*
Add checkbox to edit level page to set if level requires email confirmation.
*/
//show the checkbox on the edit level page
function pmproec_pmpro_membership_level_after_other_settings()
{
$level_id = intval($_REQUEST[‘edit’]);
if($level_id > 0)
$email_confirmation = get_option(‘pmproec_email_confirmation_’ . $level_id);
else
$email_confirmation = false;
?>
<h3 class=”topborder”>Email Confirmation</h3>
<table>
<tbody class=”form-table”>
<tr>
<th scope=”row” valign=”top”><label for=”email_confirmation”><?php _e(‘Email Confirmation:’, ‘pmpro’);?></label></th>
<td>
<input type=”checkbox” id=”email_confirmation” name=”email_confirmation” value=”1″ <?php checked($email_confirmation, 1);?> />
<label for=”email_confirmation”><?php _e(‘Check this to require email validation for this level.’, ‘pmpro’);?></label>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action(‘pmpro_membership_level_after_other_settings’, ‘pmproec_pmpro_membership_level_after_other_settings’);//save email_confirmation setting when the level is saved/added
function pmproec_pmpro_save_membership_level($level_id)
{
if(isset($_REQUEST[’email_confirmation’]))
$email_confirmation = intval($_REQUEST[’email_confirmation’]);
else
$email_confirmation = 0;
delete_option(‘pmproec_email_confirmation_’ . $level_id);
add_option(‘pmproec_email_confirmation_’ . $level_id, $email_confirmation, ”, ‘no’);
}
add_action(“pmpro_save_membership_level”, “pmproec_pmpro_save_membership_level”);/*
Functions
*/
//Check if a level id requires an invite code or should generate one
function pmproec_isEmailConfirmationLevel($level_id)
{
global $pmpro_email_confirmation_levels;//get value from options
$email_confirmation = get_option(‘pmproec_email_confirmation_’ . $level_id, false);//check option and global var
return (!empty($email_confirmation) || !empty($pmpro_email_confirmation_levels) && in_array($level_id, $pmpro_email_confirmation_levels));
}//generate a key from a user id
function pmproec_getValidationKey($user_id)
{
$key = md5($user_id . AUTH_KEY . $user_id);
if(strlen($key) > 16)
$key = substr($key, 0, 16);return $key;
}/*
Save validation key in user meta after checkout.
*/
function pmproec_pmpro_after_checkout($user_id)
{
global $pmpro_level;if(pmproec_isEmailConfirmationLevel($pmpro_level->id))
{
//already validated?
$oldkey = get_user_meta($user_id, “pmpro_email_confirmation_key”, true);
if($oldkey != “validated”)
{
//nope? give them a key
$key = pmproec_getValidationKey($user_id);
update_user_meta($user_id, “pmpro_email_confirmation_key”, $key);
}
}
}
add_action(“pmpro_after_checkout”, “pmproec_pmpro_after_checkout”);/*
If a user hasn’t validated yet and needs it, don’t give them access.
*/
function pmproec_pmpro_has_membership_access_filter($hasaccess, $mypost, $myuser, $post_membership_levels)
{
//hide_buddy_press_pages()
$uri = $_SERVER[‘REQUEST_URI’];//lock some things for members only
$members_only = array(
“/members-2/”, “/activity/”, “/groups-2/”, “/forums/”, “/welcome-back/”
);
//if they don’t have access, ignore this
if(!$hasaccess)
return $hasaccess;//if this isn’t locked by level, ignore this
if(empty($post_membership_levels))
return $hasaccess;//does this user have a level that requires confirmation?
$user_membership_level = pmpro_getMembershipLevelForUser($myuser->ID);
if(pmproec_isEmailConfirmationLevel($user_membership_level->id))
{
//if they still have a validation key, they haven’t clicked on the validation link yet
$validation_key = get_user_meta($myuser->ID, “pmpro_email_confirmation_key”, true);if(!empty($validation_key) && $validation_key != “validated”)
{
$hasaccess = false;
foreach($members_only as $check)
{
//make sure they are a memberif(preg_match($check, $uri))
{
wp_redirect(“http://www.google.com”);
exit;
}
}
}
}
return $hasaccess;
}
add_filter(“pmpro_has_membership_access_filter”, “pmproec_pmpro_has_membership_access_filter”, 10, 4);/*
Add validation lik to confirmation email.
*/
function pmproec_pmpro_email_body($body, $email)
{
//must be a confirmation email and checkout template
if(!empty($email->data[‘membership_id’]) && pmproec_isEmailConfirmationLevel($email->data[‘membership_id’]) && strpos($email->template, “checkout”) !== false)
{
//get user
$user = get_user_by(“login”, $email->data[‘user_login’]);$validated = $user->pmpro_email_confirmation_key;
$url = home_url(“?ui=” . $user->ID . “&validate=” . $validated);//need validation?
if(empty($validated) || $validated != “validated”)
{
//use validation_link substitute?
if(false === stripos($body, “!!validation_link!!”))
{
$body = “<p>IMPORTANT! You must follow this link to confirm your email address before your membership is fully activated:<br />” . $url . “</p><hr />” . $body;
$body = str_replace(“Your membership account is now active.”, “”, $body);
} else
$body = str_ireplace(“!!validation_link!!”, $url, $body);
}
}return $body;
}
add_filter(“pmpro_email_body”, “pmproec_pmpro_email_body”, 10, 2);/*
Process validation links.
*/
function pmproec_init_validate()
{
if(!empty($_REQUEST[‘validate’]) && !empty($_REQUEST[‘ui’]))
{
$validate = $_REQUEST[‘validate’];
$ui = $_REQUEST[‘ui’];
$user = get_userdata($ui);
if($validate == $user->pmpro_email_confirmation_key)
{
//validate!
update_user_meta($user->ID, “pmpro_email_confirmation_key”, “validated”);do_action(‘pmproec_after_validate_user’, $user->ID, $validate);
if(is_user_logged_in())
wp_redirect(home_url());
else
wp_redirect(wp_login_url());exit;
}
}
}
add_action(“init”, “pmproec_init_validate”);/*
Update confirmation page to mention validation email if needed.
*/
function pmproec_pmpro_confirmation_message($message)
{
//must be an email confirmation level
if(!empty($_REQUEST[‘level’]) && pmproec_isEmailConfirmationLevel(intval($_REQUEST[‘level’])))
{
global $current_user;
if($current_user->pmpro_email_confirmation_key != “validated”)
{
$message = str_replace(“is now active”, “will be activated as soon as you confirm your email address. Important! You must click on the confirmation URL sent to ” . $current_user->user_email . ” before you gain full access to your membership“, $message);
}
}return $message;
}
add_filter(“pmpro_confirmation_message”, “pmproec_pmpro_confirmation_message”);/*
Function to add links to the plugin row meta
*/
function pmproec_plugin_row_meta($links, $file) {
if(strpos($file, ‘pmpro-email-confirmation.php’) !== false)
{
$new_links = array(
‘‘ . __( ‘Support’, ‘pmpro’ ) . ‘‘,
);
$links = array_merge($links, $new_links);
}
return $links;
}
add_filter(‘plugin_row_meta’, ‘pmproec_plugin_row_meta’, 10, 2);/**
* Add link to the user action links to validate a user
*
* Use the pmproec_validate_user_cap filter to change the capability required to see this.
*/
function pmproec_user_row_actions($actions, $user) {
$cap = apply_filters(‘pmproec_validate_user_cap’, ‘edit_users’);
if(current_user_can($cap))
{
//check if they still have a validation key
$validation_key = get_user_meta($user->ID, “pmpro_email_confirmation_key”, true);
if(!empty($validation_key) && $validation_key != “validated”)
{
$url = admin_url(“users.php?pmproecvalidate=” . $user->ID);
if(!empty($_REQUEST[‘s’]))
$url .= “&s=” . esc_attr($_REQUEST[‘s’]);
if(!empty($_REQUEST[‘paged’]))
$url .= “&paged=” . intval($_REQUEST[‘paged’]);
$url = wp_nonce_url($url, ‘pmproecvalidate_’ . $user->ID);
$actions[] = ‘Validate User‘;
}
else
$actions[] = ‘Validated’;
}return $actions;
}
add_filter(‘user_row_actions’, ‘pmproec_user_row_actions’, 10, 2);
add_filter(‘pmpro_memberslist_user_row_actions’, ‘pmproec_user_row_actions’, 10, 2);/**
* Manually validate a user. Runs on admin init. Checks for pmproecvalidate and nonce and validates that user.
*
*/
function pmproec_validate_user()
{
if(!empty($_REQUEST[‘pmproecvalidate’]))
{
global $pmproec_msg, $pmproec_msgt;//get user id
$user_id = intval($_REQUEST[‘pmproecvalidate’]);
$user = get_userdata($user_id);//no user?
if(empty($user))
{
//user not found error
$pmproec_msg = ‘Could not reset sessions. User not found.’;
$pmproec_msgt = ‘error’;
}
else
{
//check nonce
check_admin_referer( ‘pmproecvalidate_’.$user_id);//check caps
$cap = apply_filters(‘pmproec_validate_user_cap’, ‘edit_users’);
if(!current_user_can($cap))
{
//show error message
$pmproec_msg = ‘You do not have permission to validate users.’;
$pmproec_msgt = ‘error’;
}
else
{
//validate!
update_user_meta($user_id, “pmpro_email_confirmation_key”, “validated”);//show success message
$pmproec_msg = $user->user_email . ‘ has been validated.’;
$pmproec_msgt = ‘updated’;
}
}
}
}
add_action(‘admin_init’, ‘pmproec_validate_user’);/**
* Show any messages generated by PMPro Email Confirmations
*/
function pmproec_admin_notices()
{
global $pmproec_msg, $pmproec_msgt;
if(!empty($pmproec_msg))
echo “<div class=\”$pmproec_msgt\”><p>$pmproec_msg</p></div>”;
}
add_action(‘admin_notices’, ‘pmproec_admin_notices’);Googled around, an older examples won’t work with the current version of BuddyPress 2.4.3. How to make sure that the activities of the Administrator isn’t recorded or not shown, sitewide / plugins / etc….
Prefer to add this in: bp-custom.php
Thank yo in advance.
Code what i had found:
<?php // Don’t record activity by the site admins or show them as recently active function my_admin_stealth_mode(){ if ( is_site_admin() ) { global $bp; remove_action(‘wp_head’,’bp_core_record_activity’); delete_user_meta($bp->loggedin_user->id, ‘last_activity’); } ?>Here’s another code, this removes the activity of the currently logged in user itself from the page, this still works:
But obviously it wont hide the administrator’s activity in the users perspective!<?php //filter on pre_user_query add_action( 'pre_user_query', 'devb_exclude_loggedin_user', 201 ); function devb_exclude_loggedin_user( $query ) { //don't modify the query if the user is not logged in if ( !is_user_logged_in() ) return; //do not hide users inside the admin if ( is_admin() && !defined('DOING_AJAX') ) return; $qv = $query->query_vars; global $wpdb; //hide $query->query_where .= $wpdb->prepare(" AND {$wpdb->users}.ID !=%d ", get_current_user_id()); } ?>How do I hide my ‘Members’ page from all except Admin?
Hello,
I have 2 s2member levels, and quite a bit of groups for each level, it’s getting confusing for the admin when editing. I’d like to hide some of the groups from the admin in the EDIT section if the user is in a specific level.
I found this below and tweaked it for s2member, but alas it doesn’t work LOL, if anyone can help, would greatly appreciate it!!
// Hide profile group to admin based on Levels function bpfr_hide_profile_field_group( $retval ) { if( current_user_is(administrator) && current_user_can("access_s2member_level1") ) { // exlude groups, separated by comma $retval['exclude_groups'] = '6,5'; } return $retval; } add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );Hello,
I am trying to hide the groups and forums tabs from all users except admin and the logged in users own profile. The slugs i want to hide are
/members/betauser/forums/
/members/betauser/groups/I am writing the code as shown below to get this to work but it seems i am always using the logged in user to create the /members/xxx slug where as i may need the user that was clicked.. Any ideas on what i am doing wrong here?
add_action( 'bp_actions', 'RECN_CUSTOM_MEMBER_REMOVE_SUBNAV' ); function RECN_CUSTOM_MEMBER_REMOVE_SUBNAV() { bp_core_add_message(' ok i222n the mnethod','error'); if(is_super_admin() || bp_is_my_profile()) { bp_core_add_message(' ok in the mnethod 1','error'); return; } $hide_tabs = array( 'forums'=>1, 'groups'=>1, ); $username = bp_core_get_username( bp_loggedin_user_id() ); //$parent_nav_slug =bp_get_members_root_slug() . '/' . $username; $parent_nav_slug =bp_get_members_root_slug(); bp_core_add_message(' ok in the mnethod 2'.$parent_nav_slug,'error'); foreach ( array_keys( $hide_tabs ) as $tab ) { bp_core_remove_subnav_item( $parent_nav_slug, $tab ); } if ( ! empty( $hide_tabs[ bp_action_variable( 0 ) ] ) ) { bp_core_add_message( 'Sorry buddy, but this part is restricted to super admins!', 'error' ); bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) ); } }Thanks,
Parag Bhagwat