Find out what I'm doing, Follow Me :)
If you have any question, suggestion or article topic for me to write, feel free to contact me through my shout box. ;) Some time I need an idea to write. hehe Hopefully I can help you and share my expertise.

getting an unwanted sub menu item in wordpress when using add_submenu_page

We are currently doing project in wordpress environment. In that project, we deal with customization administration menu which it bring us to seek for menu creation using add_menu_page and add_submenu_page function.

here is properties for that functions

add_menu_page(page_title, menu_title, access_level/capability, file, [function], [icon_url]);
add_submenu_page(parent, page_title, menu_title, access_level/capability, file, [function]); basename(__FILE__)

by the way. when we create submenu using add_submenu_page function, we had unwanted sub menu item appear in the first submenu. this submenu is same as main menu like this..

Menu Tile
-Menu Title
-Sub Menu Title 1
-Sub Menu Title 2

we don't want Menu Title appear as a submenu. After googling, I found that other people also got a same problem. I do a research and debugging and finally I got the solution.

add_menu_page('Menu Title', 'Menu Title', 10, 'main_menu', 'sub_menu_1_callback');
add_submenu_page('main_menu', 'Sub Menu Title 1', 'Sub Menu Title 1', 10, 'main_menu' , 'sub_menu_1_callback');
add_submenu_page('main_menu', 'Sub Menu Title 2', 'Sub Menu Title 2', 10, 'sub_menu' , 'sub_menu_2_callback');

It's pretty simple.. just to make sure the first submenu file name is same as their parent file name. In my case, look at first add_submenu_page function file name, main_menu . I put same name as add_menu_page function file name.

Download Wordpress Submenu Sample Plugin

list all hooked wordpress function

This code originally create by rarst

function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
} else {
echo '<pre>';
foreach($hook as $tag => $priority){
echo "<br />>>>>>\t<strong>$tag</strong><br />";
foreach($priority as $priority => $function){
echo $priority;
foreach($function as $name => $properties) echo "\t$name<br />";
echo '</pre>';

php create function on the fly

I'm currently studying wordpress code becoz I need to hack theme preview.I want change CSS style when preview themes function called. Current wordpress method, they'll read style.css by theme name but I don't want to do that since I develop a library for CSS Style. During hacking process, I realize this code

add_filter('stylesheet', create_function('', "return '{$_GET['stylesheet']}';") );

Not add_filter daaa. can you see create_function( inside add_filter ?

Then I ask google by using keyword php create_function and found this result. wah... so easy to create function on the fly using php.

php how to get real path for virtual directory

for the normal site you can use


to get absolute path of root.
I had a problem to get absolute path when I put my code inside virtual/alias directory. when I use echo $_SERVER['DOCUMENT_ROOT']; , it will return absolute path for document root. Not my virtual directory.

How ever, here is the solution for my problem.

echo realpath('./');

Installing ubuntu on Virtual PC 2007

How to install ubuntu on Virtual PC 2007.

Step 1
After you install Virtual PC 2007, open it and start your ubuntu virtual file.

If you want to change virtual PC settings, just click on Settings button and you will find some configuration for your virtual PC like a hardisk space, memory and etc.

Step 2
After you start your ubuntu virtual file, go to CD->Use physical drive if you want to install it from your cd rom or CD->Capture ISO Image if you want to install directly from ISO file.

Step 3
Reboot your Virtual PC by Right Alt + R or go to Action->Reset menu.Wait untill your Virtual PC boot from your CDRom/ISO.

Step 4
Here you go. Installing ubuntu on Virtual PC 2007 will start from here. Select your prefered language and press Enter to continue.

Step 5
press F6 and enter vga=771 noreplace-paravirt at the end of the line. Press Enter to continue.

Step 6
Choose your language and press Enter to continue and then choose country.

Step 7
Installer will ask your keyboard layout. From this screen, you need to follow screen instruction

Step 8
Enter your host name, this is your ubuntu computer name. can be your name and Enter to continue and follow your screen instruction.

Step 9
Partitioning disk. select Guided - Select Entire Disk and press Enter to continue. Please bare in mind, this partitioning disk is virtually partitioning and do not effect your physical disk. So don't be scared... your data will not be deleted.

Step 10
Even tho this screen mentioned that your data will be erased, don't be scared. ;) it happen virtually only. But if you Install ubuntu into real PC, you must take a consideration.

Step 11
Select Yes and press Enter.

Step 12
Setup user account and username.

Step 13
Choose whether you want to encrypt your private directory or not

Step 14
Configuring package manager. Just press Enter key to continue.

Step 15
Configure update setting

Step 16
Since we're installing ubuntu server, we need to choose software to install in that server. I'm choosing mail server for this Enter to continue.Just a few step ahead for Installing ubuntu on Virtual PC 2007.

Step 17
Taraaaa! almost done.

but not really done. There are a few step after installation finish. Fix ubuntu screen on Virtual PC 2007