arraypress/edd-register-log-views
Composer 安装命令:
composer require arraypress/edd-register-log-views
包简介
A library for easily registering custom log views in Easy Digital Downloads
关键字:
README 文档
README
A comprehensive PHP library for registering custom log views and order log links in Easy Digital Downloads. This library provides a robust solution for programmatically creating and managing log views with custom capabilities and flexible organization.
Features
- 🚀 Easy registration of custom log views
- 🔗 Order detail page log link integration
- 🔒 Capability-based access control
- 📁 Automatic file path management
- 🎯 Flexible view organization
- 🛠️ Simple helper functions
- ✅ Type safety with strict typing
Requirements
- PHP 7.4 or higher
- WordPress 6.7.1 or higher
- Easy Digital Downloads 3.0 or higher
Installation
You can install the package via composer:
composer require arraypress/edd-register-log-views
Basic Usage
Registering a Custom Log View
edd_register_custom_log_view( [ 'id' => 'audio_stats', 'title' => 'Audio Stats', 'class_name' => 'Audio_Stats_Log_Table', 'file' => 'admin/logs/class-audio-stats-log-table.php', 'capability' => 'view_shop_reports' ] );
Adding an Order Log Link
edd_register_log_order_link( [ 'id' => 'audio-stats', 'label' => __( 'View Audio Stats', 'your-plugin' ), 'view' => 'audio_stats' ] );
Configuration Options
Custom Log View Options
| Option | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | Unique identifier for the log view |
| title | string | Yes | Display text in the log views menu |
| class_name | string | Yes | Fully qualified class name for the list table |
| file | string | Yes | Path to the class file (relative to base path) |
| capability | string | No | Required capability (defaults to 'view_shop_reports') |
| base_path | string | No | Custom base path for file location |
Order Log Link Options
| Option | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | Unique identifier for the log link |
| label | string | Yes | Text to display for the link |
| view | string | Yes | The log view parameter to link to |
| url_callback | callable | No | Custom callback to generate URL |
| display_callback | callable | No | Callback to conditionally display link |
| capability | string | No | Required capability (defaults to 'view_shop_reports') |
Advanced Usage
Custom URL Callback
edd_register_log_order_link( [ 'id' => 'custom-logs', 'label' => 'Custom Logs', 'view' => 'custom_view', 'url_callback' => function( $order ) { return add_query_arg( [ 'page' => 'custom-page', 'order_id' => $order->id ], admin_url( 'admin.php' ) ); } ] );
Conditional Display
edd_register_log_order_link( [ 'id' => 'audio-stats', 'label' => 'Audio Stats', 'view' => 'audio_stats', 'display_callback' => function( $order ) { // Only show if order has audio products foreach ( $order->items as $item ) { $download = edd_get_download( $item->product_id ); if ( has_audio_files( $download ) ) { return true; } } return false; } ] );
Direct Class Usage
For more control, you can use the classes directly:
use ArrayPress\EDD\Register\LogViewsManager; use ArrayPress\EDD\Register\LogOrderLink; // Get manager instances $log_views = edd_custom_log_views(); $order_links = edd_log_order_links(); // Register views $log_views->register( [ 'id' => 'custom_logs', 'title' => 'Custom Logs', 'class_name' => 'Custom_Logs_Table', 'file' => 'class-custom-logs-table.php' ] ); // Register links $order_links->register( [ 'id' => 'custom-link', 'label' => 'Custom Link', 'view' => 'custom_logs' ] );
File Organization
By default, the library looks for log table classes relative to your plugin's root directory:
your-plugin/
├── admin/
│ └── logs/
│ └── class-audio-stats-log-table.php
├── includes/
└── your-plugin.php
You can customize this by providing a custom base_path in the view configuration.
Complete Example
<?php /** * Plugin Name: Audio Stats for EDD * Description: Track audio preview statistics */ // Register the custom log view edd_register_custom_log_view( [ 'id' => 'audio_stats', 'title' => __( 'Audio Stats', 'audio-stats' ), 'class_name' => '\\MyPlugin\\Admin\\Audio_Stats_Table', 'file' => 'admin/logs/class-audio-stats-table.php', 'base_path' => plugin_dir_path( __FILE__ ) . 'includes/', 'capability' => 'view_shop_reports' ] ); // Add link to order details page edd_register_log_order_link( [ 'id' => 'audio-stats', 'label' => __( 'View Audio Stats', 'audio-stats' ), 'view' => 'audio_stats' ] );
How It Works
The library uses WordPress hooks to integrate with EDD's log system:
- Log Views: Registers with
edd_log_viewsfilter to add custom views to the logs dropdown - View Handler: Creates
edd_logs_view_{$id}action to render your custom table - Order Links: Hooks into
edd_view_order_details_logs_afterto display links on order pages
Error Handling
The library uses type declarations and validation:
// Returns false if required fields missing $result = edd_register_custom_log_view( [ 'id' => 'example', 'title' => 'Example Logs' // Missing required fields ] ); if ( ! $result ) { error_log( 'Failed to register log view' ); }
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the GPL2+ License. See the LICENSE file for details.
Support
For support, please use the issue tracker.
arraypress/edd-register-log-views 适用场景与选型建议
arraypress/edd-register-log-views 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「wordpress」 「monitoring」 「management」 「logs」 「reports」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/edd-register-log-views 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/edd-register-log-views 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/edd-register-log-views 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
2lenet/EasyAdminPlusBundle
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Analysis module for finding problematical shop data.
Statsd (Object Oriented) client library for PHP
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-01-05