arraypress/wp-inline-sync
Composer 安装命令:
composer require arraypress/wp-inline-sync
包简介
Lightweight WordPress library for inline batch sync operations with progress UI. Register sync operations that run directly on existing admin screens.
README 文档
README
A lightweight WordPress library for inline batch sync operations with progress UI. Register sync operations that run directly on existing admin screens — no separate pages, no stats storage, no complexity.
Features
- Inline progress bar — renders above your admin table with real-time progress
- Current item display — shows the name of each item as it's processed
- Auto-binding buttons — output a trigger button, the JS handles everything
- Single REST endpoint — one endpoint serves all registered syncs
- Cursor-based pagination — works with any API that supports cursor pagination
- Cancel support — users can cancel mid-sync
- Dismissable notices — completion summary disappears on click or page refresh
- No persistence — nothing stored in the database, refresh and it's gone
Requirements
- PHP 8.1+
- WordPress 6.0+
Installation
composer require arraypress/wp-inline-sync
Quick Start
1. Register a sync
register_sync( 'stripe_prices', [ 'hook_suffix' => 'toplevel_page_sugarcart', 'title' => __( 'Sync Prices', 'my-plugin' ), 'button_label' => __( 'Sync from Stripe', 'my-plugin' ), 'container' => '.wp-list-table', 'data_callback' => 'MyPlugin\fetch_prices', 'process_callback' => 'MyPlugin\process_price', 'name_callback' => fn( $item ) => $item->product->name ?? $item->id, ] );
2. Output the trigger button
// In your admin screen render_sync_button( 'stripe_prices' );
That's it. The button renders with data attributes, the JS auto-binds on click, and the progress bar appears above your table.
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
hook_suffix |
string|array |
'' |
Admin screen hook suffix(es) where assets should load. |
capability |
string |
'manage_options' |
Required user capability. |
title |
string |
'' |
Display title shown in the progress bar header. |
button_label |
string |
'Sync' |
Text for the trigger button. |
button_class |
string |
'button' |
CSS class(es) for the trigger button. |
container |
string |
'.wp-list-table' |
CSS selector — progress bar inserts before this element. |
data_callback |
callable |
null |
Fetches items. Receives (string $cursor). |
process_callback |
callable |
null |
Processes one item. |
name_callback |
callable|null |
null |
Extracts a display name from an item. |
Callbacks
data_callback
Fetches a batch of items from your data source. Receives the cursor string (empty on first call). You control the batch size internally.
function fetch_prices( string $cursor ): array { $params = [ 'limit' => 100, 'active' => true, ]; if ( $cursor ) { $params['starting_after'] = $cursor; } $prices = $stripe->prices->all( $params ); $last = end( $prices->data ); return [ 'items' => $prices->data, 'has_more' => $prices->has_more, 'cursor' => $last ? $last->id : '', 'total' => null, // null if unknown ]; }
Return format:
| Key | Type | Description |
|---|---|---|
items |
array |
Items to process this batch. |
has_more |
bool |
Whether more batches remain. |
cursor |
string |
Cursor to pass on next call. |
total |
int|null |
Total item count if known (enables % progress). |
process_callback
Processes a single item. Called once per item in the batch.
function process_price( object $item ): string|WP_Error { $existing = get_price_by_stripe_id( $item->id ); if ( $existing ) { update_price( $existing->id, [ /* ... */ ] ); return 'updated'; } add_price( [ /* ... */ ] ); return 'created'; }
Return values:
| Value | Meaning |
|---|---|
'created' |
Item was newly created |
'updated' |
Item was updated |
'skipped' |
Item was skipped |
WP_Error |
Item failed |
name_callback
Optional. Extracts a display name from an item for the progress UI. If not provided, the library guesses by checking
common fields (name, title, label, email, id).
'name_callback' => fn( $item ) => $item->product->name ?? $item->id,
Functions
register_sync
register_sync( string $id, array $config ): Sync
Register an inline sync operation.
get_sync
get_sync( string $id ): ?Sync
Retrieve a registered sync instance.
has_sync
has_sync( string $id ): bool
Check if a sync is registered.
render_sync_button
render_sync_button( string $id, array $args = [] ): void
Output a trigger button. Accepts optional overrides for label, class, and container.
get_sync_button
get_sync_button( string $id, array $args = [] ): string
Returns the button HTML instead of echoing it.
JavaScript API
The JS auto-binds to .inline-sync-trigger buttons. For programmatic control:
// Start a sync manually InlineSync.start('stripe_prices'); // Cancel a running sync InlineSync.cancel('stripe_prices');
Events
Events are fired on $(document):
| Event | Arguments | Description |
|---|---|---|
inline-sync:complete |
syncId, totals |
Sync finished |
inline-sync:cancelled |
syncId |
User cancelled |
inline-sync:error |
syncId, message |
Sync failed |
$(document).on('inline-sync:complete', function (e, syncId, totals) { if (syncId === 'stripe_prices') { // Reload the table location.reload(); } });
Multiple Syncs
Register each sync separately. They can target the same screen:
register_sync( 'stripe_prices', [ 'hook_suffix' => 'toplevel_page_my-plugin', 'title' => 'Sync Prices', 'button_label' => 'Sync Prices', 'data_callback' => 'fetch_prices', 'process_callback' => 'process_price', ] ); register_sync( 'stripe_customers', [ 'hook_suffix' => 'my-plugin_page_customers', 'title' => 'Sync Customers', 'button_label' => 'Sync Customers', 'data_callback' => 'fetch_customers', 'process_callback' => 'process_customer', ] );
Progress Bar Behavior
During sync: Blue left border, progress track with fill, item count, current item name, cancel button.
On completion: Green left border, summary line (e.g., "120 items synced — 3 created, 115 updated, 2 skipped"), dismiss button. First 3 error messages shown inline if any items failed.
On error/cancel: Red left border, error message or "Sync cancelled", dismiss button.
On dismiss or page refresh: Gone. Nothing persisted.
License
GPL-2.0-or-later
arraypress/wp-inline-sync 适用场景与选型建议
arraypress/wp-inline-sync 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「sync」 「wordpress」 「inline」 「progress」 「batch-processing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/wp-inline-sync 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/wp-inline-sync 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/wp-inline-sync 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
Analysis module for finding problematical shop data.
Sync content to other sites on element save.
Production-ready third-party integrations for Laravel. Credential management, API request logging, rate limiting, sync scheduling, OAuth2, and health monitoring.
Synchronizing data between Laravel's framework
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-02-14