How to leave legacy technologies behind
Source code in plugin-name.php
needs PHP 7 which is present on more than
90% of WordPress installations.
Please consider sponsoring me monthly if you use my packages in an agency.
- Header comment
- PHP strict types
- PHP namespaces
- 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
- Display admin notice and deactivate plugin on error
💡 Anything else goes into a separate file.
- ❌ Global constants
- ❌ Global functions
- ❌ Classes without namespace
- ❌ Loading PHP files with
require
- ❌ Code with side-effects outside the main file
- ❌ Immediate execution without
add_action
in the main file - ❌ Conditional function or class definitions
- Get the plugin ZIP from ...
- Upload to Plugins / Add new / Upload
/wp-admin/plugin-install.php?tab=upload
- Adjust settings ...
- Or add a hook
add_filter('project/enable', '__return_true');
tofunctions.php