I want to update my plugin and have proper feedback, like the WordPress update/upgrade mechanism. How is this effect done?

Essentially I have a script I want to run that has lots of processing, and with each run through the loop, output another line to the screen. Is this done with the output buffer?

1 Answer
1

Yes, WordPress uses output buffering for displaying these messages. There’s a nifty function you can use within your loop called show_message() which utilizes wp_ob_end_flush_all();

function show_message($message) {
    if ( is_wp_error($message) ){
        if ( $message->get_error_data() )
            $message = $message->get_error_message() . ': ' . $message->get_error_data();
        else
            $message = $message->get_error_message();
    }
    echo "<p>$message</p>\n";
    wp_ob_end_flush_all();
    flush();
}

You might wish to abstract this to your own function as there is a feature in the queue to migrate this to a method within WP_Error. It’s possible this function will become deprecated in the future.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *