Archive

Posts Tagged ‘wordpress plugin’

Customize Admin Area for WordPress

May 22, 2012 Leave a comment

Hellow Guys,
Wordpress provides a great power to customize most of the things via wordpress, like curd operations on admin menu’s, customizing admin bar (which will be covered in my coming posts).

So today we would work with one of the awesome functionality by wordpress itself, like removing the unwanted menus from admin area. You might be thinking that we could simply hide it why to use the function, correct that’s also the way but remember always do the right way where ever you can.

We just need to call the following function to remove any menu you want to

remove_menu_page( $menu_slug );

$menu_slug is the file name which is called on clicking of the menu, like for user operation wordpress call’s users.php. So if you pass users.php as a “menu slug” then it will remove the entire “Users” menu from admin area. Now you may be wondering that how will i remove the sub menu from the admin area. Simple, just use the following function with the php file name and the parent file name as specified below.

remove_submenu_page( $menu_slug, $submenu_slug )

So say you need to remove some menu’s for author then you may just use the above function’s on admin init. That will make your life more simpler 🙂 … Also do not forget to check the user rights…  For details you may visit remove menuremove sub menu

Hope this helps.. Stay tuned for more ….

Advertisements

WordPress Logout Redirect not working (Solved)

May 17, 2012 4 comments

I know you all be so happy to see the title of the post. Yes there is a solution for adding a redirect after being logout.

Problem:

I was using

 echo wp_logout_url( home_url() );

It seems so simple. When we look at the url it works properly with a parameter “redirect_to”. But whenever you try to use that it will always go to default wordpress login page. I researched and found out that domain mapping plugin is stopping it from redirecting. I tried fixing it in domain mapping itself but it was a waste of time .

Solution:

But then wordpress offers amazing power with hooks. Then i found out there is one hook where i could call a function after doing redirect.

 add_filter('wp_logout','redirect_me');

This calls the function after deleting the cookie and signing out . So i wrote a function that will check if it has a redirect_to parameter in url then could redirect to destination else will redirect to where it came from. If you don’t want to redirect to HTTP_REFERER then you can always use

home_url()

function redirect_me(){

//if the user has rights of editor then return don't do anything
 if(current_user_can('editor')) return;

//get the reffer or you may user home_url() if the "request_to" is not set
 $logout_redirect_url = $_SERVER['HTTP_REFERER'];
 if(!empty($_REQUEST['redirect_to'])) wp_safe_redirect($_REQUEST['redirect_to']);
 else wp_redirect($logout_redirect_url);
 exit();
}

Hope this solution helps .

Add menu into wordpress page

May 11, 2011 Leave a comment

Hello Folks,

Since many days i was wondering to add a dynamic menus that i could insert via plugin. I wanted to insert login and logout buttons into menu bar without editing the template. Then i found out one hook for the wordpress that i could inject my content into menu.

      add_filter('wp_nav_menu_items',add_menu,10,2);

The above hook will call add_menu which contain 2 parameters.

      function add_menu($items,$args)
      {
            items .= "<li>Another Menu</li>";
            return items;
      }

it will look as following


As you can see another menu is created beside. As css is not applied it looks like that apply css would
look alike.

If there is any problem give a reply.

My First Plugin Development

February 8, 2011 12 comments

Hello readers this my first blog on wordpress plugin development . When i started with wordpress development i was dam tensed , i din even know how to install but then when i went into deep i got to know how its dam easy . Just follow my steps you would know how to create a plugin . Soon i would add a video tutorial for this.

Read more…

%d bloggers like this: