
The WordPress-Buddypress-Lockdown challenge
I often read about folks wanting to lockdown their WordPress-Buddypress site, and make it so that content is accessible to logged-in members only. Even more, many want to know how to redirect site visitors to a landing page like Facebook – with login and registration on the page – while still having some select content available to them.
Look no further folks. Today, we’re gonna git ‘er done!
Once we’re finished with this project, and depending on your chosen theme of course, your landing page should look quite similar to the screenshot at right.
To make this WordPress-Buddypress project as easy as pie for even the most novice among us, this tutorial is divided into 5 parts so you can get stuff done at your leisure:
- Custom page template
We need a custom page template to display the content we want site visitors to see. - Landing page
We’ll build our landing page with on-page login and registration. - Logged-out menu
We’ll create a special custom menu for site visitors. - Redirect function
We’ll write a custom function to ensure visitors can only access our selected content. - Make stuff look good
We’ll add a few style rules and tweak some stuff to get your new landing page and logged-out pages looking sharp as tacks!
Featured Plugin - WordPress Newsletter Plugin
Ready? Let’s dig in!
1) Custom page template
First of all, before making any of the changes described in this tutorial, I highly recommend that you be using a child-theme. If you’re not, and you’re not sure how to create one, see http://codex.wordpress.org/Child_Themes and What are Parent and Child Themes?
To make the custom template we need for visitor content, open a new document in your favorite text editor. (Do not use a word-processing program like MS-Word for this as it includes additional text formatting that will render your code useless. My +1 recommended text editor is Notepad++.)
Copy the entire contents of your theme’s page.php file to your new document. Then, insert the following code at the top, above everything else (be sure there isn’t a blank line at the top or you’ll wind up with the dreaded “Headers not sent” error when you try to use the template).
<?php /* Template Name: Custom Lockdown */ ?>
Depending on the theme you are using for your WordPress-Buddypress site, there may be a lot of code in there, but your template should look something like this:
<?php /* Template Name: Custom Lockdown */ ?> <?php get_header(); ?> /* A lot of code in here */ <?php get_sidebar(); ?> <?php get_footer(); ?>
Since we don’t want site visitors to have access to any content other than the pages we choose, let’s make it so the sidebar and footer only display when logged-in. We’ll simply wrap the sidebar and footer calls in a is_user_logged_in() conditional, so your template will now look like this:
<?php /* Template Name: Custom Lockdown */ ?> <?php get_header(); ?> /* A lot of code in here */ <?php if (is_user_logged_in()) :?> <?php get_sidebar(); ?> <?php get_footer(); ?> <?php endif; ?>
If, for whatever reason you may have, you prefer to display the sidebar and footer even when logged-out, simply omit the previous step. Remember that if you do, visitors will be enticed to click on links in displayed widgets, and may get frustrated by being constantly redirected to your landing page. (Then again, you could always install a plugin to allow you to control which widgets appear when logged-in and logged-out. See this post for 10 such plugins.)
Save your new document as template-custom-lockdown.php. If you don’t like the template name I’ve suggested, simply change it to something you think is more appropriate. Remember to change the filename too though! Upload your new template to the root folder of your active child-theme.
You should now determine which pages are the only ones you want your site visitors to see. Here are some suggestions (they may not apply to your site):
- About Us
- Privacy Policy
- Terms of Use
- Membership Options
- Features
- Our Mission
- …etc
In your WordPress website’s admin panel, go to “All Pages”. For each page you have selected, click the “Quick Edit” link, select your new Custom Lockdown template in the “Template” drop down menu and click “Update”. You can also use the “Bulk Edit” feature if you prefer.
Once we finish with part 4, those pages will be the only site pages logged-out visitors will have access to on your WordPress-Buddypress site. Of course, they will also have access to register.php, activate.php and wp-login.php. Oh, but wait, we need them to have access to the landing page too, right? Let’s build that now.
Featured Plugin - WordPress Google Maps Plugin
2) Landing page
Here’s where we take advantage of the flexibility of Buddypress components that use WordPress pages. Start by creating a new page to use as your landing page. Give it a welcoming title – maybe something like “Welcome” – add a nice image and a bit of introductory text, and click “Publish”. You do not need to assign the custom lockdown template you made in the previous step (you’ll see why in a bit). The URL for your landing page will be something like this for site visitors: yoursite.com/welcome
In your WordPress admin, go to your Buddypress settings and select the “Pages” tab. From the “Register” page dropdown, select the page you just created and click “Save”. You have now just told your WordPress-Buddypress installation that the page you created is to be used for registration. That takes care of getting the registration form to display on your landing page. Now let’s get everything else to display on that page too.
Copy the Buddypress “registration” folder from your parent theme to your child-theme. From the folder you just copied to your child-theme, open register.php. That is the template that will contain and display all your landing page content. I strongly recommend that you make a backup copy of that file, so just in case things go a bit haywire, you’ll have something to fall back on. You can call it backup-register.php and save it in the same folder.
As we want our landing page to have a similar layout as pages using the custom template we made earlier, remove the following Buddypress code from your child-theme’s register.php file. Remember to remove the corresponding closing div tags near the end of the file too, or things will go haywire!
<div id="content"> <div class="padder">
Next, we want to get the landing page content (your nice image and intro text), the login form, and the “Lost Password” link in there. We’ll be wrapping each of these elements in div containers so we can style ‘em later on. We also want to put the signup form in a special div container so we can style that too. (If you do not want your users to be able to reset their passwords with the built-in WordPress function, simply omit the entire line where you see wp_lostpassword_url.) Add the following code just above where you see <form action=”". Then add a closing </div> tag just after the closing </form> tag.
<div id="my-custom-home"> <?php the_post(); ?> <?php get_template_part( 'content', 'page' );?> </div> <div id="my-custom-login"> <h2><?php _e( 'Login Here', 'buddypress' ) ?></h2> <?php wp_login_form(); ?> <a href="<?php echo wp_lostpassword_url( get_permalink() ); ?>" title="Lost Password">Lost Your Password?</a> </div> <div id="my-custom-registration">
Note that the code above applies to more recent themes that use template parts. If your theme does not use template parts, see the comments below for an easy solution.
The last thing we want to do in register.php is hide the sidebar and footer like we did in our custom template. Replace the calls to the sidebar and footer with the respective code bits below. Again, if you don’t want to, don’t.
<<?php if (is_user_logged_in()) :?> <?php get_sidebar( 'buddypress' ) ?> <?php endif; ?> <?php if (is_user_logged_in()) :?> <?php get_footer( 'buddypress' ) ?> <?php endif; ?>
Save the register.php file and upload it to the registration folder of your child-theme.
Great stuff! We now have our landing page set up with login and registration forms on the page, and a bit of introductory content to boot. We’ve also selected the pages site visitors have access to, and have assigned our Custom Lockdown template to all of those.
Go ahead and test stuff out now to make sure it works properly before we go any further. Be sure you’re logged-out of your site, then navigate to your landing page url. Don’t worry about how it looks just yet. Let’s be sure all the functionality is there first. Done? Good.
Featured Plugin - WordPress Facebook Plugin
3) Logged-out menu
Now let’s create a logged-out menu for your WordPress-Buddypress site with links to all logged-out-authorized pages only. We need to do only 2 things to create the new menu:
- register the new menu in your child-theme’s functions.php file
- call the new menu in the right spot, and under the right conditions, in the child-theme’s header.php file
Open your child-theme’s functions.php file now. If it doesn’t have one yet, create it now (see this page for more on this file in child-themes).
Now open your parent theme’s functions.php file and locate the function that has register_nav_menu in it. It will look something like this:
if ( ! function_exists( 'theme_register_menus' ) ) :
function theme_register_menus() {
register_nav_menu('top_menu', __('Top Menu', TEMPLATE_DOMAIN));
}
endif;
Copy that entire function to your child-theme’s functions.php file. Now copy the line that has register_nav_menu in it, and paste it directly beneath that line. You should have 2 identical lines, one after the other. In one of them – it doesn’t matter which one – change both occurrences of the name of the menu to something you’ll recognize as your logged-out menu (remember to separate words in the 1st occurrence with underscores). Perhaps simply call it Logged-Out Top Menu. Your function should now look something like this:
if ( ! function_exists( 'theme_register_menus' ) ) :
function theme_register_menus() {
register_nav_menu('top_menu', __('Top Menu', TEMPLATE_DOMAIN));
register_nav_menu('logged_out_top_menu', __('Logged Out Top Menu', TEMPLATE_DOMAIN));
}
endif;
Save your functions.php file and upload it to the root of your child-theme. You now have 2 different menus registered in your child-theme. As we are declaring the same function that exists in the parent-theme, it replaces that function (which is why we register the original menu again in the child-theme). If you visit Appearance > Menus in your site’s backend, you’ll see in the Theme Locations box at top-left that Your theme supports 2 menus. See it? Great!
While you’re there, you may as well take a moment to create your new logged-out menu (we’ll get it to display in a moment). Create a new menu and add all the pages you had earlier assigned your Custom Lockdown template to. Also add the page you had earlier assigned for registration in your Buddypress settings – i.e.: your landing page. You may want to give that one an easy-to-recognize navigation label, like Login or Signup. Save your menu, select it for your logged-out menu in the Theme Locations box, and save there too.
Now we want to get that new menu to appear in the right spot in the header, but only display when logged-out. In other words, our new menu will appear when logged-out (your original menu will not be called), and it will be replaced by your original menu when logged-in.
Open your child-theme’s header.php file. If it doesn’t exist yet in your child-theme, simply copy the one from the parent to the child. Search your child-theme’s header.php until you find the call for wp_nav_menu. It will look something like either example below:
<?php wp_nav_menu( array(
'theme_location' => 'top_menu',
'menu_class' => 'topmenu',
'container' => '',
'fallback_cb' => 'theme_fallback_menu'
)); ?>
<?php wp_nav_menu( array('theme_location' => 'top_menu', 'menu_class' => 'topmenu', 'container' => '', 'fallback_cb' => 'theme_fallback_menu')); ?>
Copy that entire snippet and paste it directly beneath so you have 2 identical snippets, one on top of the other. The only thing we want to change here is the value for theme_location in the 2nd one. Locate that value in the 2nd snippet, and replace it with the value we gave to the new menu we created above. In the above example, we called it logged_out_top_menu.
Now we’re going to wrap those 2 menu calls in a conditional so that the 1st one appears only when logged-in, and the 2nd appears only when logged-out. Paste the following code before the 1st menu call:
<?php if (is_user_logged_in()) :?>
Then add this between the 2 calls:
<?php else: ?>
Finally, add the following after the 2nd menu call:
<?php endif; ?>
Your entire code for both menu calls should now look something like this example:
<?php if (is_user_logged_in()) :?> <?php wp_nav_menu( array( 'theme_location' => 'top_menu', 'menu_class' => 'topmenu', 'container' => '', 'fallback_cb' => 'theme_fallback_menu' )); ?> <?php else: ?> <?php wp_nav_menu( array( 'theme_location' => 'logged_out_top_menu', 'menu_class' => 'topmenu', 'container' => '', 'fallback_cb' => 'theme_fallback_menu' )); ?> <?php endif; ?>
We have now registered both a logged-in and a logged-out menu in the child-theme’s functions.php file, have created the new logged-out menu in our site’s backend, and have set up the header.php file so that each menu appears only when the correct condition is met.
Featured Plugin - WordPress Membership Site Plugin
4) Redirect function
Now it’s time to create the function that will ensure that site visitors – i.e.: logged-out – will be able to access only the pages we have added to our new logged_out_top_menu, our landing page (register.php), as well as activate.php and wp-login.php (for password recovery).
Open your child-theme’s functions.php file again. Paste the following code directly after the opening <?php tag:
add_action( 'wp', 'custom_lockdown_redirect', 3 );
function custom_lockdown_redirect(){
global $wp;
if (!is_user_logged_in()){
if ( bp_is_activation_page()
|| bp_is_register_page()
|| is_page_template( 'template-custom-lockdown.php' )
|| ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php' )))
)
return;
bp_core_redirect(get_option('siteurl') . "/welcome");
exit;
}
}
If you have used the example filename I gave above for the Custom Lockdown template (template-custom-lockdown.php), and the example page slug for the landing page (welcome), the redirect function will work as-is. If you have changed those in any way, you will need to edit the above function so it contains the proper names.
Once you have edited the function with your file and page names (if necessary), save your functions.php file and upload it again to your child-theme. To test the function, be sure you’re logged-out of your site. If you’re already logged-out, simply refresh the page (you may need to clear your browser’s cache also). If all is well, you should see only your logged-out menu appear in your site’s header.
Click each link to be sure you can get to it when logged-out. Now try to get to any other page or url on your site. You should be redirected to your new landing page. Fun, huh?
Featured Plugin - WordPress Wiki Plugin
5) Make stuff look good
Now for the final bit: let’s add a bit of simple css magic to make your WordPress-Buddypress landing page look snappy! If you have used the example names I gave for the wrapper divs in part 2 (Landing page), the following css will pop your landing page right into shape. Add the following to your child-theme’s style.css file. (If you’re using a theme from WPMUdev.org, you’ll likely want to edit the _inc/css/child-style.css file instead.)
/*LANDING PAGE*/
#my-custom-home {
float:left;
}
#my-custom-home .post-body img{
max-height:212px;
width:auto;
}
#my-custom-home h1.post-title, #my-custom-home .post-meta {
display:none;
}
#my-custom-login {
float:right;
background:#eee;
padding:1em;
}
#my-custom-registration {
float:left;
width:100%;
}
#my-custom-registration h2 {
background:#eee;
margin:2em 0 0.5em;
padding:0.5em;
}
Save your style.css file and upload it to your child-theme. Now, still logged-out of your site, refresh your landing page and everything should pop right into shape as in the example image at the top of this page. Here it is again just for convenience.
If you’re using a responsive theme, you may want to tweak things a bit to get the landing page looking all nice and pretty on smaller devices. If you’re not sure how to write specific style rules for various devices and capabilities, check out this great article from SmashingMagazine.com, or search Google for how to use css media queries.
I hope you enjoyed this tutorial on building a members-only WordPress-Buddypress site, and find use for it! If you need any help with any part of it, or want to show off the results of your efforts, please leave a detailed comment below (with a link to your site if possible). Thanks for reading!
Photo credit: Flickr.com
Epic post Patrick, good stuff :)
Glad you enjoyed it! This is the kind of stuff I just love to write, so it’s a win-win :-)
this is greate, but i cant find the “register_nav_menu’ my parent theme’s functions.php . for some reason it is not there. i am using buddypress.Version 1.5.7
Please any help
Hi Anaske,
What theme are you using?
Can you post a link to your site?
hi there. i have one big problem. i followed your step by step but the page cannot load. i dont know what i did wrong. check my site http://campusspage.com/ thanks
Heya Campuss Page,
You’re gonna have to be a bit more explicit than that. Just saying the page cannot load doesn’t tell me anything.
Which page doesn’t load?
Do you get any error messages in the browser?
ok, my bad. i didnt give all the info. first am using a bp child theme called bp columns. i didnt find the “root file” so i just created one by just inserting a new folder. when i insert all the other codes to where you said, i get a reply from google chrome saying the page cannot load since it has resulted to too many redirects so i have to clear the cache and even when i do so, no thing happens. i had to remove the child theme and re install it afresh. i also have another issue disterbing me. my site is a social networking site but cannot be seen through the phones. i have tried the wordpress mobile sites but nothing is happening. i have tried dudamobile but i cant be able to set it up so that visitors can directly be redirected to the login form instead of what is showing. do you have any idea on hat i can do so that my site can be mobile? i would also like it to show activity stream just like facebook and tweeter. you can check my site to see what i mean.
hi there. i was still waiting for the answer. i have changed the child theme to frisco and it is helping me with the mobile issue but the loading speed is slow and when someone trie to access it through the mobile, it gives a warning that only admin is supposed to use the mobile site.
This is just amazing!!! I 100% agree with James, EPIC POST!!! :D
Hiya Juanma,
If you do use the techniques in this tutorial, please come back and add a link to your site. :-)
Hi Patrick, i dont know if you have been seeing my messages. i am now using the frisco theme to see if the mobile issue can be solved. luckily it has but not all of it. the problem is finding the ‘page.php’ file which isnt there. i dont know what i can do about it. do you have any clue how i can design a nice landing page just like the one you have discussed here using my frisco theme?
Our team built our company’s intranet with buddypress and are getting ready to launch.
Reading this post makes me consider making a few changes however. We currently use Private BuddyPress and My Brand Login plugins for “lockdown”.
Using Patrick’s methods would provide a friendlier introduction, but I wonder how the registration would work. I was hoping to use Invite Anyone, but in combination with Private Buddypress the process gets interrupted.
My plan B is bulk importing the members, but then the members cannot choose their passwords.
Anyway, thank you for the post Patrick!
Hi Kobus,
Because we’re using register.php as the landing page template, the registration process is not interrupted, and works as it was designed to. So, no worries there.
The Invite Anyone plugin should also work fine with this method.
As for bulk importing members, yes, they can choose their passwords. Instruct your members (perhaps in a welcome email) to reset their given passwords in their BuddyPress profile once they have logged in with the passwords you give them.
Another option you may want to consider for branding the wp-login page is WPMUdev’s own super-simple Login Image plugin: http://premium.wpmudev.org/project/login-image/
Hope this helps!
I’m geting a browser redirection issue and plus my welcome text and image doesnt show up on the registration page
Hi Aliyah,
What browser issue are you getting? Can you be more specific?
If your text & image don’t show up, then your theme is probably not using “template parts”. In the code supplied above for the landing page, try replacing…
get_template_part( ‘content’, ‘page’ )
…with this
the_content()
That should clear it up.
1) The redirect error I get is the same one you get when trying to access a page which is redirecting improperly.
2) I’m using “Custom Community” and changing to your suggestion yielded no results. I simply cant get anything to show up on the login page.
I have to add all of this in order to get my content to display:
post_content;
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]>’, $content);
echo $content;
?>
Sorry, didnt show up above. I have added this to get my content showing:
post_content;
.content = apply_filters(‘the_content’, $content);
.content = str_replace(‘]]>’, ‘]]>’, $content);
.echo $content;
?.>
Any easier way to do this?
Aah forget it. Sorry about the other comments. You should delete them as they look annoying. Anyhow, Ive got this working so far. Thanx!
Glad you got it sorted!
I’m off to the country for the weekend where I only have a maddeningly slow dial-up connection, so if you need more help, I may not be back online until Sunday evening.
Have a great weekend!
Hi, that was a great tutorial. I have a question though, since my network allows users to make their own blogs. Can I lock visitors out of BuddyPress streams, profiles, etc, but not out of visiting blogs?
Hi!
The redirect function, as given above, will lock visitors out of your main site only. They will still have access to sub-sites in your network.
Hope this helps! :-)
Thanks, Patrick. But I’m having another issue. I’m using Balance and nothing about Navigation appears whatsoever in functions.php so I am having trouble with step3) Logged-out menu
If you mean the Balance theme by StudioPress, then that would be a child-theme of the Genesis Framework, right?
So, then you need to look in the functions.php file of the parent theme (Genesis) for the register_nav_menu function. Copy that entire function to the child-theme (Balance) functions.php, and make the mods as in Step 3 above.
Should get you going. :-)
Balance by PressCrew. Just came out. It’s made on Infinity.
Ah! Infinity is a whole other beast entirely. Infinity has a rather novel design and nav menus are registered and defined in ways that I’m not too familiar with.
Your best bet would be to contact Marshall or Bowe directly through their support forums: http://community.presscrew.com/discussion/premium-plugins/
Ask them how to register a new, logged-out-only main-menu in the Balance child-theme. Give them a link to this page so they can fully understand what you are trying to accomplish.
Hope that helps! :-)
For any Infinity or Balance users who happen upon this comment, Patrick’s tutorial is 100% compatible with our themes. Although we do some tricky stuff internally, there is nothing stopping you from customizing the themes using standard WordPress API functions, just like Patrick has done here. In fact, we call the exact same API functions behind the scenes.
Really great tutorial Patrick! And thank you for fielding questions about our themes. Very professional! :)
@patrick cohen
I asked, they never paid attention to it, so who knows. I will probably switch themes since I am unable to update Balance without erasing absolutely everything of the theme from my directory.
I’m surprised that they didn’t answer your query. Once you find another theme that suits you, please let me know if you need more help. I’ll gladly try to walk you through any difficulties.
:-)
probably got lost in the amount of posts in the forum. I’ll try again later.
In the meantime, I’m still using Balance.
I have a question about this on the forums..because the functions file for infinity is not the same in balance and I wasn’t able to complete the customization. Aside from that, even if I had, the way I had to update the theme by erasing everything and reinstalling, I’d have to do it all over again now.
Hi There,
I think you are a bit confused on how the update process works. When a new version of Balance comes out you can just upgrade the parent theme and keep all the changes you have made in your child theme. This is exactly why we ship all of our themes with a pre-made Child Theme. If you implement Patrick his tutorial in your child theme there is no way of losing your changes during updates :-)
Just make sure to copy over the templates to your child theme and not make any changes to the parent. So if Patrick says “Edit header.php”, first copy over “header.php” to your Balance Child theme and then make the according changes.
Regarding us not paying any attention to your support question. I’m sorry you feel that way, but we do try to handle support as quick as possible while still implementing new features and bug fixes based on community feedback. Sometimes this means you’ll have to wait a little longer before we can look at these requests.
@Patrick: Really cool to see you posting these tutorial here on WPMU. This is a common request and this is a solid write-up. Cheers!
Bowe, please look at step 3 – logged out menu. It asks to copy functions.php. but functions php is very small in Balance. so it doesn’t work with these instructions.
Patrick does not say to copy the entire file. He says to copy part of the functions.php ie; the register menu function. Like I’ve told you on our support forums all the above can be achieved by following the tutorial. If you get stuck you can always ask a developer to do it for you. It just falls outside of the theme support we normally do.
That being said I’ll try add this functionality to our themes in the future, so you can enable a logged out menu from your theme options page :-)
@Bowe @Marshall
I had loads of fun with Infinity last year when I bought a test copy to play with. But I do have a bit of difficulty getting my head around the “tricky stuff”, specifically the Walkers (don’t understand that bit yet as I still consider myself a php n00b).
And thanks for the compliments guys. Coming from 2 designers who do command respect in the WP arena, it’s high praise indeed :-)
Hi Patrick,
Thanks for the great post! One place I am stuck at is the logged out menu. The snippets”register_nav_menu” you have us search for don’t exist in my functions.php file. All I see that is similar is:
if ( !function_exists( ‘bp_dtheme_page_menu_args’ ) ) :
/**
* Get our wp_nav_menu() fallback, bp_dtheme_main_nav(), to show a home link.
*
* @param array $args Default values for wp_page_menu()
* @see wp_page_menu()
* @since BuddyPress (1.5)
*/
function bp_dtheme_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( ‘wp_page_menu_args’, ‘bp_dtheme_page_menu_args’ );
endif;
Any ideas? I am using buddypress 1.6
oppps. Wanted to paste this code:
if ( !function_exists( ‘bp_dtheme_main_nav’ ) ) :
/**
* wp_nav_menu() callback from the main navigation in header.php
*
* Used when the custom menus haven’t been configured.
*
* @param array Menu arguments from wp_nav_menu()
* @see wp_nav_menu()
* @since BuddyPress (1.5)
*/
function bp_dtheme_main_nav( $args ) {
$pages_args = array(
‘depth’ => 0,
‘echo’ => false,
‘exclude’ => ”,
‘title_li’ => ”
);
$menu = wp_page_menu( $pages_args );
$menu = str_replace( array( ”, ” ), array( ”, ‘‘ ), $menu );
echo $menu;
do_action( ‘bp_nav_items’ );
}
endif;
Hiya Mark,
I see you’re using the bp-default theme (I hope you are using a child-theme though!).
The code you’ve shown above is for the fallback menu that displays in case no custom menus have been set up in your WP backend (i.e.: it displays default pages such as Activity, Members, Groups, etc.).
You should see a line in functions.php BEFORE that code that looks something like this:
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
‘primary’ => __( ‘Primary Navigation’, ‘buddypress’ ),
) );
That code is part of the following function:
function bp_dtheme_setup()
You’ll need to copy that entire function to your child-theme’s functions.php file from
function bp_dtheme_setup() {
…all the way to
add_action( ‘after_setup_theme’, ‘bp_dtheme_setup’ );
Then modify the register_nav_menus part like this:
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
‘primary’ => __( ‘Primary Navigation’, ‘buddypress’ ),
) );
register_nav_menus( array(
‘logged-out’ => __( ‘Logged-Out Navigation’, ‘buddypress’ ),
) );
Then, modify the call to wp_nav_menu in your child-theme’s header.php file as per the instructions in the tutorial.
Hope this helps! :-)
Thanks Patrick! That worked perfectly. I am close….but i added the redirect function and i am now getting infinite redirect loop error. I know this is a tough error to figure out…any guesses? I followed your naming convention.
Thanks,
Mark
Hi Mark,
Sorry for taking so long to get back to you on this.
Do you have any plugins activated on your site that perform any kind of redirect when logged out? There may be a conflict.
Try removing the following snippet from the redirect function. We’ll work from there. Doing so should redirect logged-out users to your welcome page no matter what.
if ( bp_is_activation_page()
|| is_page_template( ‘template-custom-lockdown.php’ )
|| ( in_array( $GLOBALS['pagenow'], array( ‘wp-login.php’ )))
)
Thanks for the reply Patrick. So i commented out those line and the error goes away.
Also tried rebuilding a new site that had just wordpress and buddypress and followed the tutorial again and I arrived at the same error. Any ideas what would cause this?
Hi Mark,
We’re off to a good start here. Without the conditional pages in the redirect function, you’re redirected to your Welcome page when logged-out, right? That would indicate that the problem is with one or more of those conditionals.
The first thing that comes to mind is: be sure you have NOT assigned the Custom Lockdown template to your Welcome page. That would definitely cause a redirect loop.
Also, be sure that template is NOT used on whichever page you have assigned to the “Activate” page in your BP settings… might confuse WP, ya never know :-)
Lemme know how that goes :-) (Gotta get to work now!)
Actually no it’s not redirecting to the welcome page. I can access the welcome page but its redirecting to the root of the domain or http://www.example.com.
To remove all complications I am doing this on the clean install with only buddypress and wordpress installed. The only pages are the default ones. So custom lockdown is only assigned to “Sample Page”.
The redirect sends us to the “home” page where the “Hello world” post is. Before you have us set up the menu in step 3, “home” shows up as a tab (I deselected it from the primary and lockdown menu).
Thanks,
Mark
Update: So figured out how to get it to redirect to welcome when the code is commented out. Hadn’t set this instance to have a static home page rather than last post.
Still can’t get the redirect loop to work however.
So I have done quiet a bit of trouble shooting and here is what I have learned:
1. When I comment out the 4 lines you recommend above the redirect error goes away and i am taken to the site home page (whatever is configured at Settings>Reading>Static Page). If I set this to welcome it loads fine. I did notice when it loads its loading purely http://www.example.com not example.com/welcome. Which leads me to believe the If user is not logged in function is not being evaluated (yep I’m logged out triple checked) or the return redirect piece is failing.
2. Checked the pages for registration (in this case welcome) and activation and both have the default templates applied.
3. Tried switching the redirect function to the wordpress core one with the same infinite redirect error.
4. Removed the first if (if is not logged in) and i get the same redirect error.
Any ideas? Am I missing something? Thanks for your help.
The theme I am using has a welcome/home page template to seduce registrations. So, I would like to use what exists and go from there. Problem is the page shows up even once you’re logged in, which I don’t want.
Hi Mark,
Good debugging! Here are my suggestions:
1) Configure Settings > Reading to any page OTHER than your welcome page. This can be any other page and can use any template because it will only be called when the user is logged in. (Whichever page you set here, the url will always be http://www.example.com) Then add the bp register page to the list of allowed urls in the lockdown function as follows:
add_action( ‘wp’, ‘custom_lockdown_redirect’, 3 );
function custom_lockdown_redirect(){
global $wp;
if (!is_user_logged_in()){
if ( bp_is_activation_page()
|| bp_is_register_page()
|| is_page_template( ‘template-custom-lockdown.php’ )
|| ( in_array( $GLOBALS['pagenow'], array( ‘wp-login.php’ )))
)
return;
bp_core_redirect(get_option(‘siteurl’) . “/welcome”);
exit;
}
}
2) You could try modifying the redirect with either of the following:
bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );
bp_core_redirect( $bp->root_domain .’/’. ‘welcome’ );
Hope this helps! :-)
Thanks Patrick. Adding bp_register to the function did the trick!
Great! I’ve updated the post and added it to the function in the tut.
Glad you got it worked out… have fun! :-)
Hi נופיה שם טוב
Can you provide a link to your site so I can get a better feel for what you’re trying to do?
sure, blogmylunch.com.
The front page of the site is already ok. The problem is that I don’t want people going back to it once they’re logged in. I’d rather they go to their BuddyPress wall or to the blog.
Have you tried the BuddyPress Login Redirect plugin?
http://wordpress.org/extend/plugins/buddypress-login-redirect/
@blog my lunch, put this in your function
/*Buddypress profile as homepage */
function bp_profile_homepage()
{
global $bp;
if(is_user_logged_in() && bp_is_front_page())
{
wp_redirect( $bp->loggedin_user->domain );
}
}
function logout_redirection()
{
global $bp;
$redirect = $bp->root_domain;
wp_logout_url( $redirect );
}
add_action(‘wp’,'bp_profile_homepage’);
add_action(‘wp_logout’,'logout_redirection’);
The above code will make your site Home to be current user personal activity.
In step two you instruct us to remove the following Buddypress code from the child-theme’s register.php file:
I do not see anywhere in the register.php file. However I do see . The file I am using is register.php originally from /public_html/mysite.com/wp-content/plugins/buddypress/bp-themes/bp-default/registration
What am I doing wrong here? I am running WP 3.4.1, and BuddyPress 1.6.1
Ok, the code from my above comment was removed. I’ll try this again:
In step two you instruct us to remove the following Buddypress code from the child-theme’s register.php file:
..
..
I do not see .. anywhere in the register.php file. However I do see . . The file I am using is register.php originally from /public_html/mysite.com/wp-content/plugins/buddypress/bp-themes/bp-default/registration
What am I doing wrong here? I am running WP 3.4.1, and BuddyPress 1.6.1
Ok, one more time!
In step two you instruct us to remove the following Buddypress code from the child-theme’s register.php file:
div class=”content”
div class=”padder”
I do not see div class=”content” anywhere in the register.php file. However I do see div id=”content” . The file I am using is register.php originally from /public_html/mysite.com/wp-content/plugins/buddypress/bp-themes/bp-default/registration
What am I doing wrong here? I am running WP 3.4.1, and BuddyPress 1.6.1
Hi Paul,
Having trouble posting code I see ;)
You are absolutely right though; div class=”content” doesn’t exist… my bad. Typo corrected. Thanks for spotting that!
The correct instructions are to remove the following:
div id=”content”
div class=”padder”
… as well as corresponding closing tags, of course.
Thanks Patrick … I thought for sure I was doing something wrong since no one else mentioned it. Thanks for the correction.
Stuck on step 3. Your instruction: open your parent theme’s functions.php file and locate the function that has register_nav_menu in it. It will look something like this: (code omitted)
What is the path to the correct parent theme functions.php?
I’ve looked at the one located in the root at /public_html/mysite.com/wp-content/plugins/buddypress/bp-themes/bp-default/functions.php. There’s no matching code for register_nav_menu in this file.
Hi Paul,
Mark asked that very same question above, and it was resolved in this comment:
http://wpmu.org/how-to-build-a-facebook-style-members-only-wordpress-buddypress-site/#comment-137111
Hope it helps! :)
One thing to point out about an item in Step 3, your instructions: If you visit Appearance > Menus in your site’s backend, you’ll see in the Theme Locations box at top-left that Your theme supports 2 menus. See it? Great!
You will not see a Theme Locations box unless you actually have a menu created. So, if the box is not there, create a test menu … then the Theme Locations box will show & you’ll then be able to see that your theme supports 2 menus.
I’m so close! Everything is working, but I’m having trouble with the landing page format. I used your fix above: replacing… get_template_part( ‘content’, ‘page’ ) …with this: the_content()
Right now my Image and welcome text is on the left, the form is in the center and the “Login Here” box is on the right. UNLIKE your screen shot where the form is underneath your welcome image and welcome text and login box. Any Ideas? css?
Also do you have your site on line so I can inspect the elements and compare to mine?
Found your site at kwitterz.com… But still working on the formatting problem.
Hey Paul,
Sorry I didn’t get back to you sooner on this; was offline for the weekend.
Do you have a link to your site so I can take a look? If not, can you post a screenshot of what you have now, and let me know what theme you’re using?
I’ll see if I can help you over this last hump :)
I am using the BP Default theme (with a child theme). The site address is [removed by request].
Hi again Paul,
Thanks for the link. I see where things screwed up (my bad again, dammit).
I had indicated the wrong place to insert the my-custom-home, my-custom-login and my-custom-registration divs. All 3 should be inserted one after the other, right before the registration form.
I’ve updated Step 2 above to reflect this (I’m surprised no else reported it). You should be good to go with the rest. ;o)
It Works! Thank you.
Please remove my web site address from my previous post. Thanks a bunch.
You know what would be the cherry on top … If I could force new registrations to require an administrators approval before granting access to the site.
If you know of a way to do that then all my problems would be solved.
Hi Paul,
Glad we got everything sorted; looks good!
Your address is removed.
For new user approval, try this: http://wordpress.org/extend/plugins/new-user-approve/
Also, if you’re going to be using the child of bp-default for your site, you may want to put the content and padder divs back in to your register.php template.
Again, glad it worked out and, keep on having fun!
I am using the default BP theme (with a child theme). Site address is
j o b s – g r o u p . c 0 m
I have a Problem with Step 2. I am using BuddyBoss Theme, but I am interested on implementing This Idea. The Problem is the registration code of buddyboss seems different, so I am a bit confused where to insert the codes… My Website name is ROYALTWEET
I have already completed Step 1.
Hi Lesego,
I don’t own a copy of BuddyBoss, so I can’t see the actual code in the files. But I took a look at your registration page in Firebug: http://www.royaltweet.com/welcome-to-royaltweet/
It looks like the code for Step 2 above would be best inserted just before
div id=”login”
…form stuff here…
/div
Don’t forget to add a closing div tag after the closing tag for the “login” div.
Hope this helps! :)
Thank You For The Previous Reply
I have an issue In locating Codes. So I found it not appropriate to paste all codes here, I guess it will look ugly having long codes here, so I pasted on a notePad and Uploaded on ROYALTWEET
URL:{http://www.royaltweet.com/?attachment_id=293}
Step2.Landing page
In BuddyBoss I can not locate this two codes’ so It is way to hard for me to change the layout
3) Logged-out menu
And I am trying to lacate bellow code… Its way different too
if ( ! function_exists( ‘theme_register_menus’ ) ) :
function theme_register_menus() {
register_nav_menu(‘top_menu’, __(‘Top Menu’, TEMPLATE_DOMAIN));
}
endif;
Hi again Lesegõ,
Sorry, the link you posted to view the code on your site results in an endless redirect so i can’t see it. Could you post the code you’re having trouble with to http://pastebin.com/ instead?
For the logged-out menu, all you really need to locate is the line where you see register_nav_menu. Copy that line, paste it again immediately below, then change the menu name in the one you just pasted.
Thanks again.
I have pasted Functions.PHP & Register.PHP Codes, Paste Name: Codes. Functions.php & Register.PhP
After pasting register_nav_menu. I am geting a Syntax Error.
“Parse error: syntax error, unexpected ‘<' in /home/lkckeid0/public_html/royaltweet.com/wp-content/themes/buddyboss/functions.php on line 117"
this is what I did:
________________________________________________________
register_nav_menus( array(
‘primary-menu’ => __( ‘Primary Menu’ ),
‘secondary-menu’ => __( ‘Footer Menu’ ),
‘profile-menu’ => __( ‘Profile Sidebar’ ),
‘group-menu’ => __( ‘Group Sidebar’ ),
) );
register_nav_menus( array(
‘primary-menu’ => __( ‘Primary Menu’ ),
‘secondary-menu’ => __( ‘Footer Menu’ ),
‘profile-menu’ => __( ‘Profile Sidebar’ ),
‘group-menu’ => __( ‘Group Sidebar’ ),
) );
I also added IF or Else Statement
@lesego – if you are cutting and pasting from this tutorial to your code editor, you might want to check to make sure that the straight quotes are not pasting on your side as curly quotes. For example ’ instead of ‘
You want the latter – straight quote ‘, and not the curly quote ’
There is a difference inside a code editor and that can be throwing you off. Double check to see if that clears it up.
I have Managed To Create a Registration Page and its working… But I am still having some Issues On Registration Form Layout, and Hiding other pages from Unregistered Users. [http://www.royaltweet.com]
@Lesegõ
What exactly would you like to do to the layout? Can you create a mockup of what you’d like, upload it to a sharing site like tinypic.com and post a link here so I can see what you’re looking for?
What issues are you having with hiding pages from unregistered users?
Thank You For Your Response.
I was thinking maybe I could rearrange textBox Horizontally , three on the left and two right with left alignment, so it is giving me a hard time to do it, if you could go to the website and click submit on a registration form you ll see that there is a problem with the layout form… I am not sure whether its the container or what…
Another thing, how do i add text on the left of the loginForm, just like The Picture you shared? [www.royaltweet.com]
I have uploaded an image i hope you can see it, i used free hand drawing
http://tinypic.com/r/tz2w9/6
@Lesegõ
You can’t really put only 3 input boxes on the left and 2 on the right because 4 of them are in the basic-details-section div container. So, to put basic details on the left, and profile details on the right, add the following to your style-sheet:
`
#my-custom-registration form.standard-form #basic-details-section,
#my-custom-registration form.standard-form #profile-details-section,
#my-custom-registration form.standard-form #blog-details-section,
#my-custom-registration p.signup-submit {
clear:none;
float:left;
margin:10px;
width:48%;
}
`
I highly recommend learning how to use your browser’s developer tools to inspect page elements. It will make CSS customization a lot easier for you :)
To get some welcome text in there, please review 2) Landing page. You simply add whatever you want to the page you selected as your landing page (welcome-to-royaltweet).
Hope this helps! :)
It works. Almost everything works. But i think something is still missing and i dont know what it is… The registeration form looks a bit awkward, if you click on submission button without filling up your details, the error lines and text boxes looks weird. :-O
I was thinking maybe i could resize textbox to suit the container but my coding skills is a bit lacking
@Lesegõ,
You’re quite right. I forgot to include the CSS for your text boxes in my previous reply, sorry. Add the following to your style-sheet; it should get the text inputs nicely re-sized, and aligned with the error messages.
#my-custom-registration form.standard-form #basic-details-section input[type="password"],
#my-custom-registration form.standard-form #blog-details-section input#signup_blog_url,
#my-custom-registration form#signup_form.standard-form input[type="text"],
#my-custom-registration form#signup_form.standard-form textarea {
width:90%;
}
Hope this helps! :)
Perfect!!
It works. Thank you very, very, much.
Now wpmu is my home. :-)
Welcome home!
:)
I have a slight problem, which i have been trying to fix lately, my registration page footer is centred it does not fit the page widely, it cuts at ends… How do i make it fit the page fully?
Hi again Lesegõ,
If you want to make your footer extend the full-width of the screen like your navigation bar, try adding the following to your style-sheet:
#footer {
position:absolute;
left:0;
}
Hope this helps! :)
Thank you once Again.
It didnt work, so i came up with a simple solution, i changed the colour to make the footer look like body and background just making thing look a bit even. But I am still strangling on putting a welcome text. I have been try to follow exactly what you provided there, but i don’t know what i am missing on your steps.
Hi Patrick, superb post! It’s the only one out there to help Buddypress developers.
I have a quick question:
I’m using a child theme and at the end of step two I have successfully set up the new custom registration page and changed the settings in BP > Pages to make this the default registration page.
My big problem is that if I log out and navigate to the home URL I still get the full home page, and I’m able to access all the content.
Does this mean that my child theme is using a page other than page.php as its landing?
Any advice gratefully received! Thanks again.
Tom
Hiya Tom,
Thanks for the kind words!
As for your question: keep going, all that is covered by Step 4: Redirect.
:)
Hi Patrick,
This is a great article. On my first try is didn’t work, but before I continue I have a question. Does these steps conflicts with the wpwu-membership software?
I got here through your advice from
http://premium.wpmudev.org/forums/topic/different-homepage-for-logged-in-users-and-logged-out-visitorsuser#post-288547
Hi Patrick,
I tried hard to make your tweaks working with membership. I had no problem with just buddypress. The problem started when I turn membership on. There is a conflict between Membership registration and the buddypres registration. I found a solution and it is easy:-)
You only need to go though step 1 and step 4 – the membership software take care of the rest.
Explanation:
In step 2 membership have the landing page and take care of registration.
Step 3. You design menu outside in membership.
Step 4. The edit membership form in css, if needed.
Oh. This took some time to figure out. So here have it.
Regards,
Peter
Hello Peter,
Sorry I didn’t reply to your first request; I must have overlooked the email Notification :(
Congratulations on figuring out how to make this work with Membership!
Could you post a link to your site so others can benefit from your expertise too?
Hi Poul,
Yes, here is the link to my site: http://www.trylleskolen2.dk/forsiden/. This is just a test-URL. I already have more than 3500 members on my old membersite, so I have to be sure everything is working perfect before launch and when it is ready I’ll write the URL here.
The registration-page is http://www.trylleskolen2.dk/start The visitors will not see Memberships-registration-page anywhere. On the homepage there will be links to two different levels – one the free access level and one for the paid level. Another visitors get to the last part of the registration-process: ?action=registeruser&subscription=2
Figuring out membership is a puzzle, but when you get a hang of it, it is absolutely brilliant. And your tweaks on this blog are very useful and cool. You should get them in the membership-manual.
There was a typo…Last sentence , second paragraph.
in other words visitors get access to the last part of the registration.
My best Christmas gift this year will be having Patrick to clean up all the steps and provide the respective customized files for Frisco BP child theme where all I do is copy and paste ;)
First of all, thank you so much! I’m building a community learning platform for a non-profit and this was exactly what I needed. I’ve learned so much from this post alone.
I’ve seem to have everything working, except for one thing. After step 4 every single page redirects to welcome.html. I’m using a child theme for buddypress default them and have followed the function exactly. The logged out nav bar does show up…it’s that when you click on the any of the links they redirect to welcome.html. I’ve tried changing the pages to several default templates and it still doesn’t seem to be working. Any thoughts would be greatly appreciated.
Hiya Z!
Glad you found this educational :)
Did you assign your custom lockdown template to each page accessible to logged-out users? Trying to access pages using any other template will result in being redirected to your welcome page.
wow. thank you! I somehow had it backwards. Where everything with the template would be private. I also had a – instead of a _ in the code. Thank you again!
Hi Patrick this is exactly what I was looking for. Is there any way to do the password reset on the same page rather than going to the WordPress password reset page?
I have the site localized in different languages and the WordPress password reset page can only be shown in the default language which is a problem.
Hi Hamed,
You might find the Profile Builder plugin handy for that. It has, among other things, a shortcode you can use to display the password-recovery form wherever you need it:
http://wordpress.org/extend/plugins/profile-builder/
To execute any shortcode in your register.php template (or any other), use the do_shortcode function:
http://codex.wordpress.org/Function_Reference/do_shortcode
Hope this helps!
Hello Patrick . I need help… I have created a separate page ( not login.php or register.php) which i am using as a front page…
With the help of custom-locked-down template. Everything is just perfect excepted one thing, I want the page to be accessed by logged out users only.
With the custom-locked-down the logged out user will be redirected to the front page, is there a way to modify the code, just that when you are logged in and try to access the front page you ll be redirected to somewhere else. [RoyaltweetDotCom]
Hi Lesegõ,
Try adding this to your functions.php file. Change frontpage-slug-here and redirect-to-slug-here to the slugs of your actual pages. Should do the trick.
add_action( 'wp', 'custom_loggedin_redirect', 3 );function custom_loggedin_redirect(){
global $wp;
if (is_user_logged_in() && is_page('frontpage-slug-here'));
bp_core_redirect(get_option('siteurl') . "/redirect-to-slug-here");
exit;
}
Thank you for you response,
This is what i did:
add_action( ‘wp’, ‘custom_loggedin_redirect’, 3 );
function custom_loggedin_redirect(){
global $wp;
if (is_user_logged_in() && is_page(‘siteurl’));
bp_core_redirect(get_option(‘siteurl’) . “/home”);
exit;
}
It is not redirecting properly, infect, it seems like every pages is redirecting to home… And i get too many redirect message on a browser
Hi again Lesegõ,
The code you show above is definitely not going to work. The way you’ve entered these lines:
if (is_user_logged_in() && is_page('siteurl'));bp_core_redirect(get_option('siteurl') . "/home");
…you’re telling the browser that, no matter where the logged-in user is on your site, redirect him to “/home”, even if he’s on the homepage; infinite redirect.
In the code I gave above, change frontpage-slug-here to the slug of the page you set as your not-logged-in homepage.
Then change redirect-to-slug-here to the slug of the page you want to redirect logged-in users if they try to access your not-logged-in homepage.
If you’re not sure what those page slugs are, go to the “All Pages” screen in your wp-admin and click the “Quick Edit” link for each of those 2 pages. You’ll see a field labeled “Slug”. That’s what you need to change in the code.
Again, thank you for your response. The same thing is happening. My front page slug is welcom with with url (‘sitename’) with is the main domain and my home page slug is home… With url “/home”)
i even tried to use: [ if useer logged in and page template is custom locked down, then redirect to home] i am still geting many redirect massage in the webbrowser.
Could you post here the exact URL of both pages please? Like this:
Logged-out users front-page = http://royaltweet.com/???
Logged-in redirect to = http://royaltweet.com/???
Replace the ??? with the actual page slugs.
Front Page:[ http://www.royaltweet.com or …/welcome
Home Page: [ http://www.royaltweet.com/home
Register Page: …/register
LoginPage: … /wp-login.php
____________________________________________
The front page has only a welcome text and a trigger hiden logIn no navigations, So when you login it pretty much working and redirect well to profile, but when you type or you go back to the front page you will access it, which is not something i want, because you are already logged in you shouldnt be able to access front page… It wouldnt be nice for user to fall on a page with just lil text and no navigations.
I thought may be i could block the page from logged in user and safely redirect to… “/home”
So i came up with this
add_action(‘init’, ‘block_page’);
function block_page(){
if ( is_user_logged_in() && is_page(‘welcome’) );
wp_safe_redirect(get_option(‘siteurl’) . “/home”);
}
and got too exited then i realised it is falling back. Infect it redirect every url on my site to home except user profile . It worked first time after clearing browser cookies, then back to the same problem again… I cant also access register page and wp-login …
This function should work fine. The problem with the code you had originally tried was is_page(‘siteurl’). The presence of siteurl in that line effectively told the browser to redirect every page to home when logged-in. You only want the welcome page to redirect to home when users are logged-in.
add_action( 'wp', 'custom_loggedin_redirect', 3 );function custom_loggedin_redirect(){
global $wp;
if (is_user_logged_in() && is_page('welcome'));
bp_core_redirect(get_option('siteurl') . "/home");
exit;
}
This
add_action( ‘wp’, ‘custom_loggedin_redirect’, 3 );
function custom_loggedin_redirect(){
global $wp;
if (is_user_logged_in() && is_page(‘welcome’));
bp_core_redirect(get_option(‘siteurl’) . “/home”);
exit;
}
Is causing the same multi redirecting problem. Browser Can not open the page
@Patrick Cohen
I really want to do this, but there is also a great landing Homepage template for the theme I’m using. The question is, is there a way to put the Registration and Login and Lost Password forms on it?
The page has its own template called home or something similar.
The site is blogmylunch.com
I want to have something similar to what the Twitter front page used to be, that shows site activity, but then once someone is logged in I want to send them to their page, like on Facebook.
Nofia
Hi Patrick,
I cannot get the login fields to show up. What am I doing wrong?
Hi Patrick, i dont know if you have been seeing my messages. i am now using the frisco theme to see if the mobile issue can be solved. luckily it has but not all of it. the problem is finding the ‘page.php’ file which isnt there. i dont know what i can do about it. do you have any clue how i can design a nice landing page just like the one you have discussed here using my frisco theme?
@Patrick Cohen,
Great! I finally got it working functionally but I still have some issues:
1) logged out menu
2) template parts
3) The CSS looks a little too wide and close to the sides as well
http://blogmylunch.com
Nofyah
Hi Nofyah,
You’re using Balance child-theme for Infinity right? I may be wrong, but I don’t think that theme uses template parts. See this comment above for a possible solution:
http://wpmu.org/how-to-build-a-facebook-style-members-only-wordpress-buddypress-site/#comment-136471
I use the plugin Theme My Login and it gives me the login field all in one place. Lost password will not be redirected to wordpress login page by changing the following in your register.php file;
Replace this;
with this;
Have a look friendsworkshop.com
Patrick Cohen
I have the button Login with Facebook.
When I click enter, it returns the same page.
I use Buddypres, here’s what I used in my bp-custom.php
<?php
// **** Privacy ********
function restrict_access(){
global $bp, $bp_unfiltered_uri;
// If user is not logged in and
if (!is_user_logged_in() &&
(
// The current page is not register or activation
!bp_is_register_page() &&
!bp_is_activation_page()
)
) {
// Redirect to registration page. Change /join to your register page slug
bp_core_redirect( get_option('home') . '/wp-login.php' );
}
}
add_action( 'wp', 'restrict_access', 3 );
My website http://www.somdefabrica.com.br Thanks :) Waiting from Brazil \o/
I wish after clicking the sign in with facebook, the user is redirected to any other page.
The snippets”register_nav_menu” you have us search for don’t exist in my functions.php file. All I see that is similar is:
if ( function_exists( ‘register_nav_menus’ ) ) {
// This theme uses wp_nav_menu() in two location.
register_nav_menus( array(
‘logged-in-nav’ => __( ‘Logged in Navigation’,TEMPLATE_DOMAIN ),
‘not-logged-in-nav’ => __( ‘Not Logged in Navigation’,TEMPLATE_DOMAIN )
) );
Can you please help?
Thanks
The snippets”register_nav_menu” you have us search for don’t exist in my functions.php file. All I see that is similar is:
if ( function_exists( ‘register_nav_menus’ ) ) {
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
‘logged-in-nav’ => __( ‘Logged in Navigation’,TEMPLATE_DOMAIN ),
‘not-logged-in-nav’ => __( ‘Not Logged in Navigation’,TEMPLATE_DOMAIN )
) );
Can you please help?
Thanks
Just in case :I am using social-child template
Your theme already has logged-in and not-logged-in menus. So you can skip that whole step. :)
Hi Patrick, I currently use the graphene theme. I tried your code above, however, I’m stuck on the first step. I did exactly like you said by copying/pasting the listed code above BEFORE my themes page.php code. It worked just the opposite by blocking content from logged in users and showing for logged out users. This happened before and after your ‘quick edit step for all pages’. BTW, the following comments were found inside my themes code:
“Run the loop to output the pages. If you want to overload this in a child theme then include a file called loop-page.php and that will be used instead.”
Any suggestions on how to fix this problem? Thanx in advance.
hello
…..
hi,
i can’t find the “register_nav_menu’ my parent theme’s functions.php .
iam using buddypress default theme Version 1.6.2
i just create a new site and installed buddypress in it
The function is on line 84. The instructions at the top of functions.php in the default theme tell you what you need to do: override the bp_dtheme_setup() function in your child-theme, like so:
function bp_dtheme_setup() {register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'buddypress' ),
'secondary' => __( 'Secondary Navigation', 'buddypress' ),
) );
}
Can I do this with wordpress theme.
Please help mee
Thanks.
This is my site
http://www.miralsplet.eu
Or can you send me this theme
Hi Patrick,
I’m using WordPress for a particular project over my preferred CMS, I’m finding your post a great help. It would seem to me that some of what’s done here should be native to WordPress but that’s a different point.
I’m struggling with step 3 here and the register_nav_menu code required from the functions.php file – I’ve looked at 5 themes, including TwentyTwelve and TwentyEleven, and I can’t see the function you reference in any of them. I’m sure I’m missing something but I have downloaded a number of free templates to check, and…I’m still not seeing it (or finding it with a search).
Can you help?
Thanks,
Paul.
In Twenty-Twelve, you’ll find it on line 64 of functions.php. Also see the instructions at the top on how to override the function in your child-theme.
Patrick, this is just a superb piece of tutorial. Thank you so much. I’ve been looking, as I know many have, for a way to lockdown BuddyPress and have found discarded plugins and other detritus which have all been unhelpful. This tutorial, and the tweaks available in the comments, did the trick. I’m also using WPMembers and was able to modify and combine some of the behaviors of this tutorial and that plugin to good effect.
Hi Patrick,
Great tutorial! Everything is working fine for my site http://www.superdogsuniverse.com, except that I can not see the image and text we created for the landing page. I tried your fix replacing…
get_template_part( ‘content’, ‘page’ )
…with this
the_content()
but it is not working, I only see a blank space. I am using a child theme for BuddyCorporate template
Hi Patrick,
Firstly I’d like to thank you for a brilliant post. You’ve done this for free and it’s helped a lot of people with their jobs and projects. Great work!
I’ve used this tutorial to build a landing page for a new version of a social hub we’ve been running for about a year now (which is why it’s not on the URL you’d expect).
The only big problem I have is that since building the landing page the system no longer sends out sign-up confirmation emails or lost password emails.
I know you’re a busy man but in case I’m overlooking something obvious I thought I’d ask if you have any thoughts.
Here’s our test site:
http://www.applausegallery.com/
Thanks for your help,
Tom Addis
Simply customizing the layout of the register.php template should have no effect on the emails.
Please check for any differences between your custom template and your backup copy.
Hi Patrick,
I was directed here by Mercime on BuddyPress. She’s great! First of all, thanks for an awesome post. It’s so clear that I get it. Again, thank you!
I have one quick question though. I’m using BP 1.7 beta 1 and I can’t seem to find the Buddypress “registration” folder from my parent theme. Can you clarify, please?
Yup, Mercime is awesome :)
That folder is in the same place it’s always been:
buddypress/bp-themes/bp-default/registration
:)
Hi Patrick,
I am having some issues. So am I right to assume that template-custom-lockdown.php, should just be
/*
A lot of code in here
*/
Also I am using buddypress 1.7 and using buddypress default in the register.php. I have searched and there is no wp_lostpassword_url. I found the form part. The home page has no changed at all for me. Also the bp-default-child shoule going wp-content/themes folder from what I read bp-default can stay in the bp-themes folder is that correct? thanks
has anyone implemented this into the frisco child theme?
3rd attempt this is killing me. Where would i pay someone to implement this for me haha
This is killing me, i cant figure it out also. Have you figured it out yet?
I cant find the
“if ( ! function_exists( ‘theme_register_menus’ ) ) :
function theme_register_menus() {
register_nav_menu(‘top_menu’, __(‘Top Menu’, TEMPLATE_DOMAIN));
}”
in the functions.php
@nobbyrn @michael_vlahov
Guys, the instructions for the Frisco theme can be found in the functions.php file, right at the top.
You simply need to create a functions-custom.php file, and copy/paste the bp_dtheme_setup function (from lines 37 to 82 inclusively).
In functions-custom.php, change line 52 to this:
// This theme uses wp_nav_menu() in two locations.register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'buddypress' ),
'secondary' => __( 'Secondary Navigation', 'buddypress' ),
) );
Then save and upload that file to the theme folder. Finally, activate the custom functions file by checking the box in the theme options.
The modified function in your functions-custom.php file should override the same function in the theme’s default functions.php.
I wanted to thank you for this brilliant tutorial Patrick !
it helped me a lot to build my site an understand better some components in buddypress.
Thanks a lot!
Fabio
@Fabio
You’re very welcome!
I’m glad you found it useful :)
I tried this and I love it. But I’m having some issues with it. 1: My blog page gets locked whether I have the template set or not set. 2: In i.e and firefox, after a user logs in the page redirects to the same log in page as if the user never logged in, however the user is logged in. The user the have to click on another page to see the logged in menu. This does not happen with Chrome. I’m using the Sahifa theme, I’m not sure if that may have something to do with the issues.
My website is http://www.newjerseyhsa.org
I figured out the 2nd problem. PHP 5.4 was the culprit. I switched back to php 5.3 and the redirection after login seems to be working fine on all browsers. I’m still trying to figure out why my blog page is locked(which i don’t want to happen.