L
L
lakegull2021-11-29 14:02:28
PHP
lakegull, 2021-11-29 14:02:28

Is it possible to run a function to process records via bulk_actions-upload?

Nowhere I can find the necessary example to understand whether this is feasible and if so, how.

I created a custom action in the file library:
61a4b257deb30111916901.png
The task is to make it run a function that will process each selected image. The function is located in the theme's functions.php.
Here is the code itself:

add_filter('bulk_actions-upload', function($bulk_actions) {
  $bulk_actions['run_custom_function'] = __('Custom Function', 'txtdomain');
  return $bulk_actions;
});

add_filter('handle_bulk_actions-upload', function($redirect_url, $action, $post_ids) {
  if ($action == 'run_custom_function') {
    foreach ($post_ids as $post_id) {
                 //run the function
    }
    $redirect_url = add_query_arg('run_custom_function', count($post_ids), $redirect_url);
  }
  return $redirect_url;
}, 10, 3);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2021-11-29
@wppanda5

Why not, even a million tutorials for bulk_actions
In general, look at how Regenerate Thumbnails works https://ru.wordpress.org/plugins/regenerate-thumbnails/
it does exactly that, and there you can peep all the solutions that you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question