Creating a Plugin Update Notification Email System

Posted on 19th June 2023

in the title

Introduction

WordPress plugin development is a process that involves creating a unique, custom-made plugin for a specific website or purpose. In this guide, we will show you how to create a plugin update notification email system using the WordPress Plugin API. This notification system will email the website administrator when a new plugin update is available.

Creating the Plugin

The first step in creating our update notification email system is to create a new file called “update-notifier.php” in our WordPress plugin directory. In this file, we will first need to include the WordPress Plugin API, which can be done by adding the following line of code:

include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

Next, we need to create a function that will check if a new plugin update is available. This can be done by using the has_update() function from the WordPress Plugin API. This function takes two parameters: the plugin file path and the current plugin version. If a new update is available, this function will return true. Otherwise, it will return false.

We can then use this function to trigger our update notification email system. First, we need to create a new function that will send an email notification when a new update is available. This function will use the wp_mail() function from the WordPress API to send an email to the website administrator. The wp_mail() function takes four parameters: the email address to send the notification to, the email subject, the email body, and an array of additional headers. In our email body, we will include a link to the plugin page so that the administrator can update the plugin.

Next, we need to add a hook that will trigger our update notification email function when a new update is available. We can do this by using the add_filter() function from the WordPress Plugin API. This function takes two parameters: the hook name and the function to call when the hook is triggered. In our case, we will use the pre_update_option hook, which is triggered before an option is updated. We will then need to specify the name of our update notification email function as the second parameter.

Lastly, we need to register our plugin with WordPress. This can be done by using the register_activation_hook() function from the WordPress Plugin API. This function takes two parameters: the plugin file path and the function to call when the plugin is activated. In our case, we will use the register_activation_hook() function to trigger our update notification email function when the plugin is activated.

Conclusion

In this guide, we showed you how to create a plugin update notification email system using the WordPress Plugin API. This notification system will email the website administrator when a new plugin update is available. By following the steps in this guide, you can create a similar system for your own WordPress plugins.

The Plugin Update Notification Email System

This system will notify you by email when a new version of a WordPress plugin is released. It’s similar to the built-in WordPress update notifications, but for plugins only.

First, you need to install and activate the Plugin Update Notifier plugin. Upon activation, you need to visit Settings ยป Plugin Update Notifier to configure the plugin.

The first option on the settings page allows you to select the minimum WordPress version required for a plugin update. By default, the Minimum WordPress Version is set to 3.8. You can change it to a higher or lower version number. However, we recommend that you leave it at the default value.

The second option allows you to set the number of days between update checks. The plugin will check for updates once every X days. The default value is set to 1, but you can change it to a higher number if you want.

The next option allows you to select the email address where you want to receive update notifications. You can add multiple email addresses by separating them with a comma.

The final option allows you to select the plugins for which you want to receive update notifications. By default, the plugin will notify you about updates for all the plugins installed on your site. However, you can uncheck the plugins you don’t want to receive updates for.

Don’t forget to click on the ‘Save Changes’ button to store your settings. That’s it. You are now set to receive WordPress plugin update notifications by email.

How to Manually Update a WordPress Plugin?

If you don’t want to wait for the plugin update notification email, then you can manually update the plugin from the WordPress admin area. First, you need to visit the ‘Updates’ page and then click on the ‘Check Again’ button. WordPress will now check for updates for all the plugins installed on your site.

If there is an update available for a plugin, then you will see a notice next to that plugin saying there is an update available. Simply click on the ‘Update Now’ link to update the plugin. WordPress will now download and install the updated version of the plugin.

That’s it. You have successfully updated a WordPress plugin.

If you want to learn more about WordPress, then please check out our WordPress 101 course.

Creating a Plugin Update Notification Email System

In this article, we will show you how to create a plugin update notification email system. This is a great way to keep your plugins up to date and notified of new updates.

First, you need to create a new file and name it “plugin-updates.php”. Then, copy and paste the following code into the file:

checked ) ) {

return $transient;

}

// Send request checking for plugin updates

$request_args = array(

‘slug’ => ‘plugin-updates’,

‘version’ => $transient->checked[‘plugin-updates’],

);

$request_string = prepare_request( ‘plugin_update’, $request_args );

// Start checking for an update

$raw_response = wp_remote_post( ‘https://api.wordpress.org/plugins/update-check/1.1/’, $request_string );

if ( ! is_wp_error( $raw_response ) && ( $raw_response[‘response’][‘code’] == 200 ) ) {

$response = unserialize( $raw_response[‘body’] );

}

if ( isset( $response ) && is_object( $response ) && ! empty( $response->plugins ) ) {

$transient->response[‘plugin-updates’] = $response->plugins;

}

return $transient;

}

add_filter( ‘pre_set_site_transient_update_plugins’, ‘update_notifier_check_for_update’ );

// This function retrieves a plugin folder/main file by its slug

function get_plugin_basename_from_slug( $slug ) {

$keys = array_keys( get_plugins() );

foreach ( $keys as $key ) {

if ( preg_match( ‘|^’ . $slug .’/|’, $key ) ) {

return $key;

}

}

return $slug;

}

// This function connects to the remote API server, retrieves information and returns it as an array

function request_plugin_information( $plugin_slug ) {

// Build POST request

$request_args = array(

‘slug’ => $plugin_slug,

);

$request_string = prepare_request( ‘plugin_information’, $request_args );

// Start checking for an update

$raw_response = wp_remote_post( ‘https://api.wordpress.org/plugins/info/1.0/’, $request_string );

if ( ! is_wp_error( $raw_response ) && ( $raw_response[‘response’][‘code’] == 200 ) ) {

$response = unserialize( $raw_response[‘body’] );

}

return $response;

}

// This function prepares the data for the API request

function prepare_request( $action, $args ) {

global $wp_version;

return array(

‘body’ => array(

‘action’ => $action,

‘request’ => serialize( $args ),

‘api-key’ => md5( home_url() ),

),

‘user-agent’ => ‘WordPress/’ . $wp_version . ‘; ‘ . home_url()

);

}

// This function shows the plugin information in the WordPress Dashboard

function update_notifier_plugin_row( $plugin_file, $plugin_data, $status ) {

$current = get_site_transient( ‘update_plugins’ );

if ( isset( $current->response[ $plugin_file ] ) ) {

$r = $current->response[ $plugin_file ];

}

if ( ! isset( $r ) ) {

return false;

}

$plugins_allowedtags = array(

‘a’ => array( ‘href’ => array() ),

‘abbr’ => array(),

‘acronym’ => array(),

‘code’ => array(),

’em’ => array(),

‘strong’ => array(),

);

$plugin_name = wp_kses( $plugin_data[‘Name’], $plugins_allowedtags );

$author = wp_kses( $plugin_data[‘Author’], $plugins_allowedtags );

$version = wp_kses( $plugin_data[‘Version’], $plugins_allowedtags );

$author_url = esc_url( $plugin_data[‘AuthorURI’] );

$name = get_plugin_basename_from_slug( $plugin_file );

echo ‘

‘;

if ( ! current_user_can( ‘update_plugins’ ) ) {

printf( __(‘There is a new version of %1$s available. View version %3$s details.’, ‘plugin-updates’), $plugin_name, esc_url( $author_url ), $version );

} elseif ( empty( $r[‘package’] ) ) {

printf( __(‘There is a new version of %1$s available. View version %3$s details automatic update is unavailable for this plugin.’, ‘plugin-updates’), $plugin_name, network_admin_url( ‘plugin-install.php?tab=plugin-information&plugin=’ . $name . ‘&TB_iframe=true&width=640&height=500’ ), $version );

} else {

printf( __(‘There is a new version of %1$s available. View version %3$s details or update now.’, ‘plugin-updates’), $plugin_name, network_admin_url( ‘plugin-install.php?tab=plugin-information&plugin=’ . $name . ‘&TB_iframe=true&width=640&height=500’ ), $version, wp_nonce_url( self_admin_url( ‘update.php?action=upgrade-plugin&plugin=’ ) . $plugin_file, ‘upgrade-plugin_’ . $plugin_file ) );

}

echo ‘

‘;

}

// This function determines if a plugin has an update, and adds the update row to the WordPress Dashboard if so

function update_notifier_check_plugin_update() {

$plugin_file = get_plugin_basename_from_slug( ‘plugin-updates’ );

$current = get_site_transient( ‘update_plugins’ );

if ( isset( $current->response[ $plugin_file ] ) ) {

add_action( “after_plugin_row_” . $plugin_file, ‘update_notifier_plugin_row’, 10, 3 );

}

}

add_action( ‘admin_init’, ‘update_notifier_check_plugin_update’ );

?>

This code goes in your plugin’s main file.

Next, you need to create a new file and name it “plugin-update-notifier.php”. Then, copy and paste the following code into the file:

<?php

/*

Plugin Name: Plugin Update Notifier

Plugin URI: https://example.com/plugin-update-notifier/

Description: This plugin will send you an email when a plugin is updated.

Version: 1.0

Author: John Doe

Author URI: https://example.com

*/

// This function runs when the plugin is updated

function update_notifier_update_db_check() {

global $plugin_updates, $wp_version;

// Compare