WordPress Plugin Development Cookbook
eBook - ePub

WordPress Plugin Development Cookbook

Yannick Lefebvre

  1. 420 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

WordPress Plugin Development Cookbook

Yannick Lefebvre

Book details
Book preview
Table of contents
Citations

About This Book

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 guideKey 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 communityBook DescriptionWordPress 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 communityWho this book is forThis 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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is WordPress Plugin Development Cookbook an online PDF/ePUB?
Yes, you can access WordPress Plugin Development Cookbook by Yannick Lefebvre in PDF and/or ePUB format, as well as other popular books in Informatik & Programmierung in PHP. We have over one million books available in our catalogue for you to explore.

Information

Year
2022
ISBN
9781801816939

Chapter 1: Preparing a Local Development Environment

Before you start writing your first WordPress plugin, it is important to have a good set of tools in place that will allow you to work locally on your computer and be more efficient in your work. While it is possible to perform some development tasks with the built-in tools that are provided with the operating system, creating a solid local development environment will help you develop plugins quickly and have full control over your server settings to be able to test different configurations.
This chapter proposes a set of free tools that can easily be installed on your computer, regardless of your preferred operating system, to facilitate the development of your future WordPress plugins. These tools include a local web server to speed up page access and avoid sending files constantly to a remote server, a version control system to keep incremental backups of your work, and a code editor to enhance your editing capabilities.
We will cover the following recipes in this chapter:
  • Installing a local web server on your computer
  • Creating a local version control repository
  • Installing a dedicated code editor/text editor

Technical requirements

You can find complete code examples on GitHub under the following repository: https://github.com/PacktPublishing/WordPress-Plugin-Development-Cookbook-Third-Edition.

Installing a local web server on your computer

The first step to preparing a local development environment is to install a local web server on your computer. This will transform your computer into a system capable of running the core WordPress code and performing all tasks related to rendering a WordPress website locally.
Having a local web server has many benefits:
  • It provides a quick response to the frequent page refreshes that are made as plugin code is written, tested, and refined, since all information is processed locally.
  • It removes the need to constantly upload new plugin file versions to a remote web server to validate code changes.
  • It allows development to take place when no internet connection is available (for example, when traveling on an airplane). This is only possible if your plugin code does not interact with external servers.
  • It offers a worry-free programming environment where you cannot bring down a live website with a programming error or an infinite loop.
There are many free packages available online that contain all of the web server components necessary to run a WordPress installation.

How to do it…

Follow these steps to easily install the aptly named Local application from Flywheel:
  1. Visit the Local website (https://www.localwp.com/) and download the appropriate package for your computer.
    Note
    Local is free and available for Windows, macOS, and Linux platforms. The screenshots and instructions in this recipe are based on Local version 6.1.5 running on Windows 11. The installation steps and exact dialog content may vary based on your choice of platform.
  2. Launch the Local installer.
  3. On Windows, select whether the application should be available only to the user performing the application or to all users (requires administrator privileges), and then leave all the other options at their default values.
  4. Also on Windows, make sure that the Run Local checkbox is checked at the end of the installation process and click on Finish to exit the installer and start Local.
Figure 1.1 – Last page of the Local installation program on Windows
Figure 1.1 – Last page of the Local installation program on Windows
  1. On macOS, open the installation package and drag the Local program to the Applications folder. Once this is done, search for Local and run it.
  2. When Local first starts, you will need to accept the application's Terms of Service and will also be given the option to activate Error Reporting to automatically report problems back to the Local team. You can activate the error reporting feature at your discretion.
  3. On the next screen, you will be prompted to create a free Local account. This is optional and can be bypassed by closing the account creation screen, bringing you to the main Local interface.
Figure 1.2 – Main Local interface
Figure 1.2 – Main Local interface
  1. Click on + CREATE A NEW SITE to start the site creation process.
  2. Name your new site Plugin Development Site and click on CONTINUE.
  3. Select the Preferred option to create a site running the latest versions of PHP and MySQL, along with the nginx web server, and then click on CONTINUE.
  4. Specify a username, password, and email to create an account on your development WordPress site and then click on ADD SITE. The Local application will download and install the required components and start all of the required applications to have a working local WordPress installation. On Windows, you may need to allow multiple applications through the computer's firewall.
Figure 1.3 – Newly created local development site
Figure 1.3 – Newly created local development site
  1. Visit your local development site by clicking on the OPEN SITE button in the top-right corner of the Local interface. The default address of your site is http://plugin-development-site.local/.
  2. Back in the Local interface, click on the ADMIN button to visit your site's login page and connect using the credentials you provided during the site creation process.
  3. Make sure that the active theme is Twenty Twenty-Two. If not, install it and activate it.
  4. Still in the Local interface, click on the arrow next to the site path under the site name to access the site's local files on your computer. The WordPress software files will be found under the app\public directory within the site directory.

How i...

Table of contents

  1. WordPress Plugin Development Cookbook
  2. Third Edition
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
  7. Chapter 1: Preparing a Local Development Environment
  8. Chapter 2: Plugin Framework Basics
  9. Chapter 3: User Settings and Administration Pages
  10. Chapter 4: The Power of Custom Post Types
  11. Chapter 5: Customizing Post and Page Editors
  12. Chapter 6: Extending the Block Editor
  13. Chapter 7: Accepting User Content Submissions
  14. Chapter 8: Customizing User Data
  15. Chapter 9: Leveraging JavaScript, jQuery, and AJAX Scripts
  16. Chapter 10: Adding New Widgets to the WordPress Library
  17. Chapter 11: Fetching, Caching, and Regularly Updating External Site Data
  18. Chapter 12: Enabling Plugin Internationalization
  19. Chapter 13: Distributing Your Plugin on WordPress.org
  20. Other Books You May Enjoy
Citation styles for WordPress Plugin Development Cookbook

APA 6 Citation

Lefebvre, Y. (2022). WordPress Plugin Development Cookbook (3rd ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/3448792 (Original work published 2022)

Chicago Citation

Lefebvre, Yannick. (2022) 2022. WordPress Plugin Development Cookbook. 3rd ed. Packt Publishing. https://www.perlego.com/book/3448792.

Harvard Citation

Lefebvre, Y. (2022) WordPress Plugin Development Cookbook. 3rd edn. Packt Publishing. Available at: https://www.perlego.com/book/3448792 (Accessed: 24 June 2024).

MLA 7 Citation

Lefebvre, Yannick. WordPress Plugin Development Cookbook. 3rd ed. Packt Publishing, 2022. Web. 24 June 2024.