Jotted by brajesh on June 30, 2010
So you must have seen that the default landing page for a user profile in BuddyPress is User activity page. Sometimes you may want to change it to rather the profile page or wire or some other page.
The good thing is, it’s easy, well super easy to do that. What you need to do is put a line in bp-custom.php
//define the default component
define("BP_DEFAULT_COMPONENT","profile");// Now when you click on a user name link, You will land on User's profile not user's activity page
Similarly, you can use any of the active component as the landing page. For example, if you are using my wire plugin, you can define BP_DEFAULT_COMPONENT to be “wire” and the wire will be the landing page. Or if you want, you may define “groups” and User’s Groups page will be the landing page but I don’t think you will ever want to do that.
I see only two three practical uses of it.
1. Using xprofile page(or profile page) as default landing page
In that case define BP_DEFAULT_COMPONENT to be “profile”
2. Using Wire as the landing page
In that case define BP_DEFAULT_COMPONENT to be “wire” or what ever you have put as BP_WIRE_SLUG(in case you have customized the slug).
3. For creating a landing page which aggregates user activities, shows users groups and others
In that case, I assume you have created a custom landing page(which is pretty easy and I will be discussing about it in one of the articles) and want it to be the default case.
So try changing and experimenting with “BP_DEFAULT_COMPONENT” and may be you can have better usage ideas for it . As always, any comment suggestions or anything, please let me know in comments.
Tags: bp-default-compoent, buddypress, misc
Posted in Tutorials, buddypress | No Comments »
Jotted by brajesh on June 28, 2010
Everyone likes shortcuts(and may be a few not), and so do I. Since my personal preference of WordPress Multiuser(or now multisite/multi network what ever you call them) I missed one thing the most while working on my BuddyPress site with WordPress single User and It was the My Blogs drop down menu. It provided me with a quick option to navigate to WordPress Dashboard or to new post screen and so on. On single user WordPress I had to manually type wp-admin in the url to get to the dashboard.
Fade up with the number of times I had to type this, I rather created a small code snippet which enabled me to navigate to the dashboard/posts screen with the same efficiency(well even took less time as it has to be a single level navigation).
here is a screenshot from my test site.
And here is the code snippet to enable this
add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu_single_wp', 6 );
function bp_adminbar_blogs_menu_single_wp() {
global $bp;
if ( !is_user_logged_in()||!current_user_can("publish_posts") )//show this menu to author
return false;
$blog =bpdev_get_single_wp_blog_info();
echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->root_domain .'/wp-admin/">';
_e( 'Blog Admin', 'buddypress' );
echo '</a>';
echo '<ul>';
if ( !empty( $blog) ) {
$alt = ' class="alt"';
$site_url = esc_attr( $blog->siteurl );
echo '<li' . $alt . '>';
echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
}
echo '</ul>';
echo '</li>';
}
//create dummy blog object, we can even avoid it too, as we only need site_url and nothing else
function bpdev_get_single_wp_blog_info(){
global $bp;
$blog=new stdClass();
$blog->siteurl=$bp->root_domain."/";
$blog->name=get_bloginfo('name');
return $blog;
}
In fact, the code for bp_adminbar_blogs_menu_single_wp is actually taken from “bp_adminbar_blogs_menu”[bp-core-adminbar.php] and modified for our purpose.
You can put the above code in your themes functions.php or in bp-custom.php or just create a plugin and drop it. That’s it.
Hope it helps, please do let me know if you use it and find any issues.
Posted in Tutorials, Wordpress, buddypress | No Comments »
Jotted by brajesh on June 27, 2010
There are times when you want all of the registered member on your blog network to be members of all the blog. WordPress does it differently. By default all the registered users are added to the main blog with the role you have specified(or “subscriber” by default ). If the user creates a new blog, they are removed from the main blog and added to the new blog they created.
My solution here will allow to automatically add users to all blogs on your network, it does not matter much if they register a new one or they do not have a blog but just a registered member. In case the user registers new blog, this function will do no harm the user will be admin of the new blog as in normal case.
To our help, there are two functions
is_blog_user():-It checks whether the current logged in user is a member of the current blog or not.
add_user_to_blog($blog_id,$user_id,$role):- it allows you to add an existing user to a blog with the specific role where $role can be “subscriber”,”author”,”editor”,”contributor” or “administrator”
Now the code, putting the following code in your theme’s functions.php will do the job or you may wrap it as a plugin in case you want it that way
add_action('wp','bpdev_add_user_to_blog',10);//hook our function
/*add logged in user to current blog*/
function bpdev_add_user_to_blog(){
if(!is_user_logged_in())
return false;//do not do anything
global $current_user,$blog_id;
if(!is_blog_user())//check for current membership
add_user_to_blog($blog_id, $current_user->ID, "subscriber");//give subscriber role for current blog
}
And if you are using buddypress, you can put the above code in bp-custom.php.
What it does:-
When a logged in user visits a blog on your network, it checks whether he/she is a member of the current blog or not. If not, it adds them as a member to the current blog.
I hope it helps in some of the cases. Let me know it it works for you or not ?
Posted in Tutorials, Wordpress Mu, buddypress | 10 Comments »
Jotted by brajesh on
Here I am, once again, but I am not here to say apologies or provide reasons for my past reluctance to blog here. I am writng the new post to let you know, my feelins for this blog has resurfaced again and I am back to have a new begining for ThinkingInWordPress.com
It was always a fun to write here and listening to you all but things changed and I got busy with the other site so never found myself time and energy to blog here and even if I tried to look back sometime, I could not find something good to start with.
Now, as wp3.0 is out and you all must be busy upgrading and having fun with it, I thought it as the right time to start all over again. I am going to write regular again with all the tips/tricks I accumulated in the last 6 months of absence from this site.
There are a few questions though.I see there are more than 100 comments which needs to be answered but they have lost the relevance to be answered as most of them were made 2-3 months ago and even if I reply them now, it won’t be useful. So I am not going to reply those old comments but will be replying any comments from now onwards again. If you have any question/confusion about the things on this site, please feel free to comment, I will be glad to helping you again.
And yes, I will be writing more than 3 posts a week for now couple of months to make it even for my absence. Hope to see you all again here
Posted in Uncategorized | No Comments »