WordPress Development Quick Start Guide - Rakhitha Nimesh Ratnayake - E-Book

WordPress Development Quick Start Guide E-Book

Rakhitha Nimesh Ratnayake

0,0
27,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

WordPress is the most used CMS in the world and is the ideal way to share your knowledge with a large audience or build a profitable business. Getting started with WordPress development has often been a challenge for novice developers, and this book will help you find your way.
This book explains the components used in WordPress development, when and where to use them, and why you should be using each component in specific scenarios. You begin by learning the basic development setup and coding standards of WordPress. Then you move into the most important aspects of the theme and plugin development process. Here you will also learn how themes and plugins fit into the website while learning about a range of techniques for extending themes and plugins.
With the basics covered, we explore many of the APIs provided by WordPress and how we can leverage them to build rapid solutions. Next, we move on to look at the techniques for capturing, processing, and displaying user data when integrating third-party components into the site design.
Finally, you will learn how to test and deploy your work with secure and maintainable code, while providing the best performance for end users.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 410

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



WordPress Development Quick Start Guide

 

 

 

 

 

 

 

 

 

 

Build beautiful and dynamic websites for your domain from scratch

 

 

 

 

 

 

 

 

 

Rakhitha Nimesh Ratnayake

 

 

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

WordPress Development Quick Start Guide

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor:Kunal ChaudhariAcquisition Editor: Reshma RamanContent Development Editor: Roshan KumarTechnical Editor: Shweta JadhavCopy Editor: Safis EditingProject Coordinator: Hardik BhindeProofreader: Safis EditingIndexer:Pratik ShirodkarGraphics:Alishon MendonsaProduction Coordinator:Deepika Naik

First published: October 2018

Production reference: 1291018

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78934-287-1

www.packtpub.com

 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the author

Rakhitha Nimesh Ratnayake is a freelance web developer, writer, and open source enthusiast. He has over 9 years of experience in developing WordPress applications and plugins. He develops premium WordPress plugins for individual clients and the CodeCanyon marketplace. User Profiles Made Easy and WP Private Content Pro are the most popular plugins developed by him. Rakhitha is the creator of WPExpertDeveloper, where he shares his latest WordPress plugins. Building Impressive Presentations with impress.js was his first book, which was published by Packt Publishing. He is also the author of the first three editions of WordPress Web Application Development. In his spare time, he likes to read books and spend time with his family.

I would like to thank my loving wife, Dulari; my daughter, Hesara; my parents; and my wife's parents for the help and encouragement provided throughout this book. I would also like to thank Packt Publishing, especially Senior Acquisition Editor, Reshma Raman, for inviting me to write this book; Content Development Editor, Roshan Kumar, and the reviewer for providing honest feedback to improve this book. Finally, I would like to thank you for reading my book and being one of the most important people who helped me make this book a success.

About the reviewer

Olivier Pons is a high skilled developer who's been building websites for many years. He's a teacher in France: at the University of Sciences of Aix-en-Provence, CESI and three other ones, where he teaches Python, Django, advanced JavaScript, nginx and Apache and Linux. In 2011, he left a full time job as a Php expert to concentrate on his own company, HQF Development. He currently runs a number of web sites, and you will easily find his web development blog if you google for "Olivier Pons". He's currently making a Unity mcq mobile application, which works together with a Django website. He works as teacher, high skilled developer and helps big companies and CTOs in making the best choice for their Web projects.

I would like to thank my family and friends for their never-ending support. I am also thankful to Packt Publishing and its amazing collection of videos, without whom none of this would be possible. I'd also like to thank Rakhitha Nimesh Ratnayake, author of the book, for putting together a very helpful guide about Wordpress Development; as well as Hardik Bhinde for giving me the opportunity to review this amazing book.

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

WordPress Development Quick Start Guide

Packt Upsell

Why subscribe?

Packt.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Code in action

Conventions used

Get in touch

Reviews

Introduction to WordPress Development

Introduction to WordPress development

Posts, pages, and custom post type management

User management

Form data management

Building custom layouts and extending theme layouts

