WordPress Development Quick Start Guide
Build beautiful and dynamic websites for your domain from scratch
Rakhitha Nimesh Ratnayake
- 300 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
WordPress Development Quick Start Guide
Build beautiful and dynamic websites for your domain from scratch
Rakhitha Nimesh Ratnayake
About This Book
Learn core WordPress concepts and components to create modern WordPress-based solutions
Key Features
- Learn the foundations of WordPress development and its hook-based architecture
- Choose the right components for any development task
- Build flexible solutions that works with existing plugins and themes
Book Description
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.
What you will learn
- Explore the role of themes, plugins, and built-in features in development
- Adapt to built-in modules and built-in database structures
- Write code for WordPress's hook-based architecture
- Build, customize, and integrate WordPress plugins
- Extend themes with custom design templates
- Capture and process data with built-in features and custom forms
- Improve usability with AJAX and third-party components
- Manage non-functional aspects, such as security, performance, and migration
Who this book is for
This book is for web developers and site owners who want to build custom websites with WordPress. Basic knowledge of PHP, JavaScript, HTML and CSS is required to get most out of this book.
Frequently asked questions
Information
Extending Plugins with Addons, Filters, and Actions
- Introduction to addons development
- Creating a basic addon for the post attachments plugin
- Understanding the WordPress core action execution process
- Customizing third-party plugins
- Identifying techniques for integrating plugins
- Integrating multiple plugins for continuous workflow
Technical Requirements
have a later version of WordPress, the described examples should work with no significant problems.
https://github.com/PacktPublishing/WordPress-Development-Quick-Start-Guide/tree/master/Chapter05
http://bit.ly/2Q8LtBa
Introduction to addons
- WooCommerce: This is an eCommerce plugin that allows you to sell physical goods as well as digital products. This plugin has an extensive addons base of over 250 addons in various categories. Payment gateways are the most popular type of addon in WooCommerce with over 75 addons. You can view and learn more about the addons base at https://woocommerce.com/product-category/woocommerce-extensions/.
- Easy Digital Downloads: This is an eCommerce solution allowing you to sell digital products. This plugin also offers over 100 addons while many of them fall into the marketing category. You can learn more about the addons base at https://easydigitaldownloads.com/downloads/.
- WP Bakery Page Builder: This is a plugin used for building page using pre-built components. Both WooCommerce and Easy Digital Downloads are free plugins in the WordPress plugin directory. However, this is a premium-only plugin with over 250 addons in various categories. The UI elements is the most popular addon category for this plugin. You can view and learn more about the addons base at https://wpbakery.com/addons/.
Creating addons for plugins
- Restrict attachment file types based on default WordPress user roles. Let's provide PDF file access only for non-subscriber members and all other file types to all users in the site.
- Download counter for attachments. We have to count the number of downloads for all attachments of a post, separately for guest users and logged-in users.
Adding a filter hook for restricting attachments
$display .= '
<div class="wpqpa-file-item" id="PF'.$file_row->id.'" data-file-id="'.$file_row->id.'" >
<div class="wpqpa-file-item-row" >
<div class="wpqpa-file-item-name wpqpa-files-list-name" >'.$file_row->file_name.'</div>
<div class="wpqpa-file-item-download" ><a href="'.$url.'" >'.__("Download","wpqpa").'</a></div>
<div class="wpqpa-clear"></div>
</div>
<div class="wpqpa-clear"></div>
</div>';
$file_display = '
<div class="wpqpa-file-item" id="PF'.$file_row->id.'" data-file-id="'.$file_row->id.'" >
<div class="wpqpa-file-item-row" >
<div class="wpqpa-file-item-name wpqpa-files-list-name" >'.$file_row->file_name.'</div>
<div class="wpqpa-file-item-download" ><a href="'.$url.'" >'.__("Download","wpqpa").'</a> </div>
<div class="wpqpa-clear"></div>
</div>
<div class="wpqpa-clear"></div>
</div>';
$file_display = apply_filters('wpqpa_post_attachment_list_item', $file_display, $file_row);
$display .= $file_display;
Adding an action hook for counting downloads
$file_mime_type = mime_content_type( $file_dir );
if( $file_mime_type != '' ){
do_action('wpqpa_before_download_post_attachment',$attachments[0]);
header( 'Cache-Control: public' );
header( 'Content-Description: File Transfer' );
Creating the attachments addon
add_filter( 'wpqpa_post_attachment_list_item', 'wpqaa_post_attachment_list_item' , 10 ,2 );
function wpqaa_post_attachment_list_item( $display, $file_data ){
$upload_dir = wp_upload_dir();
$file_dir = $upload_dir['basedir'] . $file_data->file_path;
$file_mime_type = mime_content_type( $file_dir );
if($file_mime_type == 'application/pdf'){
if( !is_user_logged_in() || ( is_user_logged_in() && current_user_can('subscriber') ) ){
$display = '';
}
}
return $display;
}
- The callback function has two parameters, with the first one being the HTML for displaying the file link and the second one being the details about the file from database.
- First, we construct the path of the file by using the WordPress wp_upload_dir function and file path captured from our custom table.
- Then, we use the PHP mime_content_type function to get the MIME type of the attachment.
- Next, we filter the files with the MIME type for PDF.
- Then, we use the condition to check whether the file should be displayed to the user. The first part of the condition checks if we are logged into the site, as the file needs to be restricted for guest users. The second part of the condition checks if the user is logged in as a subscriber.
- We restrict the file by emptying the content when one of these conditions is met.