Category Archives: Wordpress

WordPress .htaccess on Zeus Server Rewrites

WordPress .htaccess on zeus server rewrites (rather than Apache)

Yesterday, I got luck to transfer a WordPress website from one hosting to another.

 

The New hosting provider is http://www.names.co.uk and what I have found is it provides the web server Zeus instead of Apache as always I have worked on.

 

It is really a new experience for me as I have not worked on Zeus server before that.
Let’s discuss what is the main issue I have faced as WordPress move is not a difficult task.

 

You have to export import database and the path updates in database it’s very quick by following some simple queries.

move your wordpress site to a new domain – easy wordpress migration

And the other is just need to transfer files and need to update “wp-config.php”.

That’s it!

 

But what I have faced is, Zeus not supports mod_rewrite as this is a module for Apache servers.
So, Zeus doesn’t support .htaccess files which are required to make your site’s URLs look pretty and SEO friendly (WordPress with its Permalinks).

The file that you need to create is called rewrite.script and is Zeus equivalent to Apache’s .htaccess file.

 

Follow the below steps to work your WordPress site smoothly with permalinks.

The .htaccess File for default WordPress looks like this:

 

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

 

Zeus equivalent rewrite.script File

 

RULE_0_START:
# get the document root
map path into SCRATCH:DOCROOT from /
# initialize our variables
set SCRATCH:ORIG_URL = %{URL}
set SCRATCH:REQUEST_URI = %{URL}

# see if theres any queries in our URL
match URL into $ with ^(.*)\?(.*)$
if matched then
set SCRATCH:REQUEST_URI = $1
set SCRATCH:QUERY_STRING = $2
endif
RULE_0_END:

RULE_1_START:
# prepare to search for file, rewrite if its not found
set SCRATCH:REQUEST_FILENAME = %{SCRATCH:DOCROOT}
set SCRATCH:REQUEST_FILENAME . %{SCRATCH:REQUEST_URI}

# check to see if the file requested is an actual file or
# a directory with possibly an index. don’t rewrite if so
look for file at %{SCRATCH:REQUEST_FILENAME}
if not exists then
look for dir at %{SCRATCH:REQUEST_FILENAME}
if not exists then
set URL = /index.php?q=%{SCRATCH:REQUEST_URI}
goto QSA_RULE_START
endif
endif

# if we made it here then its a file or dir and no rewrite
goto END
RULE_1_END:

QSA_RULE_START:
# append the query string if there was one originally
# the same as [QSA,L] for apache
match SCRATCH:ORIG_URL into % with \?(.*)$
if matched then
set URL = %{URL}&%{SCRATCH:QUERY_STRING}
endif
goto END
QSA_RULE_END:

 

You can also download the “rewrite.script” file by the below URL.

Download rewrite.script file

Upload “rewrite.script” file to your WordPress root folder (the same folder that contains wp-config.php).

 

If your WordPress site in installed in a sub folder, update line 27 and include the folder to the path before /index.php.

Next you will have to go into the WordPress Settings > Permalinks and save your permalink choice again. This will force WordPress to rebuild the permalinks for the site.

 

You can safely delete the .htaccess file from the remote site as it is no longer needed.

 

I think your site is working now fine but you may notice that you have index.php at the start of all your URLs.
Go to the WordPress settings > Permalinks and update that to a custom structure permalink:

/%category%/%postname%/

 

I think it all works, if you still face any issue post your comments below.

What is a WordPress Child theme & how to customize WordPress Theme using WordPress Child theme?

We all know that a WordPress theme is a collection of template files which lets us change the user interface, design, look & feel of the site.

 

Have you created WordPress theme or have installed any free theme or commercial one, many of you have done this job and have also customized but the problem is created when you have customized the original theme files and the update of that theme is available and you never would like to update as your customization will get destroyed if you update that, but my recommendation is that you should always keep your plugins and themes updated to the latest version. So you should take care during the customization and never do the customization in original file and should create a child theme. But what does that mean, and how do you do it?

 

In WordPress 3. 0 or latest versions a new concept was added by WordPress core team and community named as “Child Theme”.

 

As per the WordPress Codex definition of Child Theme:

 

“A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme. 

Child theme allows you to modify, or add to the functionality of that parent theme. A child theme is the safest and easiest way to modify an existing theme, whether you want to make a few tiny changes or extensive changes. Instead of modifying the theme files directly, you can create a child theme and override within. “

 

How to work with WordPress Child Theme?

 

Let’s take an example; I’ll create a child theme for WordPress default ‘Twenty Twelve’ theme.

1) So in this case, to create a child theme, I have to create a new directory alongside the ‘Twenty Twelve’ theme’s directory called twentytwelve-child.
“twentytwelve-child” directory should be in parallel of original theme twentytwelve.

2) Create a style.css file under the ‘twentytwelve-child’ theme directory.

Put the below text in style.css file

/*
Theme Name:     Twenty Twelve Child
Theme URI:      http://wp. tutsplus.com/
Description:    Child theme for Twenty Twelve
Author:         Japh
Author URI:     http://wp. tutsplus.com/author/japh
Template:       twentytwelve
Version:        1. 0. 0
*/

// This @import line loads the stylesheet of parent theme
@import url('. . /twentytwelve/style.css');

//Theme customization starts here

There are two important parts here to notice:

Template: twentytwelve
It tells WordPress that this theme is a child theme of the ‘Twenty Twelve’ theme

@import url(“. . /twentytwelve/style.css”);
It loads the parent theme’s (twentytwelve in this case) style.css as a starting point

3) Now you can log into your WordPress dashboard and see your ‘Twenty Twelve Child’ theme there, and activate it.

4) Make further alterations & addition and you will found that these will automatically reflected on your website.

 

Just Done!!

 

Now always keep in mind that whenever you want to make a customization to your theme, does it in your child theme.

Files in your child theme override files of the same name in the parent theme. So any file from your parent theme you want to change, copy to your child theme & make your modifications there.

The same goes for any templates that may not be in your parent theme. You can add them in your child theme, and WordPress will use them.

One exception to these rules is the functions.php file. In this case, the functions.php file for the child theme is loaded first, followed by the functions.php file of the parent theme. So there’s no need to copy the functions.php file from the parent into the child, just start fresh in the child theme for that one.

This allows the child theme to have all the functionality from the parent theme. Parent themes can also make their function pluggable, which allows a child theme to override them.

 

Why should you use WordPress Child Themes?

 

1. Safe Updates

A child theme automatically inherits the parent theme’s features, styles, and templates. This allows you to make changes to your site using child themes without ever modifying the parent theme. When a new version of the parent theme available, you can safely update it as you know that all your modifications are saved in the child theme.

 

2. Easy to Extend
A child theme built on a powerful theme framework allows a great deal of flexibility without writing a lot of code. You can selectively modify only the template files and functions that you need without going through other template files. You can add new functionality and much more.

 

3. Fall-back Safe
When you are creating a complete theme you need to think about all the possible scenarios and code for them. However, when you are working on a child theme and you forget to code for something, then there is always the parent theme’s functionality available as the fallback option.

 

WordPress catchable Tools for Child Theme

 

One-Click Child Theme plugin built and tested for the latest WordPress 3.x version.It adds a menu link into your Admin “Themes” section to automatically build a child using your currently active theme.This is fantastic if you don’t want to mess with FTP and are looking to play around with some new ideas.You can also use Child Themify plugin for creating the child themes.

 

If you plan to edit these files within the admin panel you’ll also enjoy clearer syntax highlighting for that you can install the Advanced Code Editor for some much-improved functionality. This makes wading through PHP code blocks and HTML/CSS a whole lot more manageable.

 

Additional Resources & references

 

1. http://wp.tutsplus.com/tutorials/theme-development/child-themes-basics-and-creating-child-themes-in-wordpress/

2. http://www.hongkiat.com/blog/wordpress-child-themes-dev/

 

Hope this all helps.

 

How to Import Large XML File (WXR file) in WordPress

You all knows that WordPress comes with built in import/export functionality that allows you to import or export your WordPress posts in XML format.

 

Have you ever tried to move your blog from one server to another, I think you have done this many time. But I am pretty sure that you were stuck in case the WXR (XML) file is very large to import? I have also faced this one but after a little search on Google, I have found perfect solution & sharing the same with you, hope this will help you to save several minutes.

 

I am also sure that you have tried to fiddling with PHP variables to increase the upload size limit, but even then you might run into some sort of execution time-out. But in case of large file, your server admin may not even let you change these settings or will show timeout even after updating.

 

The perfect way is to split your huge WXR data file into smaller chunks.

 

Even though you can manually split your large XML files by creating multiple XML files with the same header, category, and footer information and dividing the rest of the items. But no one has time for that and obliviously it increases chances of mistakes? There is a very nice free tool that allows you to split your XML files with just a few clicks.

 

Version 1.52 of the WXR Splitter is here!
Download the below and split your large file in chunks automatically.

 

WordPress XML (WXR) splitter

 

WXR splitter comes with the features
1)  Super fast parsing of the WXR file.
2)  Files are split by file size rather than by number of lines or tags.

 

Minimum requirements for running the WXR splitter

Operating System: Windows XP, Windows Vista, or Windows 7 with the .NET 2.0 framework installed.
(If you don’t have it installed, you can download .NET 2.0 directly from Microsoft)

 

There is a similar WordPress WXR Split utility available for Mac users. Use the below link to download

 

Click here to Download

 

Still trouble with the tools? Or need more help, post your comment below.

Quickly Deactivate or Activate All WordPress Plugins via Database or FTP

WordPress plugin activate deactivate all at once and Quickly

Sometimes during troubleshooting, it’s recommend to deactivate all plugins and activate them one by one and suppose at that time you will not able to login in WordPress admin (wp-admin) or white screen of death. At the same point we need to disable all the plugin or some plugin then in that case, How will you disabled/deactivate all or some plugin manually by the database or using FTP. Some time we need it to do very quickly.
I am sharing with you the technique by which you can quickly disable and (re)enable your entire set of WordPress plugins.

 

Deactivate All Plugins Using FTP

 

Navigate to the “/wp-content/” folder. You will see a folder called plugins. Rename the plugins folder to anything like  “plugins-deactivate”. Once you do this, all of your plugins will be deactivated automatically.

 

There may be due to some issue with plugin and it locked out your admin panel. If the issue was with your plugin, you should be able login to your “/wp-admin/” after deactivating the plugin. Once you do that, go back to your /wp-content/ directory and rename “plugins-deactivate” back to plugins. You can troubleshoot the problem by activating plugin one by one until your site breaks again.

 

 

Deactivate all plugins using phpMyAdmin

 

Login to your database using with phpMyAdmin and then have a backup.
I always suggest you to take Backup before doing any updates in table directly, so please in first step take backup of your database.
If you have backup of your database, you can quickly restore that and can revert your changes, so in this case(if there will some accident) you will always in safe hands.

 

Now, search a row in “wp_options” table that have “option_name” as “active_plugins”. Use the following SQL query (update your Database table prefix “wp_” if needed) for doing the same job.

 

SELECT * FROM wp_options WHERE option_name = ‘active_plugins’;

 

Once you found active_plugins column, click to edit it. You will see something like the below, depends on the number and type of plugins you have installed:

 

a:13:{i:0;s:19:”akismet/akismet.php”;i:1;s:23:”all_in_one_seo_pack.php”;i:2;s:28:”breadcrumb-navigation-xt.php”;i:3;s:37:”contact-coldform/contact_coldform.php”;i:4;s:13:”feedcount.php”;i:5;s:36:”google-sitemap-generator/sitemap.php”;i:6;s:13:”gravatars.php”;i:7;s:30:”nofollow-free/nofollowfree.php”;i:8;s:17:”ol_feedburner.php”;i:9;s:26:”simple_recent_comments.php”;i:10;s:18:”simple_twitter.php”;i:11;s:9:”top10.php”;i:12;s:16:”wp-db-backup.php”;}

 

