gdarko / wp-batch-processing Goto Github PK
View Code? Open in Web Editor NEW๐ Easily process large batches of data in WordPress. Provide the data, setup the processing procedure, run the batch processor from the admin dashboard. Profit.
๐ Easily process large batches of data in WordPress. Provide the data, setup the processing procedure, run the batch processor from the admin dashboard. Profit.
Hey, I'm greatly interested in your project, since I have orders from a WooCommerce shop to batch process, but I can't make it work...
When defining the setup()
method, neither $orders = get_posts([ "post_type" => "shop_order" ]);
nor $orders = get_orders();
seem to retrieve anything.
error_log( print_r( $orders ) );
always prints an empty array...
I'm probably doing something wrong, but what? Is there any other info I can give you to help me debug that, if the problem comes from me?
Thanks by advance!
Hi, I am sorry if you think you've given all the instructions in the plugin README.md or in this article; https://medium.com/@gdarko/processing-batch-data-in-wordpress-7cc5ae5720f0
But I am not able to figure out where exactly to place my own Batch class definition? I am placing it in my own custom plugin and it doesn't get recognized when I go under "Wordpress" > "Batches".
I am new to Wordpress let alone this plugin. Please help me understand how to implement this where exactly do I need to put my batch definition and will your plugin recognize my Batch?
My Plugins structure:
myplugin/myplugin.php
myplugin.php code:
if (class_exists('WP_Batch')) {
class Update_Posts_Status extends WP_Batch {
public $id = 'update_files_path';
public $title = 'Updates files path';
public function setup() {
$posts = get_posts();
foreach ($posts as $post) {
$this->push(new WP_Batch_Item($post->ID, ['post_id' => $post->ID]));
}
}
public function process($item) {
$post_id = $item->get_value('post_id');
$post = get_post($post_id);
$post_update = [
'post_id' => $post_id,
'post_status' => 'publish'
];
wp_update_post( $post_update );
return true;
}
public function finish() {
//
}
}
function wp_batch_processing_init() {
$batch = new Update_Posts_Status();
WP_Batch_Processor::get_instance()->register($batch);
}
add_action('wp_batch_processing_init', 'wp_batch_processing_init', 15, 1);
}
Thanks
In WP_Batch_Processing_Ajax_Handler
change dg_batch_item_error_message
filter for batch processing finished to this dg_batch_item_finished_message
.
Please add get_data like you did get_value to fetch all data at once:
/**
* Return data
*
* @param $key
* @param null $default
*
* @return mixed|null
*/
public function get_data($default = null) {
return isset($this->data) ? $this->data : $default;
}
Your script is working great, thanks for awesome work :)
Just a little suggestion, make your script standalone so it can be used with other plugins. Developer should have option to remove this check is_batch_runner_screen( $action = null )
or can override it completely.
Hi,
I need to run the batch process once daily. How can I add it with a cron job? Is there a hook that trigger running the batch process? If yes, can I trigger that with a cron job?
Thank you very much for the great plugin - it helps a lot in many cases.
Cann't figure out if there is a way to hook into the end of a particular process - for example to update some options in DB. Could it be done?
If there is no one it would be great to have the ability to do that.
It would be nice to be able to cancel an import and restart even if the current batch is not complete.
Hi There
This is a very great work and thanks for sharing with us.
I would like to know if this can be used as a library instead of using as a plugin
First of all, love your work on this plugin, its been very helpful...
But I was wondering, is there a hook or something that I can use, to start an batch programmatically ?
I want to make an cron job, that runs a batch every night.
Hi,
I am trying with simple delete post like this, but the batch keep running even reach 100%...
Please check that...!
public function setup() {
$posts = get_posts( array(
'numberposts' => 10,
'post_type' => 'it24-serial-number'
) );
foreach ( $posts as $post ) {
$this->push( new WP_Batch_Item( $post->ID, array( 'post_id' => $post->ID ) ) );
}
}
public function process( $item ) {
// Retrieve the custom data
$post_id = $item->get_value( 'post_id' );
// Return WP_Error if the item processing failed (In our case we simply skip author with user id 5)
// if ( $post_id != 5 ) {
// return new WP_Error( 302, "ID".$post_id );
// }
// Do the expensive processing here. eg. Sending email.
// ...
**wp_trash_post($post_id);**
// Return true if the item processing is successful.
return true;
}
/**
* Called when specific process is finished (all items were processed).
* This method can be overriden in the process class.
* @return void
*/
public function finish() {
// Do something after process is finished.
// You have $this->items, or other data you can set.
}
}
Hi,
Really love this plugin, the only thing that stood out to me about the admin interface was it didn't have any time estimate for how long the process may take (it's a feature I guess I'm used to from other large batch tasks like Relevanssi's indexer). How else do I know how many cups of coffee I have time to go and make? :D
e.g.
Thanks!
Hello, I am using this plugin and it is really awesome. Congratulations!
I just wonder if it is possible to rerun a batch process after it has finished? For example, I need to calculate some stats from time to time - I did it once using this but I dont know how to rerun them again. I guess I could add something in the finish
method to clean the run but not sure how to do it. It'd be nice if that can be done automatically or something like that.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.