Today I have upgraded my blog to 2.0.5-RC1. Upgrade was simple as usual. I was checking everything on my blog and it was smooth. I don’t think there is any new features but lot of bug and changes has been done.
http://trac.wordpress.org/query?status=closed&milestone=2.0.5Â
One issue I came across was the default category was not getting selected after I made the upgrade. I have mailed the list and waiting for a reply ;-).
There is a simple way to push your rewrite rules to wordpress using a simple filter. To do this you need use rewrite_rules_array filter. Before starting with that let me explain the basic rewrite structure of wordpress 2.0 and above.
# BEGIN WordPress
< IfModule mod_rewrite.c >
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
< /IfModule >
# END WordPress
The rules above are the default rules in wordpress when you enable permalink option. The rules checks if the incoming request URI is a physical files or a physical directory. If both the conditions are false it directs the control to index.php. So that ends there. If you type any random url on permalink enabled wordpress blog you will get a 404 error page. This is because wordpress tries to decode the incoming url with series of rules and detects if the request is of some pattern. And if there is a pattern match it loads the needed stuff else it load a 404 page.
Basically the default pattern is generated based on what you set on permalink option page. And it has standard pattern rules for loading page, rss, author, category etc etc… The next thing you need to do it is to insert your pattern into wordpress rules array. This is achieved with the help of rewrite_rules_array filter. I will show how you can load your rewrite rules into wordpress.
function insertMyRewriteRules($rules){
$newrules = array();
$newrules['redirect/url/(.+)$']=’index.php?is_page_redirect=1&redirect_url=$matches[1]‘;
return $newrules+$rules;
}
add_filter(’rewrite_rules_array’,'insertMyRewriteRules’);
Using the above function I have added a pattern /redirect/url/(anything) to rewrite rules. If request URI has this pattern then it will pass two variables namely is_page_redirect and redirect_url to index.php. Variable redirect_url will hold the pattern match of string followed after /redirect/url/ in the request uri.
Example if I requested a url imthi.com/redirect/url/http://www.example.com/ redirect_url will hold ‘http://www.example.com’. Now pattern is matched and parsed into index.php as query variables. Now the next is to tell url query parser to use these variables. To do so you have apply a filter query_vars.
function insertMyRewriteQueryVars($vars){
array_push($vars, ‘is_page_redirect’, ‘redirect_url’);
return $vars;
}
add_filter(’query_vars‘,’insertMyRewriteQueryVars’);
The above function will add the two variables into the query vars and by which you instruct wordpress not to loose if these variables found in the request query. Okay that is done and the variables are retained. Next step is tell the query parser to use this. That is done with the help of action parse_query.
function insertMyRewriteParseQuery($query){
if(!empty($query->query_vars['is_page_redirect'])){
header(”location:”.$query->query_vars['redirect_url']);
exit();
}
}
add_action(’parse_query’,'insertMyRewriteParseQuery’);
The above fuction will check if there is variable is named is_page_redirect in query vars. If present it redirects to location present in variable redirect_url. :-D.. Lets wrap this up and make it a plugin which will apply redirect to comment author website urls.
Download comment url redirect plugin. Dont be surprised it is really simple..
Wordpress filters does the magic of data manipulation. Once you understand the power of filters in wordpress you can do lot of magic. This is very much helpful for developers who write plugins for wordpress. It is not necessary that you can use only wordpress default filters. If you want you can create your own filters.
What does this filter do? Filters basically passes a value to series of functions and returns the value. To understand the full concept of filters in wordpress you need know two functions basically
- add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
- apply_filters($tag, $string)
add_filter - Adds a function to a filter. The added function will be executed while a filter is applied.
- Param tag - This is a normal string text using this you can group number functions for a particular filter
- Param function_to_add - This is the function to be called when a filter is being executed
- Param priority - If you want to change the sequence of execution or the order of execution you can do by changing this param
- Param accepted_args - This mention no of arguments for the filter function.
apply_filters - Executes a filters and it returns a value.
- Param tag - This is a normal string text using this you can group number functions for a particular filterParam
- Param string - A values that is passed for the function.
function filter_function1($inval){
return strtolower($inval);
}
function filter_function2($inval){
return ucwords($inval);
}
add_filter('format_name','filter_function1');
add_filter('format_name','filter_function2');
$name = 'IMTHiaz rAFIQ';
$name = apply_filters('format_name',$name);
print $name;
That would print name as Imthiaz Rafiq. Here I have used a simple example. Wordpress uses this for everything. So if you want to control any data in wordpress you can do it with the help of filters ;-).
Check this site out for all filters and actions in wordpress..
Untill Next time ….!!!
Today I realesed a simple plugin named wp-pda for wordpress. This plugin enables the blog to viewable in pda browser. I hope there are so many bloggers who will like their blog to be read by PDA users.
To donwload the wp-pda plugin
Tom Sella was kind enough to add hebrew translation and fix some more hard coded strings in the plugin. I have update the files he has send me
Download Wordpress Organizer
Thanks Tom
It had been really long time since I posted something good. Too much work at office and everyday is exciting with lots of challenge. Learning a lot these days. I was playing around with lot of stuffs in Ajax. Got a new i-mate jasjam pda. It is really cool with lots of features. Its really good for people who are always in move. For people like me
to experiment and to program with new technology and provide good solution to people.
It looks really magnificent and it is load with these features
- 3G Windows Mobile 5.0
- 400MHz Samsung CPU
- 2.0 MP Camera
- 128MB ROM / 64MB RAM
- 1350mAh Battery
- MP3/Video PlayerGSM
- /GPRS UnlockedTri
- -Band UMTSQuad
- -Band GSM
- UMTS/EDGE/HSDPABluetooth
- v2.0
- Wifi 802.11b/gMicro
- SDInternet
- ExplorerPocket
- OutlookPocket
- WordPocket
- ExcelPocket
- Powerpoint
I was able to sync my outlook and pda and all my contacts are up to date. I was able to configure wifi and use the pda like a normal laptop. Browse site, POP3 mails, MS Exchange, MSN, etc etc.. But not to that level of a laptop ;-).
I was browsing my blog using my pda and believe me it sucks majorly. So I am planning to write a small plugin which can enable any pda users to browser my site. At least read the crap that I am posting
I hope there are so many blogger who wish to make their site pda or mobile friendly. Please welcome me to the community of pda users ..!!!!!