Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: BuddyPress Profile Privacy
- * Plugin URI: http://buddypress.org
- * Description: Basic profile privacy for BuddyPress
- * Author: modemlooper
- * Version: 1.0
- * Author URI: http://modemlooper.me
- */
- // Exit if accessed directly
- if ( !defined( 'ABSPATH' ) ) exit;
- // ------- Check if member is a friend ------------- code snippet by @pollyplummer //
- function bp_displayed_user_is_friend() {
- global $bp;
- if ( bp_is_profile_component() || bp_is_member() ) {
- if ( ('is_friend' != BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $bp->displayed_user->id )) && (bp_loggedin_user_id() != bp_displayed_user_id()) && get_user_meta($bp->displayed_user->id, 'bp-profile-privacy') != '1' )
- if ( !is_super_admin( bp_loggedin_user_id() ) )
- return true;
- }
- }
- function bp_setup_privacy_nav() {
- global $bp;
- /* Add a nav item for this component under the settings nav item. See bp_example_screen_settings_menu() for more info */
- bp_core_new_subnav_item( array(
- 'name' => __( 'Privacy', 'buddypress' ),
- 'slug' => 'privacy',
- 'parent_slug' => $bp->settings->slug,
- 'parent_url' => $bp->loggedin_user->domain . $bp->settings->slug . '/',
- 'screen_function' => 'bp_privacy_screen_settings_menu',
- 'position' => 40,
- 'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
- ) );
- }
- add_action( 'bp_setup_nav', 'bp_setup_privacy_nav' );
- function bp_privacy_screen_settings_menu() {
- global $bp, $current_user, $bp_settings_updated, $pass_error;
- if ( isset( $_POST['submit'] )) {
- if (isset($_POST['bp-profile-privacy'])) {
- update_user_meta($bp->loggedin_user->id, 'bp-profile-privacy', '1');
- } else {
- update_user_meta($bp->loggedin_user->id, 'bp-profile-privacy', '0');
- }
- bp_core_add_message( 'Settings updated!' );
- bp_core_redirect( bp_displayed_user_domain() . $bp->settings->slug . '/privacy' );
- }
- add_action( 'bp_template_content', 'bp_privacy_screen_settings_menu_content' );
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
- }
- function bp_privacy_screen_settings_menu_content() {
- global $bp;
- ?>
- <form action="" method="post" id="standard-form" name="settings-form">
- <h5><input name="bp-profile-privacy" type="checkbox" id="bp-profile-privacy" value="1" <?php if (get_user_meta($bp->displayed_user->id, 'bp-profile-privacy',1) == '1') echo 'checked="checked"' ?> tabindex="99" /> check to only show profile to friends</h5>
- <div class="submit" style="margin-top:10px;">
- <input type="submit" name="submit" id="submit" value="<?php _e( 'Save Changes', 'buddypress' ); ?>" />
- </div>
- </form>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement