Archive for the ‘Wordpress Development’ Category

wp_update_user and user_login

September 4, 2012 Leave a comment

The most frustrating part till now, the solution what i got, is writing a query which i didn’t liked. So i was searching more of a native wordpress function. Wen i was using wp_update_user with its arguments & i was adding user_login to update my username. Everything was fine but when i tried updating the user_login it used to be the same the day i created the user. So then after looking all over unfortunately there is only one way to do it and which is :

      $wpdb->query("UPDATE $wpdb->users SET user_login = '[new_user]' WHERE ID = '[user_id]'");

WordPress strictly discourage to update username/user_login.

Categories: Wordpress Development

embed Video in post without shortcode (WordPress)

July 11, 2012 1 comment

WordPress from long time were using shortcode to embed video from youtube, but since 2.9 they dynamically insert a object code on entering the url.


Just you need to paste the link (without square brackets) and it will automatically convert to video. Here are the list of supported site


Categories: Wordpress Development

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 ….

Implementing jsonp for cross domain request

May 19, 2012 Leave a comment

Your would be very happy when it comes to crossdomain with ajax call. I have one of the solution to make a crossdomain successful with jsonp.


The main problem for making a cross domain request is many browser has a security restriction as we cannot make any request other than the current domain.


The solution is jsonp, but you might be thinking how does that work to0?

We all know that javascript can be included with any domain, there is no restriction for that . So we can use the same thing to get our desired output.

I have created a test application in php to give a response to a get request.

$callback_function = $_GET['callback'];</pre>
//some json generated via some logic.
$some_json_string = '{"menu": {
 "id": "file",
 "value": "File",
 "popup": {
 "menuitem": [
 {"value": "New", "onclick": "CreateNewDoc()"},
 {"value": "Open", "onclick": "OpenDoc()"},
 {"value": "Close", "onclick": "CloseDoc()"}

//set header as we need to return the javascript
header('Content-type: application/javascript');

//return with a function which was set as a callback
echo $callback_function.'('.$some_json_string.')';

Also some javascript code in your html/php file which is on other domain.


You can refer to the following screenshot. You can also check the domain from which i am calling. The domains have been changed via host file.
cross domain jsonp request...
I will be implementing jsonp without getJson method. Hope this will save lot of your time ..

Categories: Wordpress Development

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.


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 .


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.


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


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);

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.


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.

Adding template page from plugin

April 18, 2011 Leave a comment

Hello readers,

I have found a very simple solutions to assign a template page to specific or all pages . According to my previous tutorial for creating the template page and placing into the wordpress current template.

For creating the template you need to add comment on the top of the page as known from my blog

Template Name: new template

Now what ever you want add the functionality to the page and then add header/footer as on your preference.
Now your template file is ready to run or attach to page. But now no need to copy that php file to the template folder of wordpress.
all you need to do is call the following hook

add_filter( 'page_template', 'catch_plugin_template' );

Now this will be called on every page/post load.

add_filter( 'page_template', 'catch_plugin_template' );
function catch_plugin_template($template)
$template = WP_PLUGIN_DIR . '/yourpluginname/template-file.php';
return $template;

Now the above could will execute on every page and the template would be assigned to all the pages you have created.

Thank You for reading.

%d bloggers like this: