Setting up development environment is a tedious processes. Vagrant makes it easier to create and configure lightweight, reproducible, and portable development environments.
We can use vagrant box to create our WordPress development environment, where nginx, php, MySQL, WordPress and other necessary softwares were pre-installed.
I wrote a solution for that, named WordPress-Vagrant.
Laravel framework offers a nice vagrant box named Homestead, that already contains almost everything that we need. So, instead of creating a new box from scratch, I did use homestead as base box and added WordPress on it.
Once you clone the repository and setup according to instructions, you shall get a virtual machine with following softwares pre-installed.
- Ubuntu 14.04
- PHP 5.6
- Node (With PM2, Bower, Grunt, and Gulp)
- Memcached (PHP 5.x Only)
- Running WordPress instance
Newly created WordPress instance can be accessable by visiting http://wordpress.app
All WordPress files serve from a directory named wordpress, inside your project directory on your local machine. So, you can use your favourite IDE for writing your codes.
Initially wordpress directory contains no files. When you run vagrant up, it will dump all WordPress files for you.
Visit WordPress-Vagrant and feel free to fork.
WordPress has WP_Error class for checking WordPress errors and error messages since version 2.1.0. WordPress uses object of WP_Error class for reporting errors from several WP functions. However, we can use this object in plugin or theme to handle error within WordPress. This class containing various useful method for managing error.
Constructor of WP_Error allows three parameters: $code, $message and $data
$error = new WP_Error( $code, $message, $data );
here, $code containing error code. it may be string or integer, $message containing error message and $data containing error data. however all parameter are optional.
Suppose, we want to report new error, so we can use:
$error = new WP_Error( 'not_found', 'Page Not Found', 'Page Data' );
Here, we consider not_found as error code, ‘Page Not Found’ as error message and ‘Page Data’ as error data.
After creating error object we can check error by is_wp_error function.
All WordPress ajax request can be handle by admin-ajax.php
WordPress uses wp_ajax_ and wp_ajax_nopriv_ action hooks to handle ajax requests.
This is a sample plugin to allow users to select sub category from parent category by ajax load.
Sometimes WordPress asking you for ftp details when you are going to add new plugins or themes or going to upgrade. In that case it also restrict you to edit your file or .htaccess file. This problem occur while your WordPress don’t have sufficient or wrong FTP info for accessing your files in server.
To overcome this problem, let your wordpress know about your FTP account by adding those lines in wp-config.php file.
//*For using SSL Connection set this to true*