WordPress Plugin Development Cookbook - Third Edition

Book description

Create plugins for WordPress through detailed recipes that cover the creation of shortcodes, custom post types, and custom blocks, integrate data from external sources, and do much more with this recipe-based guide

Key Features

  • Create plugins that change and extend WordPress to perform virtually any task
  • Extend the WordPress Block Editor (Gutenberg) and other components with the help of detailed examples and explanations
  • Customize WordPress to meet your project's needs and create plugins that benefit the entire community

Book Description

WordPress is one of the most widely used, powerful, and open content management systems (CMSs). Whether you're a site owner trying to find the right extension, a developer who wants to contribute to the community, or a website developer working to fulfill a client's needs, learning how to extend WordPress' capabilities will help you to unleash its full potential. This book will help you become familiar with API functions to create secure plugins with easy-to-use administration interfaces.

This third edition contains new recipes and up-to-date code samples, including new chapters on creating custom blocks for the block editor and integrating data from external sources. From one chapter to the next, you'll learn how to create plugins of varying complexity, ranging from a few lines of code to complex extensions that provide intricate new capabilities. You'll start by using the basic mechanisms provided in WordPress to create plugins, followed by recipes covering how to design administration panels, enhance the post editor with custom fields, store custom data, and even create custom blocks. You'll safely incorporate dynamic elements into web pages using scripting languages, learn how to integrate data from external sources, and build new widgets that users will be able to add to WordPress sidebars and widget areas.

By the end of this book, you will be able to create WordPress plugins to perform any task you can imagine.

What you will learn

  • Discover action and filter hooks, which form the basis of plugin creation
  • Explore the creation of administration pages and add new content management sections through custom post types and custom fields
  • Add new components to the block editor library
  • Fetch, cache, and regularly update data from external sources
  • Bring in external data sources to enhance your content
  • Make your pages dynamic by using JavaScript, jQuery, and AJAX and adding new widgets to the platform
  • Add support for plugin translation and distributing your work to the WordPress community

Who this book is for

This book is for WordPress users, developers, and site integrators interested in creating new plugins to address their personal needs, fulfill client requirements, and bring new capabilities to the WordPress community. Basic knowledge of PHP and WordPress is expected.

