codelight / wp-decorator
dev-main
2021-03-06 20:07 UTC
This package is auto-updated.
Last update: 2024-11-07 04:00:22 UTC
README
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.