Display update notification messages like ‘What’s New’

I am about to push out a new update for my plugin. I’ve used a few functions only available to WordPress 3.8, which is fine because I want to support the latest version.

How do I display a message to the user before they update the plugin with a list of What’s New, or just a general warning that WordPress 3.8 is required to run the latest version of the plugin?

I have attached a screenshot of where I’d like the message to display. Is this something that is displayed based on what you put in the change log of your readme.txt in trunk?

enter image description here

1 Answer
1

You can hook into in_plugin_update_message-{$file}.

For the above plugin, the according code looks as follows:

add_action('admin_menu', array($this,'admin_menu'), 11);
function admin_menu()
{
    global $pagenow;

    if( $pagenow == 'plugins.php' )
    {
        $hook = apply_filters('acf/get_info', 'hook');

        add_action( 'in_plugin_update_message-' . $hook, array($this, 'in_plugin_update_message'), 10, 2 );
    }
}

function in_plugin_update_message( $plugin_data, $r )
{
    $version = apply_filters('acf/get_info', 'version');
    $readme = wp_remote_fopen( 'http://plugins.svn.wordpress.org/advanced-custom-fields/trunk/readme.txt' );
    $regexp = '/== Changelog ==(.*)= ' . $version . ' =/sm';
    $o = '';

    if( !$readme )
    {
        return;
    }

    preg_match( $regexp, $readme, $matches );

    if( ! isset($matches[1]) )
    {
        return;
    }

    $changelog = explode('*', $matches[1]);
    array_shift( $changelog );

    if( !empty($changelog) )
    {
        $o .= '<div class="acf-plugin-update-info">';
        $o .= '<h3>' . __("What's new", 'acf') . '</h3>';
        $o .= '<ul>';

        foreach( $changelog as $item )
        {
            $item = explode("https://wordpress.stackexchange.com/questions/129392/http", $item);

            $o .= '<li>' . $item[0];

            if( isset($item[1]) )
            {
                $o .= '<a href="https://wordpress.stackexchange.com/questions/129392/http" . $item[1] . '" target="_blank">' . __("credits",'acf') . '</a>';
            }

            $o .= '</li>';


        }

        $o .= '</ul></div>';
    }

    echo $o;
}

Ad: Here is how I did this for a plugin I’m involved in.

Leave a Comment