rockschtar/wordpress-role

WordPress Role Abstraction

1.0.3 2021-04-12 18:00 UTC

This package is auto-updated.

Last update: 2022-06-29 01:50:57 UTC


README

Description

WordPress Role abstraction. Developed for usage with composer based WordPress projects (roots/bedrock orjohnpbloch/wordpress).

Requirements

Install

composer require rockschtar/wordpress-role

Usage

Basic Example

// describe role
use Rockschtar\WordPress\Role\Role;

class FAQManagerRole extends Role
{
    public function roleName(): string
    {
        return 'faq-manager';
    }

    public function capabilities(): array
    {
        return [
          'edit_faq',
          'read_faq',
          'delelte_faq'
        ];
    }

    public function displayName(): string
    {
        return __('FAQ Manager', 'my-textdomain');
    }
}

//register role hook
register_activation_hook(MY_PLUGIN_FILE, 'myprefix_register_faq_role');

function myprefix_register_faq_role() {
    FAQManagerRole::register();
}

//unregister role hook
register_deactivation_hook(MY_PLUGIN_FILE, 'myprefix_unregister_faq_role');

function myprefix_unregister_faq_role() {
    FAQManagerRole::unregister();
}

License

rockschtar/wordpress-role is open source and released under MIT license. See LICENSE.md file for more info.