Setting up the development environment

Installing the development stack

Installing and configuring WordPress

Setting up web browsers and code editors

Preparing development tools

Client-side monitoring with browser development tools

Server-side monitoring with WordPress plugins

Query Monitor

Debug This

Working with the configuration file

An overview of advanced configurations

Securing plugins and upload directories

Configuring advanced debugging settings

Script debugging

Logging errors and customizing php.ini rules

Understanding the role of the WordPress file and directory structure

How to choose files and directories for development

A brief overview of WordPress coding standards

Summary

Managing Database Structure, Storage, and Retrieval

Introduction to the WordPress database

Understanding the role of built-in database tables

Posts-related database tables

wp_posts 

wp_postmeta 

Terms-related tables

wp_terms 

wp_termmeta 

wp_term_relationships 

wp_term_taxonomy 

User-related tables

wp_users 

wp_usermeta

Options and comments tables

wp_options 

wp_comments 

wp_commentmeta 

Understanding the importance of database usage

Building existing features on the frontend

Customizing existing plugins

How to track database usage in WordPress

Using MySQL/MariaDB log files 

Comparing database backups 

Creating a manual query logger 

Tracking database usage of common WordPress features

Post creation

Page creation

User creation

Media uploads

Overview of the multisite database structure

Creating and managing custom tables

Creating custom tables

Executing basic CRUD operations on existing tables

Inserting records

Updating records

Deleting records

Selecting records

Executing basic CRUD operations on custom tables

Inserting records

Updating and deleting records

Selecting records

Summary

Designing Flexible Frontends with Theme Development

Technical requirements

Introduction to WordPress themes

Installing and configuring themes

Understanding the role of themes in development

What are application-specific themes?

Understanding built-in theme components

Identifying theme components that are used in existing sites

Getting started with developing themes

What is a child theme?

Creating a child theme

Modifying parent themes with a child theme

Building and customizing designs by modifying template files

Extending theme features through available filters and actions

Steps for extending theme-specific hooks

Working with the WordPress theme template hierarchy

Archive Page hierarchy

Author archive pages

Categories, tags, and custom taxonomy archives

Date Archive pages

Custom Post Type Archive

Singular Page Hierarchy

Static Page Hierarchy

Creating and using custom page templates

Single Post Page hierarchy

Attachment Post hierarchy

Blog post hierarchy

Creating and assigning page templates for posts

Custom post hierarchy

Other Pages in the template hierarchy

Site Front Page template path

Blog Posts Index Page template path

Error 404 Page template path

Search Result Page template path

Conditionally changing template design and content

What is conditional template design?

Adding conditions to theme files

Conditionally loading template files

Summary

Building Custom Modules with Plugin Development

Technical requirements

Understanding the role of plugins

WordPress plugin types based on features

Creating your first plugin

Exploring the life cycle of a plugin

Developing a post attachments plugin

Creating settings upon plugin activation

Implementing post attachment uploads

Uploading attachments and saving attachment data

Displaying uploaded attachments

Displaying attachments in posts

Implementing the post attachments download

Handling plugin version upgrades

Handling plugin deactivation

Uninstalling the plugin to clean the resources

Identifying the advantages of custom plugin development as a developer

Guidelines for building quality plugins

Summary

Extending Plugins with Addons, Filters, and Actions

Technical Requirements

Introduction to addons

Creating addons for plugins

Adding a filter hook for restricting attachments

Adding an action hook for counting downloads

Creating the attachments addon

The WordPress action execution process

The frontend action execution process

Scenario 1 – Using parent plugin features

Scenario 2 – Accessing the WordPress post object

Scenario 3 – Accessing the WordPress query object

The backend action execution process

How to use the priority of actions and filters

Identifying the extendable features of third-party plugins

Customizing third-party plugins

Techniques for customizing third-party plugins

Customizing look and feel using styles

Customizing the features with hooks

Building the WooCommerce product file manager

Adding the file upload field to WooCommerce products

Adding scripts for uploading files

Uploading files to products

Introduction to AJAX in WordPress

