Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WordPress Plugin Development Cookbook

You're reading from   WordPress Plugin Development Cookbook Create powerful plugins to extend the world's most popular CMS

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher
ISBN-13 9781788291187
Length 386 pages
Edition 2nd Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Yannick Lefebvre Yannick Lefebvre
Author Profile Icon Yannick Lefebvre
Yannick Lefebvre
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Preparing a Local Development Environment FREE CHAPTER 2. Plugin Framework Basics 3. User Settings and Administration Pages 4. The Power of Custom Post Types 5. Customizing Post and Page Editors 6. Accepting User Content Submissions 7. Customizing User Data 8. Creating Custom MySQL Database Tables 9. Leveraging JavaScript, jQuery, and AJAX Scripts 10. Adding New Widgets to the WordPress Library 11. Enabling Plugin Internationalization 12. Distributing Your Plugin on wordpress.org

Downloading and configuring a local WordPress installation

The next component of our local development environment is to install WordPress on your local web server to run a fully working website and have all of its files hosted locally.

WordPress has always prided itself with its easy five minutes installation process. Installing it on a local web server is even easier and quicker than it would be on a live remote server. This recipe covers the creation of a MySQL database to store all data related to our new WordPress installation and the actual setup process.

Getting ready

This recipe assumes that you have a local web server installed on your computer. This web server can be a fresh install performed using the previous recipe or can be from a previous installation. The steps in the following section are written with a focus on new local web servers. If you have created a new account to access the MySQL database or changed the root user's password, some of the steps will change slightly. The location of the phpMyAdmin tool might also be different if you are using a different web server than XAMPP. You should refer to your web server's documentation to find out what that address is.

How to do it...

  1. In the web browser, navigate to the address http://localhost/phpmyadmin/ to access your web server's database administration tool.
  2. Click on Databases tab in phpMyAdmin.
  3. Type the name of the new database to be created in the empty field following to the words Create database. In this case, we will use the name wordpressdev:
  1. Click on the Create button to complete the database creation process.
  2. Download the latest WordPress installation package from the official WordPress website (https://wordpress.org). The download link can be found on the very first page of the website and the download package will work on any web server, local, or remote.
The following instructions have been tested against WordPress version 4.8. While the installation process does not usually change much between versions, there may be slight differences in these steps on newer versions.
  1. Extract the WordPress archive file contents using your favorite file archiver utility or your operating system's built-in capabilities.

 

  1. Copy the contents of the resulting wordpress folder to your local web server's web content directory (c:\WPDev, if you followed the previous recipe). You should not copy the wordpress folder itself unless you want the address of your WordPress website to be http://localhost/wordpress.
  2. Direct your web browser to http://localhost to start the WordPress installation process.
  3. Select your preferred language and click on Continue.
  4. On the next page, click on the Let's Go button to start your development site's configuration.
  5. Update the Database Name field to reflect the name of our newly-created database (wordpressdev).
  6. Set the MySQL User Name to root.
  7. Delete all the characters from MySQL Password to leave it empty, since local MySQL server root accounts are typically configured without any password.
  8. Leave the Database Host field with its default value (localhost).
  9. Change the Table Prefix field from its default value to wpdev_:
  1. Click on the Submit button to validate the information entered. If any parameters are not entered correctly, or if the WordPress installation process cannot correctly access your database server, it will display an error page and give you an opportunity to make corrections.
  2. Click on the Run the install button for WordPress to create the required table structure in the designated MySQL database.
  3. Specify a Site Title (for example, Development Site).
  4. Set Username for the admin user. For increased security, it's always best to choose a username that people would not be able to easily guess. Obvious names such as admin or administrator should be avoided.
  5. Optionally, change the randomly generated password with a password of your own choice. If WordPress determines that your new password is weak, you will need to check the additional checkbox that appears to confirm that you want to use a weak password.
  6. Enter your email address in the appropriate field (although no email will actually be sent on most local development installations).
  7. If you are configuring a live external development server, check the Discourage search engines from indexing this site option, since we do not want this development site to appear anywhere.
  8. Click on Install WordPress to complete the installation and you will be automatically logged in to the site's WordPress Dashboard.

 

  1. Click on the Development Site link in the Dashboard admin bar to see your new site:

How it works...

In the first few steps, the phpMyAdmin interface is used to create a database on the local MySQL server. This web-based database management tool comes bundled with XAMPP and most other web servers. The http://localhost/phpmyadmin address will always take you to the database administration tool, even if you relocate your web server's document root directory as documented in the previous recipe.

Once a database is created and the WordPress files have been copied to the correct location, pointing your browser to the local web server gets it to search through the document root directory to find HTML files to send back to the browser or PHP files to execute. In the case of WordPress, the web server finds the index.php file and executes it using its PHP interpreter. As the WordPress code is executed, it checks if a configuration file is present and launches the installation process when it does not find one. The WordPress code does not see any difference between the local web server that we are running it on and a remote live web server that would be accessible anywhere online.

While we specified an email address for the administrator during the installation, many local web servers are not configured to send out email messages so we will never receive any email communication in these cases. It is preferable to use a remote server when developing and testing email functionality in a plugin.

Once this recipe has been completed, you will have a functional WordPress installation in place.

You have been reading a chapter from
WordPress Plugin Development Cookbook - Second Edition
Published in: Jul 2017
Publisher:
ISBN-13: 9781788291187
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime