I’m writing a plugin right now that will populate custom metadata for all posts on the site based on a certain rule. I’ve already created a Plugin’s settings page and a logic that should be triggered for each post. See below:
add_action('admin_menu', 'plugin_admin_page');
function plugin_admin_page() {
add_options_page('Plugin Page', 'Plugin Section', 'manage_options', 'plugin_page', 'plugin_options_page');
}
function plugin_options_page() {
// I need to add a button to trigger bulk operation from here. This is a "start_bulk_operation" function.
// Also, I'd like to display progress on this Settings page.
}
function start_bulk_operation() {
$posts = get_posts( array('post_type' => 'post', 'numberposts' => -1 ) );
foreach ( $posts as $post ):
// Do something with the post
endforeach;
}
What I don’t know how to do is how to trigger my custom logic (plugin’s function) from the Settings page. Also it would be great if the approach will let me show progress as well, like “Updating post #50 out of 897”.
Any ideas? Thanks in advance!