Displaying uploaded files in products

Integrating multiple plugins for a continuous workflow

Types of plugin integrations

Custom integrations

One-sided integrations

Mutual integrations

Considerations in custom plugin integrations

Checking the feasibility of integration

Identifying exact data changes and hooks

Checking the impact with other plugins

Implementing multiple plugin integrations

Assigning points for completed orders

Adding users to BuddyPress private groups

Summary

Practical Usage of WordPress APIs

Technical Requirements

A brief overview of WordPress APIs

Using built-in APIs

Introducing shortcodes

Structure of a shortcode

Developer's perspective of a shortcode

Content creator perspective of a shortcode

User's perspective of a shortcode

Using built-in shortcodes

Building custom shortcodes

Creating custom shortcodes

Restricting content using a shortcode

Displaying posts with attachments

Understanding the usage of shortcodes

Tips for using shortcodes

Managing custom routes with Rewrite API

Understanding the need for custom routes

Creating the routing rules

Adding query variables

Flushing the rewriting rules

Displaying content for custom routes

Building remote connections with REST API

Introducing core REST API endpoints

Understanding and testing Core API endpoints

Managing custom routes and endpoints

Creating custom routes for posts

Creating custom routes and endpoints for custom table data

Building the REST API client

REST API client from external site

Summary

Managing Custom Post Types and Processing Forms

Technical requirements

Introduction to custom post types

Why do we use custom post types for modeling data?

Building an object-oriented plugin

Building custom post types for properties

Creating property custom post types

Creating the property types taxonomy

Managing custom fields for custom post types

Building the property fields template

Saving property custom fields

Limitations of storing data as meta values

Introduction to form management

Building custom forms in the frontend

Adding forms using a shortcode

Creating properties using custom forms

Loading forms using custom URLs

Choosing between custom post types and custom forms

Using a form management plugin

Summary

Discovering Key Modules in Development

Technical requirements

UI components

Integrating the jQuery image slider

Building a product image slider

Creating a plugin menu page

Saving slider images using AJAX

Preparing slider images

Integrating jQuery slider

Reusing the slider as a widget

Integrating jQuery accordion

Creating an accordion model and capturing data

Preparing accordion content

Steps for integrating UI components

Simplifying development with page builders

Understanding the features of page builders

Developing components for page builders

Simplifying and customizing admin features

Creating custom dashboard widgets

Registering and building dashboard widgets

Customizing backend list tables

Creating and executing custom bulk actions

Adding custom list columns

Sorting custom column values

Summary

Enhancing Security, Performance, and Maintenance

Introduction to testing

Unit and integration testing

Code quality testing

Using the PluginTests service

Performance testing

P3 - the Plugin Performance Profiler plugin

Securing WordPress sites

Migrating WordPress sites

Maintaining WordPress sites

Backup files and databases

Updating WordPress plugins and themes

Optimizing database tables 

Checking request errors and broken links

Checking error logs

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

WordPress is the most widely used CMS in the world. As a developer, WordPress is the ideal way to share your knowledge with a large community as well as build a profitable business. Getting started with WordPress development has been a challenge for novice developers, compared to building everything from scratch in other frameworks. It's very easy to build WordPress sites by connecting bits and pieces without actually knowing what's happening under the hood. Many developers tend to follow this path and face maintenance and security nightmares in the long run. This book is structured to explain the components used in WordPress development, when and where to use them, and why you should be using each component in specific scenarios.

You will begin this book by learning the basic development setup and coding standards of WordPress. Mastering the built-in database is one of the keys to becoming a expert in WordPress development. In this section, you will learn about the database structure, and examine the data usage of the built-in features and their limitations in order to plan the data needs of your application. Then you will move onto an important topic: the theme and plugin development process. In this section, you will learn how themes and plugins fit into an application while understanding basic to advanced techniques for extending themes and plugins.

With the basics covered, we explore the use of the wide range of APIs provided by WordPress and see how we can leverage them to rapidly build solutions. Next, we move onto another essential section, where we explore the techniques for capturing, processing, and displaying user data while integrating third-party components into the site's design. Finally, you will learn how to test and deploy the application with secure and maintainable code, while providing the best performance for end users.

