Changeset 355695
- Timestamp:
- 03/05/2011 01:02:36 PM (15 years ago)
- Location:
- buddypress-private-community
- Files:
-
- 4 added
- 3 edited
-
tags/0.6 (added)
-
tags/0.6/mm-buddypress-private-community-config-EXAMPLE.php (added)
-
tags/0.6/mm-buddypress-private-community.php (added)
-
tags/0.6/readme.txt (added)
-
trunk/mm-buddypress-private-community-config-EXAMPLE.php (modified) (5 diffs)
-
trunk/mm-buddypress-private-community.php (modified) (7 diffs)
-
trunk/readme.txt (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
buddypress-private-community/trunk/mm-buddypress-private-community-config-EXAMPLE.php
r290666 r355695 5 5 * This must be saved here: 6 6 * - /wp-content/plugins/buddypress-private-community-config/mm-buddypress-private-community-config.php 7 * to stop this file from being overwritten when the plugin is updated. And so no database calls are needed. 7 * IMPORTANT NOTE: The config file SHOULD NOT be contained in this plugins folder, it should have its own folder in the plugins directory as shown above. 8 * This is to stop the file from being overwritten when the plugin is updated, and so no database calls are needed. 9 * 10 * See FAQs and forum for more examples of config file setups. You'll need a config file if you're not running your BP community from the root of your domain or sub-domain. 11 * http://buddypress.org/community/groups/buddypress-private-community/home/ 8 12 * 9 13 * You can change the below settings: 10 14 */ 15 16 17 /** 18 * There are 2 modes: 19 * 20 * 1, ::$MODE = ::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS (DEFAULT MODE) 21 * - Blocks all pages/URIs apart from them listed in the ::$ALLOWED_URIS array from logged out users. 22 * - Widgets can be unblocked by adding their ids to the ::$ALLOWED_WIDGET_IDS (when ::$BLOCK_WIDGETS=TRUE) 23 * 24 * 2, ::$MODE = ::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS (opposite to the above mode) 25 * - Doesn't block any pages from logged out users apart from the URIs listed in the ::$NOT_ALLOWED_URIS 26 * - Widgets can be blocked by adding them to the ::$NOT_ALLOWED_WIDGET_IDS 27 * 28 */ 29 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE = MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS; 30 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE = MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS; 31 32 /* 33 * If your community isn't on the root of your domain or sub-domain then you should set the ::$WP_SUB_FOLDER to the directory of your community. 34 * e.g. http://my-domain.com/{my-wp-installation}, then ::$SUB_FOLDER='' 35 * e.g. http://my-domain.com/sub-folder-name/{my-wp-installation}, then ::$SUB_FOLDER='sub-folder-name' 36 * e.g. http://my-domain.com/sub/folder/name/{my-wp-installation}, then ::$SUB_FOLDER='sub/folder/name' 37 * Note, don't use a start or trailing '/' otherwise the plugin won't work. 38 */ 39 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$WP_SUB_FOLDER = 'my/private/community'; 40 11 41 /** 12 42 * $ALLOWED_URIS is an array of URIs that are accessible to everyone. … … 16 46 * - '/about' is OK, but '/about/' isn't valid! 17 47 * - '/about?page=info' is OK too 18 * - '' is the homepage, '/' is invalid! 48 * - '' is the HOMEPAGE, 49 * - '/' is INVALID! 19 50 * 20 51 * You can now also use the special character '*' at the end of your uris to allow access to greater areas of your site. … … 35 66 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_URIS = Array('/contacts', '/about', '/welcome'); 36 67 /** 68 * Used in the ::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS mode only. List of URIs that should be blocked. 69 * Note, you should use the special char * to stop access to all sub folders and query strings. 70 * array('/private', '/private/*', '/private?*') or array('/private*') 71 */ 72 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_URIS = Array('/private*'); 73 /** 37 74 * Currently the REDIRECT_TO_URL cannot include a '?' in the URL! 38 75 * This would result in an infinite redirect loop! … … 40 77 * - "site_url() . '/info'" is OK, but "site_url() . '/info?page=landing_page'" would result in an infinite redirect loop! 41 78 * 42 * Obviously, this URL should exist on your site !79 * Obviously, this URL should exist on your site or on another site, if required. 43 80 * 44 81 * Default = site_url() (Your homepage) … … 59 96 /** 60 97 * If true, this blocks all BuddyPress and WordPress sidebar widgets from displaying when the user is logged out. 98 * Selected widgets can be displayed by adding their ids to the ::$ALLOWED_WIDGET_IDS. 61 99 * Default = TRUE 62 100 */ 63 101 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$BLOCK_WIDGETS = FALSE; 64 102 103 /** 104 * A list of widget ids that are allowed to be displayed. All other widgets are hidden when ::$BLOCK_WIDGETS=TRUE. 105 * Used in MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS only. 106 * E.g. Array('calendar-2'); where calendar-2 is a widget id. 107 * Widget ids can be found be inspecting their html, e.g <div id="calendar-2">{WIDGET}</div> 108 * @var Array 109 */ 110 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_WIDGET_IDS = Array('calendar-2'); 111 /** 112 * A list of widget ids that are not allowed to be displayed. All other widgets are displayed. 113 * Used in MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS only. 114 * E.g. Array('calendar-2'); where calendar-2 is a widget id. 115 * Widget ids can be found be inspecting their html, e.g <div id="calendar-2">{WIDGET}</div> 116 * @var Array 117 */ 118 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_WIDGET_IDS = Array('private-widget-2'); 119 65 120 /** 66 121 * This blocks all BuddyPress and WordPress RSS feeds if TRUE. -
buddypress-private-community/trunk/mm-buddypress-private-community.php
r290666 r355695 3 3 Plugin Name: BuddyPress Private Community 4 4 Plugin URI: http://wordpress.org/extend/plugins/buddypress-private-community/ 5 Description: This plugin makes your BuddyPress community private. Only logged in members can view the social areas in full. You can set URLs that are available to everyone.6 7 Version: 0. 55 Description: This plugin makes your BuddyPress community private. In the default mode, only logged in members can view the social areas in full, logged out users have restricted access. You can restrict the access of logged out users by listing the pages/areas of your site that you'd like to make public to the world in the config file (See FAQs or the example config file for more information.) Alternatively, you can make your site accessible to logged out users, but restrict access to some private pages/areas of your site. This plugin also blocks widgets and RSS feeds by default, you can config which widgets you'd like to be blocked or not blocked and you can allow RSS feeds by changing the config file. This plugin is very flexible and can be set-up to work how you'd like it to work. See the FAQs or the example config file for more information about the two modes and configurable settings. If you're running BP not on the root of your domain or sub-domain, then you'll need to make a config file before this plugin will work - again see FAQs. Also, you can see this plugin in action here: <a href="http://www.englishpubpool.co.uk/bppc_test/about/">http://www.englishpubpool.co.uk/bppc_test/about/</a> 6 7 Version: 0.6 8 8 Author: NipponMonkey 9 Author URI: http://www.englishpubpool.co.uk 9 Author URI: http://www.englishpubpool.co.uk/bppc_test/about/ 10 10 License: GPL2 11 11 */ … … 32 32 require( dirname(dirname( __FILE__ )) . '/buddypress-private-community-config/mm-buddypress-private-community-config.php' ); 33 33 34 // Initiate the static plugin class on init 34 // Initiate the static plugin class on init 35 35 add_action('init', array('MM_BUDDYPRESS_PRIVATE_COMMUNITY', 'initiate'), 1); 36 36 37 37 38 38 class MM_BUDDYPRESS_PRIVATE_COMMUNITY { 39 /** 40 * Default mode. Blocks all pages apart from the ones listed in the ::$ALLOWED_URIS array. 41 * @var int 42 */ 43 const MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS = 1; 44 /** 45 * Blocks no pages apart from the ones listed in the ::$NOT_ALLOWED_URIS array. 46 * @var int 47 */ 48 const MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS = 2; 49 /** 50 * The mode, can be changed in the config file. 51 * @var int 52 */ 53 public static $MODE = MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS; 54 /** 55 * '' will redirect to the WP home page, otherwise provide an full URL. E.g. "http://my-domain.com/landing-page" or site_url('redirect-landing-page'). 56 * @var string 57 */ 39 58 public static $REDIRECT_TO_URL = ''; 40 59 public static $BLOCK_RSS_FEEDS = TRUE; 41 60 public static $BLOCK_RSS_FEEDS_WHEN_LOGGED_IN = TRUE; 61 /** 62 * This will be displayed in the query part of the URL after a logged out user tries to access a private page. 63 * @var string 64 */ 65 public static $REDIRECT_HOOK = 'bp_pc_redir_to'; 66 /** 67 * This will block widgets from being displayed when the user is loggeed out. This will help to hide private content. 68 * When set to true, you can still allow some widgets by adding the widget's id to the ::$ALLOWED_WIDGET_IDS. 69 * @var Boolean 70 */ 42 71 public static $BLOCK_WIDGETS = TRUE; 43 public static $REDIRECT_HOOK = 'bp_pc_redir_to'; 72 73 /* 74 * Used in MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS only. Array of allowed urls that non-logged in users have access to. 75 * E.g. array('/redirect-landing-page','/contacts','/about') 76 * This array can be set in the config file - See example config file for more info. 77 * @var Array 78 */ 44 79 public static $ALLOWED_URIS = Array(''); 80 /* 81 * Used in MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS only. 82 * E.g. Array('/private-page-1*', '/private-info*') 83 * This array can be set in the config file - See example config file for more info. 84 * @var Array 85 */ 86 public static $NOT_ALLOWED_URIS = Array(''); 87 /** 88 * A list of widget ids that are allowed to be displayed. All other widgets are hidden. 89 * Used in MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS only. 90 * E.g. Array('calendar-2'); where calendar-2 is a widget id. 91 * Widget ids can be found be inspecting their html, e.g <div id="calendar-2">{WIDGET}</div> 92 * @var Array 93 */ 94 public static $ALLOWED_WIDGET_IDS = Array(); 95 /** 96 * A list of widget ids that are not allowed to be displayed. All other widgets are displayed. 97 * Used in MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS only. 98 * E.g. Array('calendar-2'); where calendar-2 is a widget id. 99 * Widget ids can be found be inspecting their html, e.g <div id="calendar-2">{WIDGET}</div> 100 * @var Array 101 */ 102 public static $NOT_ALLOWED_WIDGET_IDS = Array(); 103 104 /* 105 * e.g. http://my-domain.com/my-wp-installation, then ::$SUB_FOLDER='' 106 * e.g. http://my-domain.com/sub-folder-name/my-wp-installation, then ::$SUB_FOLDER='sub-folder-name' 107 * e.g. http://my-domain.com/sub/folder/name/my-wp-installation, then ::$SUB_FOLDER='sub/folder/name' 108 * Note, don't use a start or trailing '/'. 109 */ 110 public static $WP_SUB_FOLDER = ''; 45 111 46 112 /** … … 120 186 */ 121 187 protected static function handle_block_widgets() { 122 if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$BLOCK_WIDGETS === TRUE) { 123 add_action('bp_after_sidebar_login_form', array('MM_BUDDYPRESS_PRIVATE_COMMUNITY', 'hide_wp_widgets_from_logged_out'), 1); 188 if (is_user_logged_in() === FALSE) { 189 if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$BLOCK_WIDGETS === TRUE) { 190 add_action('wp_head', array('MM_BUDDYPRESS_PRIVATE_COMMUNITY', 'hide_wp_widgets_where_needed'), 1); 191 } 124 192 } 125 193 } … … 188 256 189 257 /** 190 * An easy way to block all widgets from being displayed to logged out users. 191 * 192 * This assumes the login form is available on the accessible page, and that the login form comes before the 193 * sidebar widget area - like in the standard theme. 194 * 195 * It removes the registered widgets when the BuddyPress login form is shown, and adds them again 196 * after the sidebar template has been processed. 197 * 198 * This means the widgets will be available in other widgeted areas. 258 * Takes out all unwanted widgets running checks against allowed/not allowed widget ids set by the user in the config file - depending on the mode too. 199 259 * 200 260 */ 201 public static function hide_wp_widgets_from_logged_out() { 202 // WordPress global 261 public static function hide_wp_widgets_where_needed() { 203 262 global $wp_registered_widgets; 204 // removes all widgets so they can't be displayed! 205 $wp_registered_widgets = array('all_widgets' => $wp_registered_widgets); 206 add_action('bp_inside_after_sidebar', array('MM_BUDDYPRESS_PRIVATE_COMMUNITY', 'hide_wp_widgets_from_logged_out_restore_widgets_global'), 1); 207 } 208 209 public static function hide_wp_widgets_from_logged_out_restore_widgets_global() { 210 // WordPress global 211 global $wp_registered_widgets; 212 // Adds the widgets again! They could now be used in other widgets areas. 213 $wp_registered_widgets = $wp_registered_widgets['all_widgets']; 263 if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE===MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS) { 264 // Mainly not allowing access, so block widgets. 265 $is_blocking = true; 266 $widget_ids = MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_WIDGET_IDS; 267 }else if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE===MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS) { 268 // Mainly allowing access, so don't block widgets. 269 $is_blocking = false; 270 $widget_ids = MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_WIDGET_IDS; 271 } 272 if (count($widget_ids)==0) { 273 if ($is_blocking) $wp_registered_widgets = array();// block all. Otherwise allow all (hence no else!) 274 }else { 275 $allowed_widgets = array(); 276 foreach ($wp_registered_widgets as $widget_id=>$widget) { 277 $was_found = false; 278 foreach ($widget_ids as $allowed_id) { 279 if ($allowed_id==$widget_id) { 280 $was_found = true;; 281 if ($is_blocking) { 282 // Widget found in allowed list - so keep it! 283 $allowed_widgets[$widget_id] = $widget; 284 } 285 continue; // go to next widget 286 } 287 } 288 if (!$is_blocking && !$was_found) { 289 // Widget not found in not allowed list - so keep it! 290 $allowed_widgets[$widget_id] = $widget; 291 } 292 } 293 $wp_registered_widgets = $allowed_widgets; 294 } 214 295 } 215 296 … … 233 314 if (isset($_GET[$REDIRECT_QUERY_NAME]) && preg_match('/^\//', $_GET[$REDIRECT_QUERY_NAME])!=0) { 234 315 // This always redirects logged in users when the $REDIRECT_QUERY_NAME is valid! 235 $REDIRECT_TO = $bp->root_domain . urldecode($_GET[$REDIRECT_QUERY_NAME]);316 $REDIRECT_TO = site_url(urldecode($_GET[$REDIRECT_QUERY_NAME])); 236 317 bp_core_redirect($REDIRECT_TO); 237 318 exit(); 238 319 } 239 320 // User is logged in - so everything else is OK - normal WP/BP permission take control. 321 return; 240 322 }else { 241 323 /** … … 243 325 */ 244 326 $REDIRECT_TO = MM_BUDDYPRESS_PRIVATE_COMMUNITY::$REDIRECT_TO_URL; 245 $allowed_uris = MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_URIS;246 327 247 328 // Current page URI. … … 250 331 /** 251 332 * Prepare the URI for checking against the allowed URIs 333 * - Remove the sub folder from the URI. 252 334 * - Remove the the $REDIRECT_QUERY_NAME part if it has one 253 335 * - Remove the ? if the URI now ends with ? 254 336 * - Remove the final / if the URI now ends in / 255 337 * 256 * E.g. "/ about/?bella-redir=/members" will be converted to "/about"338 * E.g. "/to-my-bp-folder/events/?event_id=4&bella-redir=/members" will be converted to "/events/?event_id=4" 257 339 */ 258 $uri_trimmed = preg_replace("/" . $REDIRECT_QUERY_NAME . "=[^&?]*/", '', $uri); 259 $uri_trimmed = preg_replace("/\?$/", '', $uri_trimmed); 260 $uri_trimmed = preg_replace("/\/$/", '', $uri_trimmed); 261 //$uri_trimmed = preg_replace("/\/?\??" . $REDIRECT_QUERY_NAME . "=[^&?]*/", '', $uri); 340 if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$WP_SUB_FOLDER==''){ 341 // Don't have to trim the $WP_SUB_FOLDER folder. 342 $uri_trimmed = $uri; 343 }else { 344 $uri_trimmed = substr($uri, strlen(MM_BUDDYPRESS_PRIVATE_COMMUNITY::$WP_SUB_FOLDER) + 1); 345 } 346 $uri_trimmed = preg_replace( 347 array("/" . $REDIRECT_QUERY_NAME . "=[^&?]*/", "/\?$/", "/\/$/"), 348 array('', '', ''), 349 $uri_trimmed 350 ); 262 351 $uri_trimmed = strtolower($uri_trimmed); 263 352 264 /** 265 * Check to see if logged out user is allowed access to this page 266 */ 267 for ($i=0; $i < count($allowed_uris); $i++) { 268 $cur_allowed_uri = strtolower($allowed_uris[$i]); 269 if ( 270 ( 271 $cur_allowed_uri === $uri_trimmed 272 ) || ( 273 strpos($cur_allowed_uri, '*') === strlen($cur_allowed_uri) - 1 274 && strpos($uri_trimmed, substr($cur_allowed_uri, 0, strlen($cur_allowed_uri) - 1)) === 0 275 ) 276 ) { 277 // Is allowed access, so return. 278 return; 353 if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE===MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS) { 354 /** 355 * Check to see if logged out user is allowed access to this page 356 */ 357 $allowed_uris = MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_URIS; 358 for ($i=0; $i < count($allowed_uris); $i++) { 359 $cur_allowed_uri = strtolower($allowed_uris[$i]); 360 if ( 361 ( 362 $cur_allowed_uri === $uri_trimmed 363 ) || ( 364 strpos($cur_allowed_uri, '*') === strlen($cur_allowed_uri) - 1 365 && strpos($uri_trimmed, substr($cur_allowed_uri, 0, strlen($cur_allowed_uri) - 1)) === 0 366 ) 367 ) { 368 // Is allowed access, so return. 369 return; 370 } 279 371 } 280 }281 372 282 // If this part is reached, then the user is logged out and doesn't have access to this page. 283 // So, handle the redirect to the default accessible page. 373 // If this part is reached, then the user is logged out and doesn't have access to this page 374 // because it's not in the allowed list. 375 // So, handle the redirect to the default accessible page. 376 377 // Add redirect URL, if needed 378 if (preg_match('/^\//', $uri_trimmed)===0) { 379 $uri_trimmed = '/' . $uri_trimmed; 380 } 381 // This assumes the $REDIRECT_TO doesn't already have a ? in the URL. 382 // '/' added at the start to stop an extra redirect that BP seems to do to add it to the URL. 383 $REDIRECT_TO .= '/?' . $REDIRECT_QUERY_NAME . '=' . urlencode($uri_trimmed); 384 385 bp_core_redirect($REDIRECT_TO); 386 exit(); 387 }else if (MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE===MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS) { 388 /** 389 * Check to see if logged out user is allowed access to this page 390 */ 391 $not_allowed_uris = MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_URIS; 392 for ($i=0; $i < count($not_allowed_uris); $i++) { 393 $cur_not_allowed_uri = strtolower($not_allowed_uris[$i]); 394 if ( 395 ( 396 $cur_not_allowed_uri === $uri_trimmed 397 ) || ( 398 strpos($cur_not_allowed_uri, '*') === strlen($cur_not_allowed_uri) - 1 399 && strpos($uri_trimmed, substr($cur_not_allowed_uri, 0, strlen($cur_not_allowed_uri) - 1)) === 0 400 ) 401 ) { 402 // If this part is reached, then the user is logged out and doesn't have access to this page 403 // because it's in the allowed list. 404 // So, handle the redirect to the default accessible page. 405 406 // Add redirect URL, if needed 407 if (preg_match('/^\//', $uri_trimmed)===0) { 408 $uri_trimmed = '/' . $uri_trimmed; 409 } 410 // This assumes the $REDIRECT_TO doesn't already have a ? in the URL. 411 // '/' added at the start to stop an extra redirect that BP seems to do to add it to the URL. 412 $REDIRECT_TO .= '/?' . $REDIRECT_QUERY_NAME . '=' . urlencode($uri_trimmed); 413 414 bp_core_redirect($REDIRECT_TO); 415 exit(); 416 } 417 } 418 // The page didn't match a not allowed URI, so the page can be loaded. 419 return; 420 }else { 421 die('Unknown BuddyPress Private Community Mode: mode=' . MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE . '. Please check your config file.'); 422 } 284 423 285 // Add redirect URL, if needed286 if (preg_match('/^\//', $uri_trimmed)===0) {287 $uri_trimmed = '/' . $uri_trimmed;288 }289 // This assumes the $REDIRECT_TO doesn't already have a ? in the URL.290 $REDIRECT_TO .= '?' . $REDIRECT_QUERY_NAME . '=' . urlencode($uri_trimmed);291 292 bp_core_redirect($REDIRECT_TO);293 exit();294 424 } 295 425 } -
buddypress-private-community/trunk/readme.txt
r290666 r355695 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RWX65UE2TBFH2 4 4 Tags: private, community, privacy, secret, secure, buddypress, buddy, press, BP, admin, page, security, plugin 5 Requires at least: Only tested on 2.9+ 6 Tested up to: 3. 0.1 & 1.2.5.27 Stable tag: 0. 55 Requires at least: Only tested on 2.9+ (Requires PHP5) 6 Tested up to: 3.1 & 1.2.8 7 Stable tag: 0.6 8 8 9 9 This plugin makes your BuddyPress community private. Only logged in members can view the social areas in full. You can configure the default settings. … … 11 11 12 12 == Description == 13 This plugin makes your BuddyPress community private. So, only logged in members can view all areas of your community. 14 If you visit the community when you're logged out and your visiting a private page, then you're redirected to a landing page of your choice. It defaults to the homepage. 15 16 You can set urls that are accessibly to non-logged in users using a special config php file - no database calls are needed. 17 18 By default the plugin blocks all of your widgets from being visible to logged out users. This stops possible private information from being seen when non-logged in users visit your site. 19 20 Also, all RSS feeds are blocked by default too. These default settings can be changed in a special config file - see FAQs for more information. 13 This plugin makes your BuddyPress community private. You can control which areas of your site are accessible to logged out users in two ways, "restrict site access, but allow some public pages" or "allow site access, but restrict some private pages". This plugin also can block widgets from logged out users and block all RSS feeds. 14 15 In the default mode (restrict access, but allow some public pages), logged out users only have access to your homepage, or access to a list of pages/areas that you'd like to make public. Logged in members have full site access. 16 17 If you visit the community when you're logged out and you're visiting a private page, then you're redirected to a landing page of your choice (defaults to the homepage). 18 19 You can set uris that are accessibly to non-logged in users using a special config php file - no database calls are needed. 20 21 In the alternative mode (allow site access, but restrict some private pages), logged out members have full site access, but you are able to make some pages/areas of your site private - so only logged in members are able to view them. This is the opposite to the default mode. 22 23 In the default mode, the plugin blocks all of your widgets from being visible to logged out users. This stops possible private information from being seen when non-logged in users visit your site. 24 You can change the config file so that some of your widgets are still displayed. In the alternative mode, all widgets are shown but you're able to block widgets that should only be displayed to members. 25 26 Also, all RSS feeds are blocked by default too. 21 27 22 28 You might also like to change these setting in your WordPress and BuddyPress settings. … … 26 32 * WP Privacy Settings: Site Visibility = I would like to block search engines, but allow normal visitors 27 33 34 See the FAQs or the example config file in the download for more information on configuring this plugin. 35 36 You can see an example of this plugin working in the default mode here: http://www.englishpubpool.co.uk/bppc_test/about/ 37 38 * Please note, this plugin requires PHP 5. 39 28 40 If you'd like to ensure that users don't stay logged into your site after a set period of inactivity (for security reasons), then you could use this plugin: 29 41 … … 34 46 1. Upload the plugin's folder to the `/wp-content/plugins/` directory 35 47 2. Activate the plugin through the 'Plugins' menu in WordPress 36 3. That's it! 48 3. If your community is not in the root of your domain or subdomain, then you must make a config file. You must set the ::$WP_SUB_FOLDER variable to the directory of your community. E.g. for www.my-domain.com/bp/(BP SITE), ::$WP_SUB_FOLDER='bp'. For www.my-domain.com/charity/community/(BP SITE), ::$WP_SUB_FOLDER='charity/community'. WARNING, please make sure you save the config file in the correct place - See FAQs for information about creating a config file. All it requires is making a new folder (in the correct place) and adding a PHP config with your settings. These settings will override the default settings. 49 4. That's it! 37 50 38 51 You can change the default setting by creating a special config file. See FAQs for more information. 39 52 You can change: 40 53 41 * The ALLOWED_URIS, these are the pages that are accessible to non-members. (Default = Array('')) 54 * The MODE, two modes: block all pages from logged out users apart from a few public pages OR allow access to all pages apart from a few private (members only) ones. 55 * The WP_SUB_FOLDER, the directory where your BP site is, this must be changed if your BP site isn't at the root of your domain or sub-domain. 56 * The ALLOWED_URIS, these are the pages that are accessible to non-members. (Default = Array('')) (Used in default mode only) 57 * The NOT_ALLOWED_URIS, these are the pages that are not accessible to non-members. (Default = Array('')) (Used in alternative mode only) 42 58 * The REDIRECT_TO_URL, this is where you'll be redirected too if you try to access a private page when you're logged out. (Default = site_url()) 43 59 * The REDIRECT_HOOK, this is a string that will appear in the URL that stores the private page that you were redirected from. This is used to redirect the user again after logging into your site. 44 60 * The BLOCK_RSS_FEEDS, if true then all of the WordPress and BuddyPress feeds will be blocked. (Default = TRUE) 45 61 * The BLOCK_WIDGETS, if true then the sidebar widgets won't be displayed to logged out users. This is useful as often private information is contained in the sidebar widgets. (Default = TRUE) 62 * The ALLOWED_WIDGET_IDS, an array of widget ids that are OK to display to logged out users (Used in default mode only). 63 * The NOT_ALLOWED_WIDGET_IDS, an array of widget ids that are not OK to be display to logged out users (Used in alternative mode only). 46 64 * You can also set custom messages that will appear in the RSS/ATOM feeds instead of your private content. 47 65 48 66 == Frequently Asked Questions == 67 68 = Why isn't my config file working? = 69 70 99% of the time is because you didn't save the config file in the correct place. 71 72 You MUST save the file in a new directory, not in this plugin's folder structure, but in the main plugins folder. 73 74 ` 75 // You MUST save the file here: 76 /wp-content/plugins/buddypress-private-community-config/mm-buddypress-private-community-config.php 77 78 // NOT HERE: 79 /wp-content/plugins/buddypress-private-community/mm-buddypress-private-community-config.php 80 81 // NOR HERE: 82 /wp-content/plugins/buddypress-private-community/buddypress-private-community-config/mm-buddypress-private-community-config.php 83 ` 84 85 This is to ensure that your config setting are not deleted when you update the plugin in the future. 86 87 See "How can I override the default settings?" for information about the setting that you can change. 88 49 89 50 90 = How can I override the default settings? = 51 91 You can create your own config file (that won't be overwritten when you update this plugin) that stores your preferred settings. 52 To stop this file from being overwritten when you update the plugin, you have to create a new folder, called "buddypress-private-community-config", in the plugin directoryand create a file called "mm-buddypress-private-community-config.php" in the new folder.53 Because the file is in a seperate folder to the plugin, the config file won't be overwritten whe you update the plugin later - and thismeans no database calls are needed to run this plugin. So, it should be a fast plugin.54 55 Here is an example config file, that should be saved in the new config directory. 92 To stop this file from being overwritten when you update the plugin, you have to create a new folder, called "buddypress-private-community-config", in the WP wp-content/plugins/ directory (NOTE: this is not in the wp-content/plugins/buddypress-private-community folder to avoid overriding the file on update) and create a file called "mm-buddypress-private-community-config.php" in the new folder. 93 Because the file is in a seperate folder to the plugin, the config file won't be overwritten when you update the plugin later. Also, this method means no database calls are needed to run this plugin. So, it should be a fast plugin. 94 95 Here is an example config file, that should be saved in the new config directory. It might look confusing at first, but in most cases you only need to use some of these settings as required. See FAQs "How can I allow members to automatically register to my private community?" for a simple config file that allows user to register to your site. 56 96 57 97 ` … … 62 102 * This must be saved here: 63 103 * - /wp-content/plugins/buddypress-private-community-config/mm-buddypress-private-community-config.php 64 * to stop this file from being overwritten when the plugin is updated. And so no database calls are needed. 104 * IMPORTANT NOTE: The config file SHOULD NOT be contained in this plugins folder, it should have its own folder in the plugins directory as shown above. 105 * This is to stop the file from being overwritten when the plugin is updated, and so no database calls are needed. 106 * 107 * See FAQs and forum for more examples of config file setups. You'll need a config file if you're not running your BP community from the root of your domain or sub-domain. 108 * http://buddypress.org/community/groups/buddypress-private-community/home/ 65 109 * 66 110 * You can change the below settings: 67 111 */ 112 113 114 /** 115 * There are 2 modes: 116 * 117 * 1, ::$MODE = ::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS (DEFAULT MODE) 118 * - Blocks all pages/URIs apart from them listed in the ::$ALLOWED_URIS array from logged out users. 119 * - Widgets can be unblocked by adding their ids to the ::$ALLOWED_WIDGET_IDS (when ::$BLOCK_WIDGETS=TRUE) 120 * 121 * 2, ::$MODE = ::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS (opposite to the above mode) 122 * - Doesn't block any pages from logged out users apart from the URIs listed in the ::$NOT_ALLOWED_URIS 123 * - Widgets can be blocked by adding them to the ::$NOT_ALLOWED_WIDGET_IDS 124 * 125 */ 126 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE = MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS; 127 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$MODE = MM_BUDDYPRESS_PRIVATE_COMMUNITY::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS; 128 129 /* 130 * If your community isn't on the root of your domain or sub-domain then you should set the ::$WP_SUB_FOLDER to the directory of your community. 131 * e.g. http://my-domain.com/{my-wp-installation}, then ::$SUB_FOLDER='' 132 * e.g. http://my-domain.com/sub-folder-name/{my-wp-installation}, then ::$SUB_FOLDER='sub-folder-name' 133 * e.g. http://my-domain.com/sub/folder/name/{my-wp-installation}, then ::$SUB_FOLDER='sub/folder/name' 134 * Note, don't use a start or trailing '/' otherwise the plugin won't work. 135 */ 136 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$WP_SUB_FOLDER = 'my/private/community'; 137 68 138 /** 69 139 * $ALLOWED_URIS is an array of URIs that are accessible to everyone. … … 73 143 * - '/about' is OK, but '/about/' isn't valid! 74 144 * - '/about?page=info' is OK too 75 * - '' is the homepage, '/' is invalid! 145 * - '' is the HOMEPAGE, 146 * - '/' is INVALID! 76 147 * 77 148 * You can now also use the special character '*' at the end of your uris to allow access to greater areas of your site. … … 92 163 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_URIS = Array('/contacts', '/about', '/welcome'); 93 164 /** 165 * Used in the ::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS mode only. List of URIs that should be blocked. 166 * Note, you should use the special char * to stop access to all sub folders and query strings. 167 * array('/private', '/private/*', '/private?*') or array('/private*') 168 */ 169 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_URIS = Array('/private*'); 170 /** 94 171 * Currently the REDIRECT_TO_URL cannot include a '?' in the URL! 95 172 * This would result in an infinite redirect loop! … … 97 174 * - "site_url() . '/info'" is OK, but "site_url() . '/info?page=landing_page'" would result in an infinite redirect loop! 98 175 * 99 * Obviously, this URL should exist on your site !176 * Obviously, this URL should exist on your site or on another site, if required. 100 177 * 101 178 * Default = site_url() (Your homepage) … … 116 193 /** 117 194 * If true, this blocks all BuddyPress and WordPress sidebar widgets from displaying when the user is logged out. 195 * Selected widgets can be displayed by adding their ids to the ::$ALLOWED_WIDGET_IDS. 118 196 * Default = TRUE 119 197 */ 120 198 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$BLOCK_WIDGETS = FALSE; 121 199 200 /** 201 * A list of widget ids that are allowed to be displayed. All other widgets are hidden when ::$BLOCK_WIDGETS=TRUE. 202 * Used in MODE_BLOCK_ALL_AND_ALLOW_SOME_URIS only. 203 * E.g. Array('calendar-2'); where calendar-2 is a widget id. 204 * Widget ids can be found be inspecting their html, e.g <div id="calendar-2">{WIDGET}</div> 205 * @var Array 206 */ 207 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_WIDGET_IDS = Array('calendar-2'); 208 /** 209 * A list of widget ids that are not allowed to be displayed. All other widgets are displayed. 210 * Used in MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS only. 211 * E.g. Array('calendar-2'); where calendar-2 is a widget id. 212 * Widget ids can be found be inspecting their html, e.g <div id="calendar-2">{WIDGET}</div> 213 * @var Array 214 */ 215 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_WIDGET_IDS = Array('private-widget-2'); 216 122 217 /** 123 218 * This blocks all BuddyPress and WordPress RSS feeds if TRUE. … … 159 254 160 255 ` 256 // If you're running WP/BP from a sub folder, set this value to direct the plugin to the correct place. 257 // Don't set this or set it to '' if your WP/BP site is at the root of your domain or subdomain. 258 //MM_BUDDYPRESS_PRIVATE_COMMUNITY::$WP_SUB_FOLDER = 'my/private/community'; // for www.my-domain.com/my/private/community/(BP SITE) 161 259 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_URIS = Array( 162 '/my-landing-page', // your choice of landing page163 '/another-allowed-uri', //any other page(s) you'd to make public to non-members164 '/register', // Allow access to the registration form165 '/activate?key=*' // Allow access to the account activation URIs. The wildcard character * allows all activation codes to be accepted as valid URIs.260 '/my-landing-page', // Where "/my-landing-page" is your default landing page of choice - this must match your your choice of ::$REDIRECT_TO_URL. 261 '/another-allowed-uri', // (Optional extra uri(s)) any other page(s) you'd to make public to non-members 262 '/register', // Allow access to the registration form 263 '/activate?key=*' // Allow access to the account activation URIs. The wildcard character * allows all activation codes to be accepted as valid URIs. 166 264 ); 167 265 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$REDIRECT_TO_URL = site_url() . '/my-landing-page'; … … 174 272 175 273 274 = How can I allow a widget to be displayed to logged out users? = 275 276 This can be done by adding the widget's id string to the ::$ALLOWED_WIDGET_IDS array. E.g. 277 278 ` 279 // This line will let the widget with id=calendar-2 to be displayed when logged out users visit your site. 280 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_WIDGET_IDS = Array('calendar-2'); 281 ` 282 283 You can find the widget's id by looking at your site's source HTML. The widget id should be shown in the widget's main div. E.g. 284 285 ` 286 <div id="calendar-2"> 287 // calendar widget! 288 </div> 289 ` 290 291 You can add more widget ids easily: 292 293 ` 294 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_WIDGET_IDS = Array('calendar-2', 'calendar-3', 'hallooo-widget-2'); 295 ` 296 297 Similarly, you can hide widget in the alternative mode in a similar way - e.g. 298 299 ` 300 // Used in alternative mode only. (::MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS) 301 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$NOT_ALLOWED_WIDGET_IDS = Array('private-widget-2', 'top-secret-widget-1'); 302 ` 303 304 305 = What is the redirect hook for? = 306 307 The redirect hook is used to redirect a logged out member to a private page they tried to access when logged out. The redirect happens after they login. 308 309 This is important for when a member gets an email with a link to somewhere on the community that is private. If the member clicks on this link and isn't yet logged in, then they will be redirect to the default landing page. 310 311 When this happens, you notice that the redirect hook can be seen in the url, and it points the page that the member tried to access. Now, when the user successfully logs in, the plugin automatically handles a redirect to the page that the user originally tried to access. 312 313 This means the user doesn't have to go back to their emails and find the link again as the redirect is handled for them. 314 315 You can change the key word/string used as the hook in the config file. 316 317 176 318 = How private will my BuddyPress community really be? = 177 319 Well, access to your community through PHP pages will be blocked to logged out users, but your images and uploaded files will still be accessible via their URLs as no PHP code is blocking access to jpgs, xls. etc... … … 191 333 192 334 335 = Can I use this plugin with PHP 4? = 336 337 Sorry, this plugin only works with PHP 5. WP and BP and moving to PHP 5 only, so we currently have no plans to make this plugin available for PHP 4. 338 339 340 = I'm getting a parse error! = 341 342 If you can a parse error like below: 343 344 ` 345 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in mm-buddypress-private-community.php on line 39 346 ` 347 348 This normally means you're not running PHP 5. This plugin requires PHP 5. 349 350 If this wasn't the problem, then you should try installing the plugin again. I've had one report where re-installing the plugin after getting this error fixed the bug - maybe from a bad download or something. 351 352 353 = I'm getting an infinite redirect loop error! = 354 355 This normally means your config file isn't set up correctly. 356 357 You must make sure that your redirect url is a public page. E.g. here is a simple config file: 358 359 ` 360 // Here we make a BP page called 'welcome' th default redirect page, and make this a public page to avoid an infinite redirect loop. 361 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$WP_SUB_FOLDER = 'my-community'; 362 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$ALLOWED_URIS = Array('/contacts', '/about', '/welcome'); 363 MM_BUDDYPRESS_PRIVATE_COMMUNITY::$REDIRECT_TO_URL = site_url('welcome'); 364 ` 365 366 Note that the redirect URL is set to the 'welcome' page. This page must be in the ::$ALLOWED_URIS, as can be seen above. 367 368 If the '/welcome' URI is removed from the ::$ALLOWED_URIS array, then an infinite redirect will occur. 369 370 193 371 == Changelog == 372 373 = 0.6 = 374 * IMPORTANT! BREAKABLE UPDATE: Changed how sub-directory installations are handled. Now you must set the ::$WP_SUB_FOLDER variable to the folder where your community is. (my-domain.com/community/{BP_SITE}, then ::$WP_SUB_FOLDER='community'. ALLOWED_URIS would now look like this array('/about') instead of array('/community/about') in this example - meaning that the ALLOWES_URIS are always written in the same way relative to your BP site_url.) See FAQs or the example config file. 375 * Added another mode allowing you to give access to logged out users but block a few private pages/URIs (MODE_BLOCK_NONE_AND_NOT_ALLOW_SOME_URIS). 376 * Added the ability to display/block widgets (depending on the mode) by their id (ALLOWED_WIDGET_IDS & NOT_$ALLOWED_WIDGET_IDS). 377 * Changed how widgets are block, so they should be block on all themes (including two widget column themes). 194 378 195 379 = 0.5 = … … 215 399 216 400 == Upgrade Notice == 401 * Version 0.6: IMPORTANT! If you're running BP not from the root of your domain or subdomain, then you'll have to update your config file after making this update (Other users don't have to make any changes). You'll have to set the new WP_SUB_FOLDER variable to match wher your BP community is located and change your ALLOWED_URIS to so there are relative to BP rather then to the root of your domain. (e.g. if my-domain.com/bp-community/{BP_SITE}, then WP_SUB_FOLDER = 'bp-community', and say, array('/bp-community/landing-page')becomes array('/landing-page')). All future updates won't require you to make any changes. 217 402 * Version 0.1: This plugin should upgrade with no changes needed by the user.
Note: See TracChangeset
for help on using the changeset viewer.