Plugin Machine | Make Better WordPress Plugins

## Metadata
- Author: [[readwise.io]]
- Full Title: Plugin Machine | Make Better WordPress Plugins
- Category: #articles
- Document Note: This article outlines how to make better WordPress plugins using Plugin Machine. It provides guidance on making well-defined public APIs, using scalar types, callable, and array types, as well as avoiding potential problems with plugin dependencies by using dependency injection instead of relying on singletons. Plugin Machine can help developers create plugins that are more efficient and easier to deploy, manage, and upgrade. It is important to understand the concepts of public APIs, scalar types, and dependency injection in order to make the most of Plugin Machine and produce higher-quality plugins.
- Public APIs:
- Replace inner workings of a class without changing classes that use it
- PHP7 can return scalar types, callable, or array types
- Avoiding Problems:
- Instances of plugins must be installed before anything happens
- Use dependency injection instead of relying on singletons
- Dependency injection allows updating or upgrading plugins without affecting any dependent objects
Today, WordPress developers have a powerful new tool at their fingertips: Plugin Machine. This innovative platform allows developers to create better WordPress plugins, taking advantage of the latest advancements in PHP7. With the ability to return scalar types, callables, and array types, developers can create feature-rich plugins that are more reliable and easier to maintain.
But Plugin Machine offers more than just improved code. It also enables developers to overcome the challenge of plugin interdependencies. Instead of relying on singletons, Plugin Machine allows developers to use dependency injection, providing objects with their dependencies through another object. This makes it possible to update and upgrade plugins without affecting any dependent objects.
Plugin Machine is a revolutionary new way to create better WordPress plugins, giving developers the freedom to create powerful, feature-rich plugins without the worry of dependencies or scalability issues.
1. What are the advantages of using dependency injection?
2. How does dependency injection help with testing hooks?
3. What is the purpose of the base class for REST API endpoints?
This document outlines techniques for making better WordPress plugins using object-oriented PHP, dependency injection, and testing. Dependency injection separates common code from the class and allows for outside objects to be passed in. This makes it possible to update or upgrade plugins without affecting any dependent objects. A "Hooks" class is also discussed which does not contain any callbacks, but adds and removes hooks. Dependency injection is also used for REST API controllers and a base class is provided. In addition, tests are recommended in order to ensure that hooks are properly added and removed.
- URL: https://readwise.io/reader/document_raw_content/52667840
Full text of this document omitted because this document is a PDF
[Download original file →](https://readwise.io/reader/document_raw_content/52667840), Plugin Machine | Make Better WordPress Plugins, readwise.io, 01h03q0zrxmw074ada0w94de2v.