Adding Sitewide Menu Items to a buddypress site

Jotted by brajesh on June 2, 2009

In this post,I will show you the quickest way to add menu items to a buddypress site,sitewide.

As you may be knowing,buddypress-wpmu powered sites need at least two themes,one for the site home page and one for the members profile,group etc(called member theme usually).So,when you want to add more menu items to the top navigation, you have two options.

1.Add the menu links to each of the theme(yes, you will have to add the link in the home theme and the buddypress member theme separately).

2.Simply write a small snippet of code and upload it to mu-plugins directory.It will add the link globally.

Well,let us start with the basics,I will take an example of the buddypress default home theme and buddypress default member theme.

Here is what you get as the top nav,when you install buddypress and activate the default themes

BP default menu

Well,so suppose now you want to add a few links(menu items) in the top navigation.As I mentioned, you have two options.

Option 1:-Go and edit the nav (for default theme,It is in header.php, look into your theme for the location of the menu) in the Buddypress Home theme and buddypress member theme.You are done.But suppose, you have to add/remove some links later ,you will have to again edit both the theme.

Well ,I have a shortcut for you.
Option 2:

Buddypress default theme(or any of the well coded buddypress theme) , provides an action hook “bp_nav_items” ,we can use this action hook to hook our new links into the menu.

Well,again we have two choices now.We can either use the functions.php of each of the theme(Home and member and add our function to add links),but again,this causes redundancy.

So,the better option is , let us define the functions in a new file say  my-extra-links.php(you may name it what ever you like) and define the action function there as

 
<?php
//add the action hook
add_action("bp_nav_items","extra_nav_links");
 
//insert the links now
function extra_nav_links()
{
?>
<li><a href="#">My Link 1</a><li>
<li><a href="#">My Link 2</a></li>
<?php
 
}
?>

Relace the hash(#) with the url of your link,and you are done.ahh ,yes, we have yet to upload the file somewhere.Since,In wordpress Mu,the files(or let us say properly ,the plugins) kept in the wp-content/mu-plugins directory gets automatically activated sitewide,we will use this functionality and upload our file to the mu-plugins directory.
Once, you are done with the uploading of the file to the mu-plugins directory, refresh your site page in the browser ,and you will see something like this
Adding sitewide links

Why you should use this approach:-It will allow you to keep your extra menu items ,even if the themes for buddypress gets changed(the only requirement is the new themes should also be using the action hook “bp_nav_items“).Well,I think, this approach, may reduces a couple of minutes in your development time.
So,what do you think? which approach is better? looking forward to your thoughts on it.

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]


View,share ,embed microsoft office files online

Jotted by brajesh on May 27, 2009

As a developer,I have been using openoffice for documentation purposes.Last day ,one of my client sent me a docx file,and I was not able to open it in open office.I tried google docs, bit it too does not support docx format.
after a couple minutes of googling,I found a wonderful site.I thought,I would share it with you all.The site is thinkfree.com.
ThinkFree:well as the name says, It is an awesome website with all the feature,you are looking from the Microsoft office.Further,It allows,sharing doc,embedding doc in pages,and viewing docs online.
thinkfree.com

Try yourself here http://thinkfree.com/

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]


Checking Programatically whether inside the wordpress post loop or not

Jotted by brajesh on May 24, 2009

Well,that sound easy ,Yes it is.While building my last plugin “wp-colored-post-titile”,I was in the dilemma to check ,whether inside the post loop or not.I looked through google,but could not find anything meaningful,not on wordpress codex too[Now It is as I added it on conditional tag page].So I started exploring the code and looking through query.php,I found this very useful function ,specially for plugin developers.

To check whether you are inside the loop or not ,you can use this function
in_the_loop()

<?php
if(in_the_loop()) /** if the curretn code is called from inside the loop */
 //do something meaningful.
?>

Now let me show you how I used it.I had to set colors for the post title.As you may be knowing ,wordpress provides the filter “the_title” for this purpose.My problem was,wordpress applies this filter to not only the title of post inside the loop ,but also to the title of post in navigation links,sidebar links(yes,I mean page titles).
So,I was in need of someway to make sure ,I apply the color to titles only when ,”the_title” filter is called from inside the loop.
My best friend “Google” ,could not help me in my problem ,so I started looking through the code .After a few minutes of search,I found the function inside the query.php
here is the example how I used it

<?php
/****code for my plugin goes here ***//
 
//apply the filter for post title
add_filter("the_title","wcpt_color_the_title");//call wcpt_color_the_title at the_title hook
 /**more codes goes here ****/
 
/**method to color the post title */
function wcpt_color_the_title($title)
{
 
global $post;
   $custom_field="_wcpt_title_color";
     $color_hex=get_post_meta($post->ID,$custom_field,true); /** get the color associated with current post title */
if(empty($color_hex)) /**if color hex is empty ..just return the title */
       return $title;
/** we are ,that means the color hex is not empty */
if(in_the_loop())	 /**so ,if we are inside the loop,let us modify the color of the post */
return "<span style='color:".$color_hex."'>$title</span>";
else                           /*** for all other conditions return the title */
return $title;
}
 
