PHP code example of lambry / batchpress

1. Go to this page and download the library: Download lambry/batchpress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lambry / batchpress example snippets


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 { }
}

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 { }
}

add_filter('batchpress/jobs', fn() => [Update::class, Import::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']);
  }
}