Displaying admin notice when update for specific plugin is available

I use the German Market plugin for generating invoices and use a custom font which is not integrated into the plugin by default, so I have to re-upload it after updating the plugin. So I do not forget this, I implemented an admin notice which is displayed if a German Market update is available. That is not very difficult, and this is the complete code:

/** * Display admin notice so I remember uploading the Clavo font after updating German Market */ function fbn_german_market_typography_notice() { $update_plugins_transient = get_site_transient( 'update_plugins' ); if ( $update_plugins_transient->response['woocommerce-german-market/WooCommerce-German-Market.php'] ) { add_action( 'all_admin_notices', function () { ?> <div class="notice notice-warning"> <p><strong>Nach dem »German Market«-Update den Clavo-Font für Rechnungen wieder hochladen!</strong></p> </div> <?php } ); } } add_action( 'admin_init', 'fbn_german_market_typography_notice' );
Code language: JavaScript (javascript)

I hook fbn_german_market_typography_notice() to admin_init. First, the function saves the value of the update_plugins transient, which stores information about available plugin updates. If $update_plugins_transient->response['woocommerce-german-market/WooCommerce-German-Market.php'] is not empty, an update is available.

In this case, the admin notice is displayed (I use all_admin_notices, so the notice is not only showed in the network admin), which hopefully will remind me to upload the font for the invoices … 🙂

Of course, the array key is different for every plugin. You can take a look at the value of the transient via var_dump( $update_plugins_transient ); to find the correct key.

PS: More on admin notices in the post »Admin Notices in Plugin UIs« by Caspar Hübinger.

Leave a Reply

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