By the end of this book, you will have the ability to choose the right components for any development task and build flexible solutions that work with existing plugins and themes.

Who this book is for

This book is intended for web developers and site owners who are planning to build custom websites with WordPress. Also, web developers could use this book as a starting point for getting into plugin and theme development. 

What this book covers

Chapter 1, Introduction to WordPress Development, covers the basic installation and configuration process of WordPress. Setting up the development environment, an introduction to WordPress coding standards, and understanding the WordPress file/folder structure are the highlights of this chapter.

Chapter 2, Managing Database Structure, Storage, and Retrieval, introduces you to the existing WordPress database table structure and its role in custom development. Executing basic queries, managing custom tables, and tracking the database usage of various features are the highlights of this chapter.

Chapter 3, Designing Flexible Frontends with Theme Development, explores the role and features of a theme in custom development. In-depth coverage of template hierarchy, custom template design, and custom development techniques in themes are the highlights of this chapter.

Chapter 4, Building Custom Modules with Plugin Development, explores the role of plugins and introduces the basics of developing a simple plugin. Understanding plugin life cycle events, identifying advantages of building plugins, and developing a plugin covering life cycle events are the highlights of this chapter.

Chapter 5, Extending Plugins with Add-ons, Filters, and Actions, focuses on extending existing plugins and core features with the use of add-ons and WordPress hooks. Customizing third-party plugins, integrating multiple plugins, and identifying the extendable features of existing plugins are the highlights of this chapter.

Chapter 6, Practical Usage of WordPress APIs, explores WordPress APIs and their functionality in custom development. Mastering the use of shortcodes, building custom routes with the Rewrite API, and allowing remote connections with REST APIs are the highlights of this chapter.

Chapter 7, Managing Custom Post Types and Processing Forms, explains the primary data capturing and managing process with custom post types and custom forms. Building object-oriented plugins for handling property management site with custom post types and building custom forms in the frontend are the highlights of this chapter.

Chapter 8, Discovering Key Modules in Development, dives into the process of improving user experience with interactive designs and customized backend features. Integrating UI components, working with page builders, and simplifying backend admin features are the highlights of this chapter.

Chapter 9, Enhancing Security, Performance, and Maintenance, covers the non-functional aspects of development for building quality and reliable sites. Identifying the process of testing, steps for securing sites, migrating sites using plugins, and exploring the primary tasks of maintenance are the highlights of this chapter.

To get the most out of this book

Basic knowledge of PHP, JavaScript, HTML and CSS is required. You also need a computer, a browser, and an Internet connection with the following working environment:

An Apache web server

PHP version 5.4 or higher

WordPress version 4.9.8

MySQL version 5.6+ 

OR MariaDB 10.0+

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/WordPressDevelopmentQuickStartGuide. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781789342871_ColorImages.pdf.

Code in action

Visit the following link to check out videos of the code being run:

http://bit.ly/2AzlbTj

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Introduction to WordPress Development

WordPress is the most widely-used CMS in the world, and the demand for developers is on the rise. Beginner WordPress developers are often restricted to using existing plugins and making minor modifications with the theme functions file. As a developer, you need a thorough understanding of WordPress core modules and components, along with a proper development setup to tackle complex application requirements.

This chapter focuses on introducing you to the prerequisites of WordPress development while clearing up some of the misconceptions about development. Unlike other frameworks, WordPress doesn't have an MVC architecture or similar. So, developers have the freedom to find their own techniques. We will begin by having a high-level overview of how developers can use the existing features in development, as well as the techniques for integrating our code with WordPress components. Then, we will move on to installing WordPress and discussing the use of configuration files with default and advanced configurations. Development tools and coding standards are the keys for producing quality code, and hence we will discuss the use of WordPress-specific coding standards as well as the use of popular open source development tools.

In this chapter, we will cover the following topics:

Installing and configuring a development environment for WordPress

How to use a WordPress configuration file

A high-level overview of the WordPress file/directory structure and their use in development

