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

v2.2.0 2023-12-27 13:30 UTC

This package is auto-updated.

Last update: 2024-04-27 14:12:21 UTC


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