franmastromarino/wp-options-orm
Composer 安装命令:
composer require franmastromarino/wp-options-orm
包简介
A package to help developers create custom WordPress entities in their own plugins.
关键字:
README 文档
README
Description
WP ORM is a specialized Object Relational Mapper designed for WordPress, simplifying the management of entities using the wp_options table. It provides an efficient way to handle single and collection entities, ideal for plugin settings and simple plugin entities, without the need for custom databases.
The primary goal of WP ORM is to obviate the need for creating custom database or multiple wp_options entries reducing the complexity associated with managing such data in WordPress.
This makes it an ideal solution for WordPress developers looking for a simplified and efficient way to handle data within plugins.
WP ORM excels in scenarios that require simple data management. It is particularly adept at managing settings and other basic entities within WordPress plugins.
For applications that require more complex data structures or advanced features, we recommend using Symlink ORM, which is better suited for handling intricate data requirements.
In summary, WP ORM offers a developer-friendly, efficient, and streamlined approach to managing WordPress data, making it an excellent choice for developers looking to enhance their plugin development process without the added complexity of custom database management.
Key Features
- Simple Entity Management: Easily create and manage single entities.
- Collection Entity Handling: Handle collection instances with ease.
Installation
composer require franmastromarino/wp-options-orm
Usage
WP ORM can be utilized to create and manage entities within WordPress. Below are examples showing its practical implementation:
Single Entity
In this example we will share a plugin settings implementation.
// Define the PluginSettings entity namespace YourNamespace\Entities; use QuadLayers\WP_Orm\Entity\SingleEntity; class PluginSettings extends SingleEntity { public $feature_enabled = 1; public $layout_type = 'grid'; public $max_items = 10; public $post_type = array( 'post', 'page' ); public $more = array( 'test1' => true, 'test2' => true, 'test3' => false, ); // Additional settings properties... }
// Model for PluginSettings namespace YourNamespace\Models; use YourNamespace\Entities\PluginSettings; use QuadLayers\WP_Orm\Builder\SingleRepositoryBuilder; class PluginSettingsModel { protected $repository; public function __construct() { $builder = new SingleRepositoryBuilder(); $builder->setTable('your_plugin_settings') ->setEntity(PluginSettings::class); $this->repository = $builder->getRepository(); } public function getSettingsTable() { return $this->repository->getTable(); } public function getSettings() { $entity = $this->repository->find(); if ($entity) { return $entity->getProperties(); } else { $admin = new PluginSettings(); return $admin->getProperties(); } } public function deleteSettings() { return $this->repository->delete(); } public function saveSettings($data) { $entity = $this->repository->create($data); if ($entity) { return true; } } // Additional model methods... }
Collection Entity
In this example we will share a plugin items collection implementation.
namespace YourNamespace\Entities; use QuadLayers\WP_Orm\Entity\CollectionEntity; class PluginItems extends CollectionEntity { public static $primaryKey = 'item_id'; public $item_id = 0; public $feature_enabled = 1; public $layout_type = 'grid'; public $max_items = 10; public $post_type = array( 'post', 'page' ); public $more = array( 'test1' => true, 'test2' => true, 'test3' => false, ); // Additional settings properties... }
namespace YourNamespace\Models; use YourNamespace\Entities\PluginItems; use QuadLayers\WP_Orm\Builder\CollectionRepositoryBuilder; class PluginItemsModel { protected static $instance; protected $repository; private function __construct() { $builder = ( new CollectionRepositoryBuilder() ) ->setTable('your_plugin_items') ->setEntity(PluginItems::class) ->setAutoIncrement(true); $this->repository = $builder->getRepository(); } public function getItemsTable() { return $this->repository->getTable(); } public function getItemDefaults() { $entity = new PluginItems(); $defaults = $entity->getDefaults(); return $defaults; } public function getItem(int $item_id) { $entity = $this->repository->find($item_id); if ($entity) { return $entity->getProperties(); } } public function deleteItem(int $item_id) { return $this->repository->delete($item_id); } public function updateItem(int $item_id, array $item) { $entity = $this->repository->update($item_id, $item); if ($entity) { return $entity->getProperties(); } } public function createItem(array $item) { if (isset($item['item_id'])) { unset($item['item_id']); } $entity = $this->repository->create($item); if ($entity) { return $entity->getProperties(); } } public function getAllItems() { $entities = $this->repository->findAll(); if (! $entities) { return; } $actions = array(); foreach ($entities as $entity) { $actions[] = $entity->getProperties(); } return $actions; } public function deleteAllItems() { return $this->repository->deleteAll(); } public static function instance() { if (! isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } }
franmastromarino/wp-options-orm 适用场景与选型建议
franmastromarino/wp-options-orm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autoload」 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 franmastromarino/wp-options-orm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 franmastromarino/wp-options-orm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 franmastromarino/wp-options-orm 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Environment processor and contexts autoloader
Extension to autoload modules dynamically
Class loader implementation (PSR-0, PSR-4)
A small autoloading library, compatible with Composer, that allows you to customise your autoloading functionality.
Gii Template Collection, Model and CRUD templates with Boostrap UI
PHP Wechaty is a Conversational AI RPA SDK for Chatbot written in PHP.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2023-12-12