https://github.com/szepeviktor/starter-plugin
Template for WordPress plugins, it took 7️⃣ years to write
https://github.com/szepeviktor/starter-plugin
composer editorconfig php phpcs phpstan wordpress wordpress-plugin
Last synced: about 1 month ago
JSON representation
Template for WordPress plugins, it took 7️⃣ years to write
- Host: GitHub
- URL: https://github.com/szepeviktor/starter-plugin
- Owner: szepeviktor
- License: mit
- Created: 2020-06-14T12:38:45.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-14T10:22:29.000Z (5 months ago)
- Last Synced: 2025-04-24T03:45:20.158Z (3 months ago)
- Topics: composer, editorconfig, php, phpcs, phpstan, wordpress, wordpress-plugin
- Language: PHP
- Homepage: https://github.com/szepeviktor/wordpress-website-lifecycle
- Size: 84 KB
- Stars: 67
- Watchers: 9
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ultimate WordPress Plugin Main File
_How to leave legacy technologies behind_
Source code in [`plugin-name.php`](/plugin-name.php) needs PHP 8 which is present on more than
[50% of WordPress installations](https://wordpress.org/about/stats/#php_versions).## Support my work
Please consider sponsoring me monthly if you use my packages in an agency.
[](https://github.com/sponsors/szepeviktor)
## Parts of plugin main file
- [Header comment](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields)
- [PHP strict types](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict)
- [PHP namespaces](https://www.php-fig.org/psr/psr-4/#2-specification)
- Prevent direct execution
- Load autoloader
- Prevent double activation
- Define constant values in an immutable container
- Load translations
- Check requirements
- PHP and WordPress minimum version
- Multisite installation
- Other plugins
- Current theme
- Composer packages
- Hook plugin activation functions
- Support [WP-CLI](https://wp-cli.org/)
- Display admin notice and deactivate plugin on error:bulb: Anything else goes into a separate file.
## What to avoid
- :x: Global constants
- :x: Global functions
- :x: Classes without namespace
- :x: Loading PHP files with `require`
- :x: Code with [side-effects](https://www.php-fig.org/psr/psr-1/#23-side-effects) outside the main file
- :x: Immediate execution without `add_action` in the main file
- :x: Conditional function or class definitions---

## Installation
1. Get the plugin ZIP from ...
1. Upload to Plugins / Add new / Upload `/wp-admin/plugin-install.php?tab=upload`## Usage
1. Adjust settings ...
1. Or add a hook `add_filter('project/enable', '__return_true');` to `functions.php`