承接 lambry/batchpress 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lambry/batchpress

Composer 安装命令:

composer require lambry/batchpress

包简介

WordPress plugin to help process data in batches.

README 文档

README

BatchPress is a little plugin to help process data in batches, with BatchPress you can run, monitor and cancel batched jobs.

Install: composer require lambry/batchpress

screenshot

Usage

To use BatchPress create a new class per job and register those classes using the batchpress/jobs filter.

Job class outline:

  • Required: label property to describe the job.
  • Required: process method which is passed a single item for processing; any info/errors can be returned and will be displayed in the log.
  • Optional|Required: items method is optional if the upload property is set to true, in this case it can be used to filter the uploaded content before staring the job. If upload if false or not defined the method is then required to return an array of items for processing.
  • Optional: upload property to tell BatchPress if a CSV upload is required.
  • Optional: batch property to set the number of items to process per batch.
  • Optional: description property to provide extra details about the job.

Basic Example

class Update {
  public $batch = 10;
  public $label = 'Update data';

  // Prepare an array of items for processing
  public function items() : array { }

  // Process each item and optionally return log info
  public function process($item) : mixed { }
}

Example with CSV upload

class Import {
  public $batch = 10;
  public $upload = true;
  public $label = 'Import data';

  // Optionally filter and format the uploaded content before processing
  public function items(array $data) : array { }

  // Process each item and optionally return log info
  public function process($item) : mixed { }
}

Registering jobs

add_filter('batchpress/jobs', fn() => [Update::class, Import::class]);

Helpers

BatchPress provides some helper methods as well, to use them just include the Helpers trait in your job class.

use Lambry\BatchPress\Helpers;

class Update {
  use Helpers;

  public function process($item) : mixed {
    // Adding an image to a post
    $id = this->uploadImage($item['url'], $item['id'], $item['title']);
    // Adding a file to a post
    $id = this->uploadFile($item['url'], $item['id'], $item['title']);
  }
}

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固