?>

Now , you may see ,how much useful this function was for me.May be it can save some time for you too.
btw,Now it is available on WordPress codex, and you may have a glance here
http://codex.wordpress.org/Conditional_Tags#Inside_The_Loop

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]


Using google Mp3 player to play music on your blog/site

Jotted by brajesh on April 23, 2009

Well,there are times when you want to play audio on your blog/website.Recently in one of my project I had to do the same.The client was insisting on using google mp3 player to play mp3 audio on their blog.

well,it was easy and if you have not worked with google mp3 player, you can use the following syntax to play audio files.

<object width="289" height="28" data="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=YOUR_MP3_URL" type="application/x-shockwave-flash">
 
<param name="bgcolor" value="#ffffff" />
<param name="flashvars" value="playerMode=embedded" />
<param name="src" value="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=YOUR_MP3_URL" />
<param name="wmode" value="window" />
<param name="quality" value="best" />
</object>

You will need to replace YOUR_MP3_URL with the url of your audio mp3 file.
It will make a tiny ,little and cute mp3 player which looks like the following image,available on your site.
Google Mp3 player

Now every thing goes well,until you check your site in IE.It works in firefox,safari,netscape and other browsers but not in IE.When you click on the play button in IE ,IE will show a download dialog for the MP3 file.well,that’s not something we will like to have as we have to keep our self fighting with IE’s quirks.
So,I looked all over the internet to find a solution,instead of finding a solution,I found that almost all web based audio player had same behavior in IE.
After a long battle with the IE ,I finally figured out(well,that was just presence of mind,nothing technical),how to make it work with IE(and the same applies for all other web based audio players to make work in IE).

In order to make the audio player work in IE, you need to rename your mp3 file to some file without extension.For example my-wonderfull-music.mp3 to “my-wonderful-music” [without any extension].Now use the new file url(the file without the extension as the value of audioURL) and it works like a charm.Oh! yes,In IE too.

here is a sample,click play and test in IE too.It will work.You may apply the same rule for other mp3 players too.
A Test music from http://www.sounddogs.com/[well I found it tiny enough to upload here]

So why It worked In IE and what was the reason btw?

IE thinks mp3 extension as something downloadable,so it starts downloading the file and shows file download dialog.To fool Ie ,we have renamed the file and made it with no extension,so now IE does not understands it and lets the player play the audio.that’s it
[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]


Limit Number of Blogs per User for wordpress Mu and buddypress website/blog network

Jotted by brajesh on March 25, 2009

Update 28th Feb, 2010: This plugin is updated, Please read more here  http://buddydev.com/buddypress/limit-blogs-per-user-plugin-for-wpmu

Well,It’s a small post after a long time.This time ,I am back with a plugin for wordpress MU.There might have been the times ,when as a site admin of wpmu site, you wished to limit the number of blogs a user can register. My plugin, limitBlogsPU(limit blogs per user),solves this problem.So ,what it does .

  • It adds an option to the options page when you are logged in as site admin of the wpmu site(or wpmu+buddyppress site),Look at the bottom of options page,and You will see a text box like this asking for number of blogs allowed per user.If you set it to zero(which is the default),It will not restrict the blog registration then.
  • It works only,if  you have allowed user registration,otherwise ,this becomes useless if the registration is disabled.
  • When ,a logged in user clicks on register blog (or register another blog,It checks ,whether the current user has already reached the restricted number of blogs),if not then the registration form is shown,otherwise it returns none on filter “wpmu_active_signup” ,restricting the wpmu to not  show registration form.

Who needs this plugin

  • Any wpmu(wordpress Mu)  site owner ,interested in limiting number of blogs registered per user
  • Any Wpmu+buddypress(Social networking plugin) based social network owner,interested in restricting numer of blogs per user.

Where Can you Download

Currently You can download it from my blog here from official wordpress lugin repositoryhttp://downloads.wordpress.org/plugin/limit-blogs-per-user.1.0.zip .

Installation and setup:-

  1. Download the plugin from herehttp://downloads.wordpress.org/plugin/limit-blogs-per-user.1.0.zip
  2. Unzip the plugin and upload the file “limit-bogs-per-user.php“  to your mu-plugins folder.If you have never worked with wpmu before,please read my post WordPress Mu Plugins Installation, sitewide Plugins vs. per blog plugin .
  3. Now The plugin will be automatically activated,please login to the wordpress backend as Site Administrator(site owner)
  4. Go to SiteAdmin-> Options page as show below wpmu options link

Now look at the bottom of options page, you will find something like this Showing The Number of Blogs to restrict fieldThere you will find ,a value 0 initially.Now you may set it to any number.The number indicates,the allowed number of blogs per user. I hope ,It will certainly help some of you.

Please note,it should work with wordpress Mu and Budypress+wpmu both.

Looking forward to your response. Brajesh

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]



Get Adobe Flash playerPlugin by wpburn.com wordpress themes