When it comes to my most basic of wordpress stack, several plugins get installed by default in my so-called basic stack. These plugins all serve a distinct purpose, but they’re all entwined, not to the point that without one there would be a failure, but I have build interdependancy through them all.
These plugins are as follows:
- Ninja Updater – My own utility plugin
- Devkit – By dPlugins, a development tool and WordPress tools plugin
- ACF Pro – This needs no introduction and has been a core part of my stack for years
- WPCodeBox – Snippet Manager
- SureMails – To handle SMTP and API service (Emailit and Brevo)
- Notify for Suremail – To handle Notifications and Failures to PushOver / Discord / Slack / Webhook
This article will focus mainly on the latest improvements to the first two but will cover some of the customations contained within Ninja Updater that work with Suremail and SureMail Notification, its also worth mentioning that two additional plugins could be installed one always and the second if I am using bricks and they are my custom version of Tasks after install for API key and Licence Deployments as well as settings changes to the WPConfig and if its a bricks installation foundations.
I am able to rely on these being installed and set up, and for example, Ninja Updater, automatically writes some of the information to the database for Suremails, i.e., a default emailit connection, removes the setup splashscreen and reduces some of the Sure Branding. It does all this: reading API Keys set and written by Tasks after install.
Devkit
The changes to Ninja Updater have been influenced by devkit and things I wanted to do. I am still running a custom version of Devkit, as not all my improvements have been added to core, but it’s getting closer. They added the admin autologin notification this week and the debug log updates. The only one needed now is a temp login action hook.
On deployed sites, I use Jeff Starr’s awesome little simple login notification to get notifications about logins, for my own admin accounts and also for rarely used admin accounts, so I am aware if they are being used. I wanted to be able to do the same with the devkit autologin and temporary users.
They have added a dpdev_temp_user_logged_in hook to the admin auto login, I’d also like to see this replicated for the temp user login, and I have built a simple script to capture this, but I hit a problem. I wanted to deploy it as an optional snippet within Ninja Updater but couldn’t get it working even though it worked perfectly in WPCodeBox.
The Changes needed
So I worked out the issue was because the snippet needed to be there on init because of ajax login, but just moving the snippets all to init would break the plugins’ loaded functionality. So i settled on loading the snippets at different times and although I now pretty much exclusively use 8.0+ I still wanted some capatability with 7.4 just incase as its still common to take a site on 7.4 and have to bring it up gradually and fix the issues and Ninja Updater is a key plugin for me doing this after all it gives me access to snippets, updates and install directly from my own custom repo as well as bundle installation.
I already had a suitable end with haystack and needle, I’ve used to keep compatibility when checking endings of files in 8.0 + with 7.4, so I reused this and decided I would load .php snippets on, plugins loaded, but for init needed snippets, these will be loaded on init and I would use the ends with to find those with .early.php in their name.
This fixed the loading issue. I also needed a way to activatethe snippet below within the snippet directory of all installs without having to manually set this by login in to every install with this combination.
/**
* Send an email when a temporary user logs in.
*
* @param WP_User $admin_user The user object passed from the action.
*/
function dpdev_notify_admin_temp_login( $admin_user ) {
error_log( 'dpdev_temp_user_logged_in fired but no valid user object.' );
// Ensure we have a valid user object
if ( ! $admin_user || ! isset( $admin_user->user_email ) ) {
return;
}
// Get site admin email
$admin_email = get_option( 'admin_email' );
// Email subject (editable)
$subject = 'Temporary User Logged In - ' . get_bloginfo( 'name' );
// Email message (fully editable)
$message = "A temporary login has just been used.\n\n";
$message .= "User ID: " . $admin_user->ID . "\n";
$message .= "Username: " . $admin_user->user_login . "\n";
$message .= "Email: " . $admin_user->user_email . "\n";
$message .= "Time: " . current_time( 'mysql' ) . "\n";
$message .= "IP Address: " . ( $_SERVER['REMOTE_ADDR'] ?? 'Unknown' ) . "\n";
// Optional headers
$headers = array( 'Content-Type: text/plain; charset=UTF-8' );
// Send the email
wp_mail( $admin_email, $subject, $message, $headers );
}
// Hook into your custom action
add_action( 'dpdev_temp_user_logged_in', 'dpdev_notify_admin_temp_login' );JavaScriptI settled on a new function which allows me to set snippets and plugin updates to override what has been set on new updates of the main ninja updater plugin which now means new snippets can be auto deployed and in the cases where updates for a plugin can no longer be served by the original author i.e discontinued a new update can be forced to be grabbed through Ninja Updater so saving future me an issue too.
In Summary
While not the most interesting of updates, its feature rich, it works with the dependencies of my stack and allows me to continue to deploy what i need to and where all within my own utility plugin
