codelight / wp-decorator
dev-main
2021-03-06 20:07 UTC
This package is auto-updated.
Last update: 2024-09-07 03:39:38 UTC
README
一个用于访问WordPress类方法的实用库
安装
$ composer require codelight/wp-decorator dev-main
快速开始
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(); }
您可能希望扩展类并添加自己的方法。
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(); }
装饰器
以下是支持的类列表。
WordPress
帖子
use Codelight\WordPressDecorator\WordPress\PostDecorator; $postDecorator = new postDecorator(get_post(1));
用户
use Codelight\WordPressDecorator\WordPress\UserDecorator; $userDecorator = new UserDecorator(get_user_by('id', 1));
评论
即将...
WooCommerce
客户
use Codelight\WordPressDecorator\WooCommerce\CustomerDecorator; $customerDecorator = new CustomerDecorator(new \WC_Customer(1));
订单
use Codelight\WordPressDecorator\WooCommerce\OrderDecorator; $orderDecorator = new OrderDecorator(wc_get_order(1));
产品
use Codelight\WordPressDecorator\WooCommerce\ProductDecorator; $productDecorator = new ProductDecorator(wc_get_product(1));
许可
MIT许可(MIT)。请参阅许可文件获取更多信息。