A brief introduction to WordPress coding standards and its usage

Using popular tools for debugging code

By the end of this chapter, you will have the necessary knowledge to understand the key development areas of WordPress and preparing the development environment for a smooth workflow.

Introduction to WordPress development

This book is intended for beginner WordPress developers and site owners who want to build custom websites with WordPress. We dive into developing solutions with WordPress, it's important to understand what exactly development is, and the areas involved. There are many people who call themselves WordPress developers and yet haven't done anything beyond changing some theme designs and using the theme functions file. WordPress development can range from simple theme design changes to building a complex web application.

Here are the components involved in WordPress development:

Theme functions file

: The first technique you encounter when getting started with development. Usually, we can add small code snippets using filters and actions to change the functionality of theme or plugins. Since this file is updated on theme updates, it's not recommended to add your own custom code. However, there are exceptions when using your own theme or a theme without version updates. This is a good starting point to add some code and learn how WordPress can be customized with actions and filters.

Child themes

: This is the next step in development, before diving into complex implementations using plugins. The child theme is a theme that we create based on an existing theme. We can either override all files in the child theme or only add the necessary files to override. If you are starting WordPress development and want to add some quick code snippets, creating a child theme and using the functions file is the ideal solution. In development, the child theme should be used for minor implementations such as design changes or displaying more/less data on frontend screens. Since we only use the

functions.php

file for code changes, this technique is not recommended for implementing advanced features. However, modern themes are packed with features and hence there may be exceptions for doing advanced implementations in child themes.

Plugins

: As a developer, developing plugins is the most important aspect of building custom websites. Plugins allow you to build independent and extendable solutions. Usually, it's a good practice to add any customization into a separate plugin or a site-specific common plugin based on its scope. You can create plugins to customize existing WordPress backend and frontend features, theme functionality, as well as developing completely new features beyond WordPress's built-in modules.

Addons

: Even though we call these addons, they are a plugin that extends the features of another plugin. In WordPress development, we are not going to build everything from scratch as there is a huge free plugin repository and thousands of premium plugins for doing all kinds of things. Most of these existing plugins are not going to align perfectly to our requirements. Therefore, we need a way to customize the features of such plugins without losing the changes on plugin updates. Addons extend the features of plugins by using actions, filters, and APIs provided by the plugin.

These are the main components and files for developing your own solutions in WordPress. Now, we need to shift focus to major areas involved in development and how they fit into WordPress. Let's review the use of existing features in development as well as custom build features.

Posts, pages, and custom post type management

Since its inception, WordPress was used as a basic CMS with the primary focus on blogging. After so many years, posts and pages are still the main aspect of WordPress, with the addition of custom post types. The primary feature of many sites is the management of posts. So, you need to master each and every aspect of post creation, editing, displaying, and managing additional data. With the arrival of custom post types, developers can match many of the user data capturing application requirements. Since the basic features such as creating, editing, displaying, and listing are inbuilt with custom post types, developers can focus on extending these features at a rapid pace.

Many large-scale applications such as event management systems, online shops, realestate sites, and job management sites are modeled using custom post types, and hence it's a primary feature in WordPress development.

User management

This is another built-in module with comprehensive functionality for user data, access levels, and permissions. You may find the need for registered members in many modern applications and sites. So, you can use the features of existing user modules to handle basic user data and permissions, while developing advanced features such as frontend login, registration, and profile management with the extension of core features.

Similar to custom post types, you will find many applications with one of the primary features as user management. Forums, online student management systems, and CRMs are some of the examples of high-level user management applications with WordPress.

Form data management

The process of capturing, processing, and displaying user data is the primary feature of many websites. We already discussed the use of custom post types for simplifying the data modeling process. However, inbuilt custom post type features are only available in the backend. Form management is essential for capturing the user data to the custom post types from the frontend. There are certain limitations that force us to use form management from scratch without using custom post types on some occasions. Such limitations include the use of existing database tables, hooks, and built-in templates in custom post types.

We can add forms using theme templates, shortcodes, or existing hooks. Modern JavaScript libraries will be used to process them while using custom database tables to enhance flexibility. So, this is another essential skill in WordPress development.

Building custom layouts and extending theme layouts

Each WordPress site or application is built around a theme and set of plugins. In general, most people prefer to use a high-quality existing theme, while some of them require a complete theme built for them from scratch. Regardless of these preferences, you need to be skilled in theme development, in order to cater to modern trends. Widget-based dynamic screens, responsive layouts, and dynamic content displays based on user preferences are some of the modern trends used in themes. The most common form of development is the customization of existing theme layouts and building new post/page templates.

Modern applications may also require you to add complex features into the theme instead of separating them into plugins. So, you need to have hands-on experience in theme files as well as common theme hooks for building advanced user interfaces.

These are some of the frequently involved areas in WordPress development, and hence you need to be familiar in order to deliver rapid solutions. Apart from these areas, you can extend most WordPress features using existing hooks, as well as build custom features such as APIs, integration of third-party UI components, and so on.

Setting up the development environment

In order to get started with WordPress development, you will need a working development environment that supports WordPress. So, we need to focus on the essential steps for building a development environment, such as the following:

Installing a development stack that supports PHP, Apache, and MySQL or Maria DB

Installing and configuring WordPress

Setting up web browsers and code editors

Let's take a quick look at each of these options for building the ideal development environment for WordPress.

Installing the development stack

The most basic requirements for running WordPress include PHP, Apache server, and a MySQL database. So, we need to either install these components from scratch or use existing tools such as WAMP, XAMPP, or MAMP. Since this book is about a quick start to WordPress development, we are going to use existing tools without wasting time on manual installation. You can choose the tool depending on your operating system. For this book, we are going to use the WAMP server on the Windows platform.

The WAMP server offers a built-in installation process, and all you need is to provide the requested inputs while going through several well-defined installation screens. Since this is already discussed in several online resources, we are not going to explain the installation process here. You can refer to http://www.wampserver.com/en/ for instructions on setting up WAMP.

Installing and configuring WordPress

Once the development stack is installed, we can move to the WordPress installation process. WordPress offers one of the simplest automated processes for installing a software framework. The complete installation process takes no more than 5-6 steps and a few minutes. Since it's already documented comprehensively in the WordPress codex, we are not going to waste time explaining it from scratch. You can refer to https://codex.wordpress.org/Installing_WordPress#Detailed_Instructions for the complete installation process.

Even though installation is a simple process, configuration might vary based on your requirements as well as different environments. Therefore, we are going to discuss the configuration in detail in the upcoming sections.

Setting up web browsers and code editors

As a developer, you should already have at least two browsers installed on your system. WordPress is frequently updated with modern versions of libraries and trends, such as responsive design. So, you need to make sure that the available browsers are updated to the latest versions. Also, you may have to install all popular browsers such as Chrome, Firefox, Opera, Safari, and Internet Explorer to adhere to browser compatibility.

A code editor is another important aspect of development, where developers need to choose one that favors their personal interests. Some popular code editors include Sublime Text, Brackets, Textmate, and Notepad++. When choosing a code editor, you need to look for essential features, such as the following:

Supported programming languages

Syntax highlighting and code readability

Autocompletion

Simplified indentation and formatting

Version management

File/folder search and replacement

Many of these editors are fully featured solutions and hence all these features are available by default. In such cases, you can make the decision based on your personal preferences. At this point, our development environment is ready with the most common tools for getting started.

Preparing development tools

Even though we can start the development right away, it's important to have the necessary tools that make our tasks easier as developers, while saving precious time. You can find hundreds of developer tools created to test and debug the code and help you pinpoint the issues in your implementations. Here, we are going to look at some of the most essential tools to support your development.

Client-side monitoring with browser development tools

There was a time when we had to install different extensions to use development tools in different browsers. Now, development tools have become the norm in the latest versions of all modern browsers. These tools provide a wide range of facilities to debug your code. The following screenshot previews the developer tools section of the Chrome browser:

