How prevent STDOUT of Plugin_Upgrader->upgrade(…)?

✨ Explanation and Solution

Updating the plugin to prevent standard output couldn’t be easier. No need to create a custom skin, WordPress already provides one for this case:

Automatic_Upgrader_Skin

Description: This skin is designed to be used when no output is intended, all output is captured and stored for the caller to process and log/email/discard.

After digging a lot I found that after every plugin update the next action is called 'upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'). This action is called to update other parts such as the language packs.

This action create new instance of Language_Pack_Upgrader with a new custom Language_Pack_Upgrader_Skin which also generates data in the standard output.

But if the WP_Upgrader who call it use and Automatic_Upgrader_Skin the Language_Pack_Upgrader will reuse it.

We therefore only need the following few lines to prevent standard output during an update:

$skin = new Automatic_Upgrader_Skin();
$plugin_upgrader = new Plugin_Upgrader($skin);
$result = $plugin_upgrader->upgrade($name);

📍 Why ob_start and ob_get_clean doesn’t work

Skins generated by the “upgrader_process_complete” action call the skin->feekback() method, which in turn calls show_message().

This contains the following lines, which broke my first implementation.

wp_ob_end_flush_all();
flush();

error code: 523