This is a serialized array, you can unserialize this array by simply using the tool “http://www.functions-online.com/unserialize.html“. Copy the above string and click on run button you will get an array that represents every activated plugin on your site.

 

Thus, to quickly disable all plugins without using the wp-admin is cut the serialize array string as we have seen above and paste it into a safe notepad (text) file. After removing the code, click the button to save your changes and that’s it. All WordPress plugins are now deactivated (although you have all the plugins files in the same place “wp-content/plugins” and you can activate the plugin whenever you want by wp-admin area- if found working). This above method is obviously handy during, when the situation is critical and time-sensitive. Once you are ready to re-enable your entire set of plugins, simply copy & paste the preserved code(serialized array string) by notepad file and put it in the “active_plugins” field. Click save and done.

 

If you want to activate only some of those, unserialize the array by the above tool and make the array of plugins you want to activate then serialize that and put the string in the “activate_plugins” columns.

 

You can also go with a very simple SQL query to disable all plugins in one second.

UPDATE wp_options SET option_value = ” WHERE option_name = ‘active_plugins’;

 

 

This method works only for WordPress older versions(2.9 or older) for later use the below.

UPDATE wp_options SET option_value = ‘a:0:{}’ WHERE option_name = ‘active_plugins’;

Disable All WordPress Updates Notifications

First of all, there is no benefit of disabling plugin updates.

 

It is very important as I have previously said in the posts that you should keep your WordPress version as well as plugins up to date. If you don’t keep, then your site could be susceptible to security vulnerabilities or performance issues.

 

But as we are developers like this ability because we do not want the clients to upgrade a plugin himself (If it may breaks the site :-)) although this is not a good reason.
We are potentially risking security, performance, and additional features all because of a fear that the site will break down due to an upgrade, it’s bad it’s it?

 

Another reason that developers disable plugin updates is if they have customized the core files. You can also use a plugin like WP Manage plugins which allows you to disable plugin updates for specific plugins.

 

But if you want to hide all the updates related notifications, just all the below codes in your theme’s “functions.php” file.

 

<?php

//Disable WordPress Theme Updates 3.0+
remove_action( ‘load-update-core.php’, ‘wp_update_themes’ );
add_filter( ‘pre_site_transient_update_themes’, create_function( ‘$a’, “return null;” ) );
//Un-schedule all previously-scheduled cron jobs for WordPress themes versions/updates check
wp_clear_scheduled_hook( ‘wp_update_themes’ );

 

//Disable WordPress Plugin Updates 3.0+
remove_action( ‘load-update-core.php’, ‘wp_update_plugins’ );
add_filter( ‘pre_site_transient_update_plugins’, create_function( ‘$a’, “return null;” ) );
//Un-schedule all previously-scheduled cron jobs for WordPress plugin versions/updates check
wp_clear_scheduled_hook( ‘wp_update_plugins’ );

 

//Diasable WordPress Core Updates 3.0+
add_filter( ‘pre_site_transient_update_core’, create_function( ‘$a’, “return null;” ) );
//Un-schedule all previously-scheduled cron jobs for wordpress versions/updates check
wp_clear_scheduled_hook( ‘wp_version_check’ );

?>

Prevent spaces and specific unwanted substrings in WordPress usernames

You can prevent spaces and specific unwanted sub strings in WordPress usernames (restrict usernames wordpress), you have to prepared a regexp for this.

Prepare your regular expression and use the same in the below function.

After that put this function in your theme’s “functions.php” that’s it.

 

//Custom Function
/*
* add a filter to invalidate a username with spaces or have admin in keyword
*/

add_filter(‘validate_username’,’bpdev_restrict_space_in_username’,10,2);

function bpdev_restrict_space_in_username($valid, $user_name){

//check if there is an space in username
if ( preg_match(‘/\s|admin/’,$user_name) )
return false;//if yes, then we can say it is an error
return $valid;//otherwise return the actual validity
}

If you need any further help in this, left your comment.