lidmo / wp-plugin-start
WP plugin start based on laravel features
Fund package maintenance!
wesleydeveloper
Installs: 35
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.4|^8.0
- lidmo/wp-foundation: ^1.0
Requires (Dev)
- roots/wordpress: ^6.1
- symfony/var-dumper: ^5.4
- wp-phpunit/wp-phpunit: ^6.1
- yoast/phpunit-polyfills: ^1.0
README
WP plugin start based on laravel features
Instalation
composer create-project lidmo/wp-plugin-start plugin-name
Hooks
To understand how the plugin is structured, I suggest you check the default hooks in the src/Hooks directory and the registration of these hooks in the src/Hooks/Kernel.php class
Hooks extend the \Lidmo\WP\Foundation\Hooks\Hook class, where name, type, arguments and priority are handled. The hook suffix determines its type automatically, while the namespace determines its name.
Create hook
To add an action to wp_enqueue_scripts we can create an EnqueueScriptsAction class in the src/Hooks/Wp directory
namespace PluginName\Hooks\Wp; use Lidmo\WP\Foundation\Hooks\Hook; class EnqueueScriptsAction extends Hook { public function handle() { // your code here } }
To add a filter to wp_insert_post_data, we can create an InsertPostDataFilter class in the src/Hooks/Wp directory
namespace PluginName\Hooks\Wp; use Lidmo\WP\Foundation\Hooks\Hook; class InsertPostDataFilter extends Hook { public function handle($attributes) { // your code here } }
Register hook
namespace PluginName\Hooks; use Lidmo\WP\Foundation\Hooks\Kernel as HooksKernel; class Kernel extends HooksKernel { protected $hooks = [ // Actions \PluginName\Hooks\Wp\EnqueueScriptsAction::class, // Filters \PluginName\Hooks\Wp\InsertPostDataFilter::class, ]; }
Set hook properties
protected $name = 'hook_name'; // set hook name protected $type = 'filter'; // set hook filter protected $priority = 100; // set hook priority protected $acceptedArgs = 1; // set hook args