Redirecting pages based on roles.

Does anyone know of a way in which I can redirect a user with a specific role every time they click on the news link?

http://example.com/archives/category/officeA

So if a user with a role of OfficeA clicks on the news link they are redirected to the officeA category. They can still see the other categories - but officeA always becomes the default news for them.

Thanks,
Rob

  • Timothy Bowers

    Hey Rob, welcome to the WPMU Dev forums! :slight_smile:

    There are a few functions in WordPress you could use:

    http://codex.wordpress.org/Function_Reference/wp_redirect

    This is the default redirection function, we could then encase that in a check for roles:

    Justin posted some great information just here:

    http://wordpress.org/support/topic/get-a-users-role-by-user-id?replies=20

    If your not yet familiar with him, then you might want to checkout his site and the book he co-authored:

    http://justintadlock.com/plugindevbook

    Personally what I would do, is grab all the user roles then loop through them to create a custom menu location for each. I would then assign a custom menu to each. This would give the greatest control over your menu for each role.

    http://codex.wordpress.org/Function_Reference/wp_nav_menu

    This would take some custom work through. I'm aware of tons of plugins which can redirect on login. But I'm not sure about redirect on click. Sorry.

    Hope this helps. :slight_smile:

  • rpwillie

    Hi Timothy,

    Thank you for this - it's really, really helpful! :slight_smile: This looks just like what I need - thanks. I don't know php, but will have a stab at it tonight :slight_smile: Unfortunately I've got to do the housework today, else I'll get in trouble..

    Just a thought though: I'm using buddypress - so I'll need to make sure all my roles are based on the buddypress member role won't I?

    Else none of the buddy press stuff will work?

    Thanks,
    Rob

  • isis

    Hi Rob!

    I just played around on my site to see if I could figure a more simple way to navigate this way. I have to say, I keep coming back to Multisite. Then it is extremely easy, there is a tab at the top of my site that says "Blogs" but you could easily rename that "News" and it lists the different blogs/sites in my network so it could be set up for you as Office A, Office B, etc and it would take the user directly to their office's news.

    We talked about this yesterday in doing group specific blogs (using multisite also) which I think is an even better option as it keeps your employees in one office in their office area ... can have activity streams and office specific forums, etc.

    To set up Multi-site you would need to get a new domain and do a redirect from a page on your main site. Since you have set up static sites before and are well versed in that, I know that part shouldn't be a problem for you. If you can easily pull off getting a new domain, I think this might be the best bet for you. I know it might seem like a big "UGGGH" :slight_smile: but I think it is going to, in the end, make your life a lot easier.

    All of these things you are wanting to do, ie, have different office pages, etc. call, inherently with Wordpress, for subsites or separate "blogs". If you want to stick with the one subdomain you are working with, you will likely have to do some php coding and I think that will give you a MUCH bigger headache than setting up Multisite.

    Don't worry so much about the warnings in the Creating a Network codex. Technically, if I listened to that, I would not have one either, but again, there is just no way I can accomplish what I want to (easily, using templates and not coding!) without it.

    You'll have to add the supplied lines to your wp-config.php, (and do it in the order that is indicated) set up a wildcard subdomain with your server and add a new set of rewrite rules to your .htaccess file. That's it. Then you will be able to move your database and wordpress, buddypress, etc over to that domain and I think you will find that the things you are trying to do work seamlessly.

    Again, it just seems as though each office inherently needs it's own "Blog" - wordpress vernacular for area of the site. This can only be accomplished (easily anyway) with multisite. From your users' viewpoint, a redirect from the main site won't be all that noticeable AND you can password protect the site if you need to.

    Good luck with the housework and your site build. If you decide to go this way and need more help, be sure to post. I'll be on and off all day as I have to do my own housework, gym and family stuff :wink: but I'm more than happy to help as much as I can!

    Cheers!
    Isis

  • Timothy Bowers

    Hey Rob

    Thank you for this - it's really, really helpful! :slight_smile: This looks just like what I need - thanks. I don't know php, but will have a stab at it tonight :slight_smile:

    You are very welcome.

    There may well be other ways to achieve this, this is just the way I would probably do it.

    If another member has a different or better idea then I'm sure they will post here. :slight_smile:

    Unfortunately I've got to do the housework today, else I'll get in trouble..

    That is the worse sort of work as well. I'm lucky, my wife is very good to me!! But don't tell her I said that.

    Just a thought though: I'm using buddypress - so I'll need to make sure all my roles are based on the buddypress member role won't I?
    Else none of the buddy press stuff will work?

    You are right, there are more roles in BuddyPress, but you should be able to loop through and pull the data. Default roles are here:

    http://codex.wordpress.org/Roles_and_Capabilities

    If your conditional statement doesn't take those into account then no it wouldn't have a menu, but you could use a Case switch and set a default to ensure all roles get something if you miss one.

    Hey Isis

    I believe what Rob is trying to achieve is that one link will go to different places dependant upon their role.

    Allowing them to have their own site I suppose could work, they would then have their own news and content.

    Thanks for that!!

    Tim

  • rpwillie

    Ugghh.... I wrote my reply... went to click on maximise... slipped with the mouse, and closed the browser window! So now I'm writing it again haha:slight_smile:

    Isis and Tim - thanks for this.

    I've had a read of the multi-site codex

    A multisite network is a collection of sites that all share the same WordPress installation. They can also share plugins and themes. The individual sites in the network are virtual sites in the sense that they do not have their own directories on your server, although they do have separate directories for media uploads within the shared installation, and they do have separate tables in the database.

    By design, all users who are added to your network will have subscriber access to all sites on your network.

    So - just to check I'm correct in my understanding:

    example.com - a landing page listing links to all the other sites
    http://officea.example.com for members of Office A
    http://officeb.example.com for members of Office B
    http://officec.example.com for members of Office C

    Each site can be used as the homepage of each respective office. Members of each office sign up to their own site - where they have access to their own news etc (but can still see news from other sites).

    They also have access to buddypress - where (due to the design of wordpress) they can friend and communicate with members from other offices - and join groups etc all from their own site.

    This is good, because it mitigates the need to automatically assign a member to a group as they have their own homepage.

    In addition to this - I can use the blog groups plugin.

    And wow! now that I've re-written this, it's half the length of my original post - so maybe that was a good thing :slight_smile:

    Kind regards,
    Rob

    ps. I've juts read a multisite can be path based or domain based... in which case I could theoretically keep them all at a subdomain? http://text.example.com/officea

    but on reflection - I think sub domains will be cleaner.... unless I use the http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/ plugin - thus giving each site its own domain name...

  • isis

    Yes, Rob, you are correct in that this will allow each office to have their own pages via their own virtual sites (news via posts and pages for more static information for their offices, etc.). Buddypress will allow them to have friends with people from other offices, etc. You could keep the main example.com as a company/employee specific site, which may be a valuable resource for those who own/run the company :slight_smile:

    In order to set up a landing page that lists each office, you would just have to assign the auto-created "Blogs" page as the Home page for the site and you can rename it to "Offices" or something of the like - make sense? This is ultra-easy to do.

    What we discussed in the live support time the other day was enabling Group Extras and then having a blog (news) for each group formed utilizing Buddypress. Remember, this requires Multisite as each of those blogs is a different virtual site. So...there are a couple of different ways to accomplish what you are wanting to do (ie, via different blogs from the main home page or different blogs within the groups - heck you could even do both at some point if the client likes the versatility); I'm going to be doing something similar in there will be "news" within the groups and then separate blogs from the main site to discuss growth of the company, featured articles, etc that affect the entire community, etc.

    ps. I've juts read a multisite can be path based or domain based... in which case I could theoretically keep them all at a subdomain? http://text.example.com/officea

    No - remember that the multisite install MUST go in the root directory no matter if you do subdomains or paths, so you are going to be required to have a separate domain for the install. It is nice and clean to have a separate domain for each.

    Install, again, is pretty easy - just follow the instructions to the "T" - creating a wildcard subdomain (that points to the main public_html folder - NOT a wildcard folder) adding supplied code to the wp-config.php file and then the supplied rewrite rules to your .htaccess file. Boom, you are done.

    I still maintain that this (Multisite) is going to be the easiest route for you after having spent a good deal of time chatting with you and coming to understand your ultimate goals. I think you'll be amazed at how much easier these things become! Again, I don't pretend to be an expert :slight_smile: so if others here think there is a simpler way, then of course, give their suggestions a shot!

    Remember to keep that clean local copy of WP and move that into your new domain :slight_smile: Also keep a clean copy of the wp-config and htaccess (by renaming the ones you add or replace code in - FTP over and then change the names there :slight_smile:

  • isis

    Rob,
    You'll note that I have Membership installed, but I have not activated it yet. I remember the confusion that got to going in the forums about utilizing that for your purposes. Just remember, that's not the way to go :wink: Buddypress + Multisite will get you where you want to be...if you run into questions as you work, feel free to post and I'll see if I can walk through some of it too. I'll be in and out today but am hoping to get some work done too!
    Isis (Wendy)

  • Timothy Bowers

    Hey again.

    Ugghh.... I wrote my reply... went to click on maximise... slipped with the mouse, and closed the browser window! So now I'm writing it again haha:slight_smile:

    Always a nightmare, not done it in a while. Opening the history should bring the tab back with the form filled in. :wink:

    At least it does in Chrome on MAC. :slight_smile:

    By design, all users who are added to your network will have subscriber access to all sites on your network.

    Yeah kinda, they do have access as a subscriber but they are not assigned an official role. You see by default they register on the main site.

    Each site can be used as the homepage of each respective office. Members of each office sign up to their own site - where they have access to their own news etc (but can still see news from other sites).

    Thats correct, although by default the admin would need to add them to each site if they want them to do something specific. Although they have subscriber access by default.

    The following plugin in the thread will help with registering at sub sites:

    https://premium.wpmudev.org/forums/topic/about-mp-blog-register-quick-hack-please

    They also have access to buddypress - where (due to the design of wordpress) they can friend and communicate with members from other offices - and join groups etc all from their own site.

    That is correct, by default though BuddyPress can only be installed on your main site. You can enable it on sub sites but the install would still be data from the main site, it just allows you to access it from a sub site.

    Pop this into your wp-config.php to enable it on multiple sites:

    define ( 'BP_ENABLE_MULTIBLOG', true );

    In addition to this - I can use the blog groups plugin.

    Which plugin? Please show a link.

    ps. I've juts read a multisite can be path based or domain based... in which case I could theoretically keep them all at a subdomain? http://text.example.com/officea

    I don't understand what you mean?

    You mean install WP in a subdomain and use it as a multisite sub folder installation?

    If so then I wouldn't personally. Better to have it in a TLD (Top Level Domain) and install it as a subdomain multisite.

    I've started playing about with multi-site locally (WAMP - have a PC laptop... mac desktop) and so far its going really, really well! Have registered a new domain name - and will sort out some dedicated hosting :slight_smile:

    If you run a Mac desktop, then you might like to use MAMP:

    http://www.mamp.info/en/index.html

    I like it.

    Its not always straight forward moving from a local install to a production install, just things to consider is the environment would be different, you need to change relevant info in the DB like links, etc.

    Can see the end of the tunnel now!

    That is always a good thing!! :slight_smile:

    Take care.

  • rpwillie

    Hi!

    I've been a bit absent trying to figure out how to configure a server... but its all sorted now. I've got a fully working wordpress multisite with buddypress installed...

    The only thing is, each sub-domain reports the following in dashboard:

    You'll need to activate a BuddyPress-compatible theme to take advantage of all of BuddyPress's features. We've bundled a default theme, but you can always install some other compatible themes or update your existing WordPress theme.

    The following active BuddyPress Components do not have associated WordPress Pages: Activity Streams, Site Tracking, Discussion Forums, User Groups, Members.

    I'd like buddypress-social to be the default theme... and is there any way to have those pages created globally? Also - does this mean that this setup is seeing each buddypress as seperate? Because I need it to be seen as one big buddpress - with lots of wordpress sites up front.

    Thanks,
    Rob :slight_smile:

  • Timothy Bowers

    Hey again.

    I'd like buddypress-social to be the default theme... and is there any way to have those pages created globally? Also - does this mean that this setup is seeing each buddypress as seperate? Because I need it to be seen as one big buddpress - with lots of wordpress sites up front.

    Which pages? And how do you mean globally?

    You mean the BuddyPress pages like the stream page?

    And globally, throughout a multisite install?

    If so then you need to enable BuddyPress to work on other sites, add this to your wp-config.php:

    define ( 'BP_ENABLE_MULTIBLOG', true );

    The message about using a BP compatible theme, is because it needs some BP theme to work best. Some plugins which are a little more complex need their own themes to work best. :slight_smile:

    I'm guessing I've got to add the pages manually - but the buddypress side will behave as one big network?

    Its WordPress Multisite which is the network. BuddyPress is more of a social networking plugin.

    You can create the BuddyPress pages from the admin area:

    Admin --> BuddyPress --> Pages

    wp-admin/admin.php?page=bp-page-settings

    Hope that helps. :slight_smile:

  • rpwillie

    Hi Tim,

    Thanks

    I put define ( 'BP_ENABLE_MULTIBLOG', true ); in as per your orgional post :slight_smile: the issue is - when I go to view a site at a subdomain - the buddypress pages aren't visible, and inside the admin panel I get this message:

    The following active BuddyPress Components do not have associated WordPress Pages: Activity Streams, Site Tracking, Discussion Forums, User Groups, Members.

    On the parent site (root site) I see all the buddpress pages. So do I have to create new buddpress pages for each site... and if I do this - will it still work as one big buddypress site (I don't want individual buddypress sites)

    Thanks,
    Ron

  • Timothy Bowers

    Hey again Ron.

    BuddyPress won't work as single separate installs, so yeah it would continue to be one site wide network.

    The following active BuddyPress Components do not have associated WordPress Pages: Activity Streams, Site Tracking, Discussion Forums, User Groups, Members.

    Yup as the plugin needs to know where to display those pages. Just create them and you'll be fine. All the information from the maindomain.com for BuddyPress is used there also.

    If you have issues with slugs redirecting then go to the components page on the sub site for buddypress and just save the settings again. :slight_smile:

  • rpwillie

    Cheers Tim,

    I tried this a moment ago - and it works brilliantly :slight_smile: the is all coming together really, really nicely! So now my question is on the theme..

    I'm using buddypress social - and I want every site to look the same... same colours.. layout.. the lot. Is there any way that I can (using the wysiwyg interface) hit every site in one go... or do I have to update each one manually?

    Using the editor, I've changed the colours, and then used firebug to examine what has been changed, and can see that the style sheet references the page and a /

    nb members/7

    So I'm guessing this is generated by the template?.. it's not a physical css file...

    So would I just edit the base.css file with the colours I want to use on every site? (so it rolls on to every site) Also, is it possible to configure the layout so it rolls across every site?

    I don't mind if this is a manual job - because the combination of buddypress and multisite does exactly what I want :slight_smile: However if there is a way I can speed this progress up - then fantastic :slight_smile:

    Cheers,
    Rob

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.