Recent Tweets

Popular Articles

Wednesday, January 13, 2016

Wordpress logged a user programmatically

This is pretty simple and need to make sure to set the auth cookie or it will lost the user when visit through pages

 // Automatic login //   
  $username = "Admin";   
  $user = get_user_by('login', $username );   
// Redirect URL //   
  if ( !is_wp_error( $user ) )   
   wp_set_current_user ( $user->ID );   
   wp_set_auth_cookie ( $user->ID );   
   $redirect_to = user_admin_url();   
   wp_safe_redirect( $redirect_to );   

Saturday, October 5, 2013

WAMP apache won't start on windows

The service "apache" used to handle http request to your localhost. The apache service won't be started mostly due to used the port 80 by services of windows.

Wamp apache not started and  indicate by orange color
This could be due to IIS server running using port 80 or the Windows web deployment agent running

Stop IIS server:

Open IIS server manger by searching "IIS" on windows search

Click "stop" as on the image to stop running the IIS Service

Click to zoom

Stop Web Deployment Agent Service:

  1. Search for administrative tools as we did for IIS above
  2. Open services
  3. Find Web deployment service

  4. Right click on it and open properties
  5. Select manual start and click stop button

    Now restart all services of WAMP and Apache should be sart fine now

Sunday, February 27, 2011

Apache is running super slow Xampp / Wamp / Stand-Alone

Recently, I found that my apache running super slow, as I do my most of the developments on the local host this was an unacceptable, and I know there is no good reason for this. And finally I figured out this is coming from my hosts file.

In there a line of code for to some strange ip address fortunately I found it is not malicious and it was my previous ip address some how entered automatically there.

I remove that line and add following to it.

## Localhost localhost

And now it is working super fast. For your knowing this is a little guide to windows, it says if I'm tries to go to localhost just redirect me to, not to any other address.

Friday, February 18, 2011

Fix An Unexpected HTTP Error occurred during the API request Wordpress Error

This error can happen either your default timeout limit is not enough or.
If you're developing on localhost, may be your firewall blocks the apache http.exe server.

If your site is hosted on a web server, and you see the error message 'An Unexpected HTTP Error occurred during the API request' after requesting a page on WordPress Admin Dashboard and you are getting this error frequently on your dashboard, then it means you have to increase the wordPress timeout limit for every request. To do that

  1. Open your FTP Client software
  2. locate the file "class-http.php" inside "wp-includes" folder.
  3. And find the code "'timeout' => apply_filters( 'http_request_timeout', 5)" and change the timeout limit to 30. (5 --> 10)
If you're developing on localhost then, and if you see this error mean your server software being blocked by the firewall or you dont have an active internet connection. To fix this,

  1. Make sure your connection is active (probably you checked already)
  2. And make sure server software in not blocked. In my case, it is httpd.exe (Apache HTTP Server) This is only required if you're accessing to the internet for something like plugin installation and, etc....

Get Current File Name using PHP

There are two ways I found to get the current page name using php.

$path = $_SERVER["SCRIPT_NAME"];
$file = basename($path); // $file is set to "myfile.php"
$file = basename($path, ".php"); // $file is set to "myfile"

$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$parts = array_reverse($parts);
echo("Script is " . $parts[0]);

Stylesheet (CSS) Media Types

One of the most important features of style sheets is that they specify how a document is to be presented on different media: on the screen, on paper, with a speech synthesizer, with a braille device, etc.

Certain CSS properties are only designed for certain media. Stylesheets for different media types may share a property, but require different values for that property. For example, the 'font-size' property is useful both for screen and print media. The two media types are different enough to require different values for the common property; a document will typically need a larger font on a computer screen than on paper. Therefore, it is necessary to express that a style sheet, or a section of a style sheet, applies to certain media types.
  1. all -- Suitable for all devices.
  2. braille -- Intended for braille tactile feedback devices.
  3. embossed -- Intended for paged braille printers.
  4. handheld -- Intended for handheld devices (typically small screen, limited bandwidth).
  5. print -- Intended for paged material and for documents viewed on screen in print preview mode.
  6. projection -- Intended for projected presentations, for example projectors.
  7. screen -- Intended primarily for color computer screens.
  8. speech -- Intended for speech synthesizers. Note: CSS2 had a similar media type called 'aural' for this purpose.
  9. tty -- Intended for media using a fixed-pitch character grid (such as teletypes, terminals, or portable devices with limited display capabilities). Should not use pixel units with the "tty" media type.
  10. tv -- Intended for television-type devices (low resolution, color, limited-scrollability screens, sound available).
  • Media type names are case-insensitive
  • Media types are mutually exclusive in the sense that a user agent can only support one media type when rendering a document.
  • User agents may use different media types on different canvases. E.g. a document may (simultaneously) be shown in 'screen' mode on one canvas and 'print' mode on another canvas.
Specifying media-dependent Stylssheets
  • Specify the target medium from a style sheet with the @media or @import at-rules.
@import url("fancyfonts.css") screen;
@media print {
/* style sheet for print goes here */
  • Specify the target medium within the document language.
<link rel="stylesheet" type="text/css" media="print, handheld" href="style.css">

Thursday, February 17, 2011

Must have Wordpress Plugins all the time

Google XML Sitemaps
This plugin will generate a special XML sitemap which will help search engines like Google, Bing, Yahoo and to better index your blog. With such a sitemap, it's much easier for the crawlers to see the complete structure of your site and retrieve it more efficiently. The plugin supports all kinds of WordPress generated pages as well as custom URLs. Additionally it notifies all major search engines every time you create a post about the new content.


Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database.

W3 Total Cache

The fastest and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.

cbnet Different Posts Per Page

Show different numbers of posts on home, archive, and search pages. This plugin will allow you to modify the number of posts shown on home, archive (category, date, author, etc.), search pages and feeds. You can even set the order of posts by ascending or descending order.

Post Editor Buttons

This plugins allows you to add your own buttons to the post edtor's toolbar. (buttons that you see above your content text area when editing posts (b,i,link,img,ul,li)).

All in One SEO Pack
Automatically optimizes your WordPress blog for Search Engines (Search Engine Optimization).

Search plugins: Wordpress Plug-ins directory