This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

bp privacy

By: modemlooper on Nov 18th, 2011  |  syntax: PHP  |  size: 2.73 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Plugin Name: BuddyPress Profile Privacy
  4.  * Plugin URI:  http://buddypress.org
  5.  * Description: Basic profile privacy for BuddyPress
  6.  * Author:      modemlooper
  7.  * Version:     1.0
  8.  * Author URI:  http://modemlooper.me
  9.  */
  10.  
  11. // Exit if accessed directly
  12. if ( !defined( 'ABSPATH' ) ) exit;
  13.  
  14. // ------- Check if member is a friend  ------------- code snippet by @pollyplummer //
  15. function bp_displayed_user_is_friend() {
  16.         global $bp;
  17.         if ( bp_is_profile_component() || bp_is_member() ) {
  18.         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' )
  19.         if ( !is_super_admin( bp_loggedin_user_id() ) )
  20.         return true;
  21.         }
  22. }
  23.  
  24.  
  25. function bp_setup_privacy_nav() {
  26.         global $bp;
  27.        
  28.                 /* Add a nav item for this component under the settings nav item. See bp_example_screen_settings_menu() for more info */
  29.         bp_core_new_subnav_item( array(
  30.                 'name' => __( 'Privacy', 'buddypress' ),
  31.                 'slug' => 'privacy',
  32.                 'parent_slug' => $bp->settings->slug,
  33.                 'parent_url' => $bp->loggedin_user->domain . $bp->settings->slug . '/',
  34.                 'screen_function' => 'bp_privacy_screen_settings_menu',
  35.                 'position' => 40,
  36.                 'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
  37.         ) );
  38. }
  39. add_action( 'bp_setup_nav', 'bp_setup_privacy_nav' );
  40.  
  41.  
  42. function bp_privacy_screen_settings_menu() {
  43.  
  44.         global $bp, $current_user, $bp_settings_updated, $pass_error;
  45.  
  46.        
  47.                 if ( isset( $_POST['submit'] )) {
  48.                         if (isset($_POST['bp-profile-privacy'])) {
  49.                         update_user_meta($bp->loggedin_user->id, 'bp-profile-privacy', '1');
  50.                         } else {
  51.                         update_user_meta($bp->loggedin_user->id, 'bp-profile-privacy', '0');
  52.                         }
  53.                 bp_core_add_message( 'Settings updated!' );
  54.                 bp_core_redirect( bp_displayed_user_domain() . $bp->settings->slug . '/privacy' );
  55.          
  56.                 }
  57.                
  58.                
  59.         add_action( 'bp_template_content', 'bp_privacy_screen_settings_menu_content' );
  60.  
  61.         bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  62.        
  63. }
  64.  
  65.  
  66.  
  67. function bp_privacy_screen_settings_menu_content() {
  68.  
  69.         global $bp;
  70.        
  71. ?>
  72.        
  73.         <form action="" method="post" id="standard-form" name="settings-form">
  74.                         <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>
  75.                         <div class="submit" style="margin-top:10px;">
  76.                         <input type="submit" name="submit" id="submit" value="<?php _e( 'Save Changes', 'buddypress' ); ?>" />
  77.                         </div>
  78.         </form>
  79. <?php
  80.  
  81. }
  82. ?>
clone this paste RAW Paste Data