Table of contents

  1. WordPress Plugin Development Cookbook
  2. Third Edition
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    8. Get in touch
    9. Share Your Thoughts
  7. Chapter 1: Preparing a Local Development Environment
    1. Technical requirements
    2. Installing a local web server on your computer
      1. How to do it…
      2. How it works…
      3. There's more…
    3. Creating a local version control repository
      1. How to do it…
      2. How it works…
      3. There's more…
    4. Installing a dedicated code editor/text editor
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
  8. Chapter 2: Plugin Framework Basics
    1. Technical requirements  
    2. Creating a plugin file and header
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Adding output content to page headers using plugin actions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Using WordPress path utility functions to load external files and images
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Modifying the site generator meta tag using plugin filters
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Adding text after each item's content using plugin filters
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Inserting link tracking code in the page body using plugin filters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Troubleshooting coding errors and printing variable content
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Creating a new simple shortcode
      1. How to do it...
      2. How it works...
      3. See also
    10. Creating a new shortcode with parameters
      1. How to do it...
      2. How it works...
      3. See also
    11. Creating a new enclosing shortcode
      1. How to do it...
      2. How it works...
      3. See also
    12. Loading a style sheet to format plugin output
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Writing plugins using object-oriented PHP
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
  9. Chapter 3: User Settings and Administration Pages
    1. Technical requirements
    2. Creating default user settings on plugin initialization
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Storing user settings using arrays
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Removing plugin data on deletion
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Creating an administration page menu item in the settings menu
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Creating a multi-level administration menu
      1. How to do it...
      2. How it works...
      3. There's more…
      4. See also
    7. Rendering the admin page contents using HTML
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Processing and storing plugin configuration data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Displaying a confirmation message when options are saved
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Adding custom help pages
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Rendering the admin page contents using the Settings API
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Accessing user settings from action and filter hooks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Formatting admin pages using meta boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    14. Splitting admin code from the main plugin file to optimize site performance
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    15. Storing style sheet data in user settings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    16. Managing multiple sets of user settings from a single admin page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    17. Creating a network-level plugin with admin pages
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  10. Chapter 4: The Power of Custom Post Types
    1. Technical requirements
    2. Creating a custom post type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Adding a new section to the custom post type editor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Displaying single custom post type items using a custom layout
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Tailoring search output for custom post type items
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Displaying custom post type data in shortcodes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Adding custom categories for custom post types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Adding custom fields to categories
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Hiding the category editor from the custom post type editor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Displaying additional columns in the custom post list page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Adding filters for custom categories to the custom post list page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    12. Adding Quick Edit fields for custom categories
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Updating the page title to include custom post data using plugin filters
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Chapter 5: Customizing Post and Page Editors
    1. Technical requirements
    2. Capturing and displaying information using custom meta boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Displaying custom post data using filter functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Hiding the Custom Fields section in the post editor
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Extending the post editor to attach custom files with the media uploader
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  12. Chapter 6: Extending the Block Editor
    1. Technical requirements
    2. Setting up a block development environment and creating a simple block
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating an editable blockquote block
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Creating a new WordPress REST endpoint
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Creating a server-side rendering block that leverages an existing shortcode
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  13. Chapter 7: Accepting User Content Submissions
    1. Technical requirements
    2. Creating a client-side content submission form
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Saving user-submitted content in custom post types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Sending email notifications upon new submissions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Implementing a CAPTCHA on user forms using an online service
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Using a local library to implement a CAPTCHA on user forms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  14. Chapter 8: Customizing User Data
    1. Technical requirements
    2. Adding custom fields to the user editor
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Processing and storing custom user data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Displaying new user data on the user list page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Using custom user data in an enclosing shortcode
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  15. Chapter 9: Leveraging JavaScript, jQuery, and AJAX Scripts
    1. Technical requirements
    2. Safely loading jQuery onto WordPress web pages
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Displaying a pop-up dialog using the built-in ThickBox plugin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Controlling pop-up dialog display using shortcodes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Displaying a calendar day selector using the Datepicker plugin
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Adding tooltips to admin page form fields using the TipTip plugin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using AJAX to dynamically update partial page contents
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  16. Chapter 10: Adding New Widgets to the WordPress Library
    1. Technical requirements
    2. Creating a new widget in WordPress
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Displaying widget configuration options
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Validating widget configuration options
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Adding a custom dashboard widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Adding a custom widget to the network dashboard
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  17. Chapter 11: Fetching, Caching, and Regularly Updating External Site Data
    1. Technical requirements
    2. Displaying RSS items from an external feed
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more…
      5. See also
    3. Optimizing plugin performance by storing external data using transients
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Scheduling plugin data updates using WP-Cron
      1. Getting ready
      2. How to do it...
      3. There's more…
      4. See also
  18. Chapter 12: Enabling Plugin Internationalization
    1. Technical requirements
    2. Changing the WordPress site language configuration
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Adapting default user settings for translation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Making admin page code ready for translation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Modifying shortcode output for translation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Translating text strings using Poedit
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Loading a language file in the plugin initialization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  19. Chapter 13: Distributing Your Plugin on WordPress.org
    1. Technical requirements
    2. Creating a README file for your plugin
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Applying for your plugin to be hosted on WordPress.org
      1. How to do it...
      2. How it works...
      3. See also
    4. Uploading your plugin using Subversion
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Providing plugin banner and thumbnail images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you

Product information

  • Title: WordPress Plugin Development Cookbook - Third Edition
  • Author(s): Yannick Lefebvre
  • Release date: March 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781801810777