Plugin to show components to registered Users only
-
Hello,
after a long search in this forums,i learnt how to make the buddypress site components like members,groups not visible to non-logged in users.
Thanks to Burt Adsit and Peterverkooijen.I learnt this from their thread http://buddypress.org/forums/topic.php?id=1651
i started this thread to avoid confusions since there are a lot of codes and error messages in that thread.
Ok….
In short,create a file named bp-custom.php in the wp-content/mu-plugins folder.
Then add this code in that file.
<?php /* Plugin Name: bpRestrict - BuddyPress Plugin Plugin URI: http://code.ourcommoninterest.org/ Description: Restricts non-logged in users from certain areas Author: Burt Adsit Version: 0.1 Author URI: http://code.ourcommoninterest.org/ License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt */ function js_restrict_access(){ global $bp, $bp_unfiltered_uri; if (!is_user_logged_in() && (BP_MEMBERS_SLUG == $bp_unfiltered_uri[0] || BP_GROUPS_SLUG == $bp->current_component || BP_BLOGS_SLUG == $bp->current_component)){ bp_core_redirect( get_option('home') . "/register?s=1" ); } } add_action( 'wp', 'js_restrict_access', 3 ); ?>
Next,open the register.php file from wp-content/themes/bphome/
After the <?php get_header(); ?> line,add this code
<?php
if($_REQUEST["s"]){?>
<script type="text/javascript">
jQuery(document).ready(function () {
setTimeout(function(){ jQuery("#error").fadeOut("slow"); }, 6000);
});
</script>
<div id="error" class="error">
<h3>The page you were trying to access is for members only. Please login or register to continue.</h3>
</div>
<?php } ?>
That’s it….
now,the non-logged in users will be redirected to sign up page whenever they try to visit the members,blog or the groups…
- The topic ‘Plugin to show components to registered Users only’ is closed to new replies.