Skip to content

A useful library for accessing WordPress's class methods

License

Notifications You must be signed in to change notification settings

codelight-eu/wp-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WordPress Decorator

A useful library for accessing WordPress's class methods

Installation

$ composer require codelight/wp-decorator dev-main

Quick Start

use Codelight\WordPressDecorator\WooCommerce\CustomerDecorator;

try {

    $customer          = new WC_Customer(1);
    $customerDecorator = new CustomerDecorator($customer);

    print sprintf('ID: %s', $customerDecorator->getId());
    print sprintf('Email: %s', $customerDecorator->getEmail());

} catch (Exception $e) {
    print $e->getMessage();
}

You may interested to extend the class and putting your methods as well.

use Codelight\WordPressDecorator\WooCommerce\CustomerDecorator;

class MyCustomerDecoratorClass extends CustomerDecorator
{
    public function __construct(WC_Customer $customer)
    {
        parent::__construct($customer);
    }

    public function getAdminColor()
    {
        return $this->getMeta('admin_color');
    }
}

try {

    $customer          = new WC_Customer(1);
    $customerDecorator = new MyCustomerDecoratorClass($customer);

    print sprintf('Admin color: %s', $customerDecorator->getAdminColor());

} catch (Exception $e) {
    print $e->getMessage();
}

Decorators

Here are the list of supported classes.

WordPress

Post

use Codelight\WordPressDecorator\WordPress\PostDecorator;
$postDecorator = new postDecorator(get_post(1));

User

use Codelight\WordPressDecorator\WordPress\UserDecorator;
$userDecorator = new UserDecorator(get_user_by('id', 1));

Comment

soon...

WooCommerce

Customer

use Codelight\WordPressDecorator\WooCommerce\CustomerDecorator;
$customerDecorator = new CustomerDecorator(new \WC_Customer(1));

Order

use Codelight\WordPressDecorator\WooCommerce\OrderDecorator;
$orderDecorator = new OrderDecorator(wc_get_order(1));

Product

use Codelight\WordPressDecorator\WooCommerce\ProductDecorator;
$productDecorator = new ProductDecorator(wc_get_product(1));

License

The MIT License (MIT). Please see License File for more information.

About

A useful library for accessing WordPress's class methods

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages