Site icon Hip-Hop Website Design and Development

How would I get the new plugin version on this function?

I created a function to create a "Changelog" for every time I update a plugin on our site. As some things can break, I figured it would be useful to be able to backtrace what got updated when.

I have the function working, but I’d like to know if I can access the new plugin version. Currently the message is 2022-01-14 14:03:34 -- WooCommerce was updated from version 6.0.0. How can I write ...from version 6.0.0 to version 6.1.0?

Full Function:

    function plugin_changelog($upgrader_object, $options) {

        $changelog = get_template_directory() . '/assets/changelog/plugin-changelog.txt';

        if ($options['action'] == 'update' && $options['type'] == 'plugin') {

            $time = current_time('mysql');
            $plugin_name = $upgrader_object->skin->plugin_info['Title'];
            $plugin_version = $upgrader_object->skin->plugin_info['Version'];
            $plugin_success = $upgrader_object->skin->result;

            // Main message:
            $message = '' . $time . ' -- ' . $plugin_name . ' was updated from version ' . $plugin_version . '';

            if ($plugin_success) {

                if (file_exists($changelog)) {
                    $file = fopen($changelog, 'a');
                    fwrite($file, $message . "nn");
                }

                fclose($file);
            }
        }
    }

    add_action('upgrader_process_complete', 'plugin_changelog', 10, 2);

Lastly, do you see any security or performance concerns from this function?