The preceding screenshot previews the Console tab, where you will see errors, notices, and information related to user requests. This tab simplifies the process of tracking and fixing errors in your client-side coding. We can also use other tabs such as Sources, Network, Performance, Security to track AJAX requests, file loading precedence, memory, and bandwidth usage, along with possible security risks.

"AJAX is a short term for Asynchronous JavaScript and XML. AJAX is a set of web development techniques using many web technologies on the client side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously (in the background) without interfering with the display and behavior of the existing page."
– Wikipedia

Other browsers provide built-in development tools with similar features. The Firefox browser consists of Inspector,Console, Debugger, Style Editor, Performance, Memory, Network, and Storage tabs. Internet Explorer consists of DOM Explorer, Console, Debugger, Network, UI Responsiveness, Profiler, and Memory tabs. The main feature set is consistent across all browsers. As a developer, you should use browser tools at least for simple tasks, such as monitoring errors, inspecting HTML tags, tracking AJAX requests, and testing CSS styles.

Server-side monitoring with WordPress plugins

The WordPress plugin repository provides quite a few plugins to help developers track errors, performance issues, styles used in requests, executed hooks, loaded scripts, and various kind of other useful features. It's up to you to choose the number of plugins to use, and which plugins to use. In this section, we are going to look at some of the most popular plugins for debugging and testing.

Query Monitor

This is the most widely used plugin among the recently updated plugins in the debug category. The primary functionality of this plugin is to monitor the database queries in user requests and help you optimize them. We use many plugins to build a WordPress site, and hence each user request may execute a large number of queries. In most scenarios, a considerable amount of queries are not relevant to the user request and executed due to low quality coding from plugin developers. This plugin allows you to track queries by plugin, making it easier to identify the plugins responsible for executing a large number of queries, as well as unnecessary ones.

The following screenshot previews the use of Query Monitor to track the queries executed by the WordPress core and individual plugins:

Apart from monitoring queries, you can also use this plugin to check hooks, scripts, and styles loaded in the current user request. Query Monitor is a must-use plugin for WordPress. You can find more details about Query Monitor plugin at https://wordpress.org/plugins/query-monitor/.

Debug This

This is one of the more recently created plugins to support developers. Unlike Query Monitor, this plugin doesn't have a primary feature. Instead, it offers a wide range of features for tracking all types of features in WordPress. You can track shortcodes, post types, PHP class/function usage, media attachments, and many other things, along with the features we already discussed in Query Monitor.

The following screenshot previews the use of Debug This with the list of available features:

As you may notice, this is an extremely useful tool for developers. The only drawback is the output of information as plain arrays, making it difficult to read. Even though it lacks the proper organization of information using user-friendly screens, you can resolve complex issues without using your own var_dump inside the code. You can find more details about the Debug This plugin at https://wordpress.org/plugins/debug-this/.

Apart from these two plugins, there are more useful plugins to help developers write quality code and save time with error handling and optimization. The following is a list of such plugins to be used in development:

What The File

(

https://wordpress.org/plugins/what-the-file/

): This plugin allows you to quickly track the templates and template parts used in the current user request. It also supports BuddyPress-based themes.

Debug Bar

(

https://wordpress.org/plugins/debug-bar/

): This plugin is similar to the

Debug This

plugin. However, it provides fewer features and a better user interface.

We looked at most popular testing and debugging plugins in the WordPress plugin repository. There are premium plugins and online services for further improving the development process. You can test these plugins and see which ones fit into your development environment.

An overview of advanced configurations

As a developer, you will have to build from simple WordPress blogs to fully functional web applications. So, advanced configurations become important for security, advanced features, and the performance of applications. Let's take a quick look at how you can modify the configuration file using other configuration options.

Securing plugins and upload directories

Due to the open source nature of WordPress, everyone knows where plugins and files are stored in your site. Therefore, the process of hacking or spamming your site becomes easier for potential attackers. As a solution, we can move plugin and upload directories to a different path using the config file, to increase the difficulty of finding paths to attack.

Let's add more configurations to change the default location of these directories:

define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/example.com/modules/' ); define( 'WP_PLUGIN_URL', 'http://localhost/ example.com /modules/'); define( 'UPLOADS', 'modules/media' );

The first two lines move the plugin directory from wp-content/plugins to the modules directory in your root directory. Since the path has changed to the root directory, it will be difficult for attackers to identify the path. These configurations only change the directory. If you already have plugins in the wp-content/plugins directory, you will have to move them manually to a new directory. The next line changes the media upload path from wp-content/uploads to the modules/media directory inside the main installation.

The process of moving the theme directory is not straightforward as the path is configured relative to the wp-content directory. Therefore, you will have to change the main path of the wp-content directory in situations where you want to change the theme directory. You may use these configurations manually, or use existing plugins to help secure your site.

Configuring advanced debugging settings

Earlier, we enabled debugging in the development environment by setting WP_Debug to TRUE. There are more settings to control the debugging process and provide more information on issues in our code. Let's walk through some of the advanced options for developers.

Script debugging

In general, conflicts in JavaScript files are a common problem due to the use of different script versions in different plugins and themes. Identifying these errors is a cumbersome process when using minified versions and concatenated script files. Let's take a look at some of the rules used for resolving these issues:

define( 'SCRIPT_DEBUG', true ); define( 'CONCATENATE_SCRIPTS', false );

The first line enables script debugging by loading the uncompressed file instead of the minified version. The second line prevents concatenation of multiple scripts, allowing you to track the line of the error. You should use these configuration rules when you are experiencing script issues in WordPress core files.

Logging errors and customizing php.ini rules

We can either display the coding errors in the browser or log them to a separate log file. It's at the preference of the developer, but I think logging the errors is the ideal solution for future reference. Also, sometimes we need to change the PHP configurations to make our code work. Many hosting servers will not allow you to directly edit the php.ini file, and hence we can use the wp-config.php file to override the default settings of the php.ini file.

Some hosting providers don't provide access to change the php.ini file, and you will have to request modification through server support.

Consider the following configuration rules for error logging with php.ini modifications:

@ini_set( 'log_errors', 'On' ); @ini_set( 'display_errors', 'Off' ); @ini_set( 'error_log', '/home/example.com/logs/php_error.log' );

First, we enable error logging in PHP and disable displaying errors in the browser by using the display_errors setting. Then, we define the path of the file where errors will be logged. You need to create this directory first and provide the necessary write permissions before this rule takes effect.

In this section, we had a brief overview of some of the most basic and advanced configurations in WordPress development. There are many other settings to help developers, as well as control features. You can take a look at the available configurations and their use in the WordPress codex at https://codex.wordpress.org/Editing_wp-config.php. Now, we have the complete setup to begin development tasks on top of WordPress.

Understanding the role of the WordPress file and directory structure

Beginning WordPress development is not a complex task. It's about making minor theme changes, installing and customizing existing plugins, and using the available hooks. As you move on, complex requirements come your way with the expectation of future-proof solutions. Trying to build such solutions without considering future WordPress, plugin, and theme versions can lead to a nightmare. Getting used to existing WordPress files/directories and knowing their role is vital in developing maintainable solutions. In this section, we are going to look at the existing files and directories of a default WordPress installation.

The following is a screenshot of typical files and directories inside your WordPress installation:

Let's look at some of the most important files and directories inside WordPress:

wp-admin

: This is where WordPress stores files related to admin-side functionality. The files in this directory are based around the

admin.php

file. Primary functionalities of these files include checking admin permission, connecting to the database, and loading the admin dashboard features. This directory is upgraded with WordPress version updates and hence the content of these files is replaced.

wp-content

: This is where WordPress stores user-uploaded files such as plugins, themes, and media files. We can add additional files/directories here without being affected by WordPress version updates. So, the content in this directory will not be replaced.

wp-includes

: This is the largest directory in WordPress with over 800 files to power the features of the admin dashboard as well as frontend functionality. The primary file in this directory is

functions.php

, considered as the main WordPress API. This directory is upgraded with WordPress version updates and hence the content of these files is  replaced.

.htaccess