Get Email Notifications When a New Admin Is Added in WordPress (Easy Guide)

Hey friends! 👋

If you’re managing a WordPress site and care even a little bit about security, this one’s for you.

🔒 Why You Should Care About New Admin Users

In WordPress, users with the Administrator role have full control — they can install plugins, edit themes, delete content, change settings, and even remove other admins. 😳

So imagine someone adds a new admin without you knowing. That’s a big security risk.

✅ What We’re Going to Do

We’ll write a simple code snippet that sends an email notification every time:

  • A new user is registered as an Administrator

  • An existing user’s role is changed to Administrator

This is perfect for WordPress site owners, web developers, security-conscious admins, or even agencies managing client websites.

📜 Code to Send Email Alerts When a New Admin Is Added

Just copy this code and paste it into your theme’s functions.php file or create a mini plugin:

// Notify when a new admin is registered
function notify_on_new_admin_registration($user_id) {
$user = get_userdata($user_id);
if (in_array('administrator', (array) $user->roles)) {
send_admin_alert_email($user);
}
}
add_action('user_register', 'notify_on_new_admin_registration');

// Notify when an existing user's role is changed to admin
function notify_on_admin_role_change($user_id, $old_user_data) {
$user = get_userdata($user_id);
$old_roles = (array) $old_user_data->roles;
$new_roles = (array) $user->roles;

// If user wasn't an admin before, but now is
if (!in_array('administrator', $old_roles) && in_array('administrator', $new_roles)) {
send_admin_alert_email($user);
}
}
add_action('profile_update', 'notify_on_admin_role_change', 10, 2);

// Shared function to send email
function send_admin_alert_email($user) {
$to = 'test1@gmail.com, test2@gmail.com, test3@gmail.com';
$subject = 'Administrator Role Assigned';
$message = "A user has been assigned the Administrator role:\n\n";
$message .= "Username: " . $user->user_login . "\n";
$message .= "Email: " . $user->user_email . "\n";
$message .= "Updated: " . current_time('mysql');

wp_mail($to, $subject, $message);
}

 

📨 Who Gets the Email Notification?

Right now, the email goes to:

You can easily change or add more recipients — just edit the $to variable in the code.

 

⚠️ Bonus Tip: Make Sure WordPress Can Send Emails

Sometimes WordPress email notifications don’t work because your server blocks them or your emails land in spam. To fix this, I highly recommend using the WP Mail SMTP plugin. It connects your WordPress site to Gmail, Outlook, or any SMTP provider so emails send reliably.


🚀 Final Thoughts

This is a simple but powerful trick to keep your WordPress site secure. You’ll always know when a new admin is added — either during registration or by someone editing a user.

No more surprises. No more silent admin access.

Let me know if you want me to turn this into a small plugin for your site. Happy coding! 👨‍💻✨

How to Display Related Products/Posts Using JetEngine Query Builder – Crocoblock

When building a WooCommerce store with Elementor and JetEngine by Crocoblock, you might want to display related products dynamically based on the current product’s category. In this tutorial, I’ll guide you through creating a custom query using JetEngine Query Builder and implementing it on your single product page.

Step 1: Create an Archive Page for Products

First, you need to create an archive page for your WooCommerce products using Elementor. This page will be designed to display all products, and later we will integrate a related product section.

  1. Go to Templates > Theme Builder in WordPress.
  2. Click on Add New Template and choose Archive.
  3. Use Elementor to design the archive layout according to your needs.
  4. Use a Listing Grid (created with JetEngine) to display products.
  5. Publish the template and assign it to the product archive.

Step 2: Create a Query in JetEngine Query Builder

Now, let’s create a query that fetches related products dynamically based on the current product’s category.

  1. Navigate to JetEngine > Query Builder in the WordPress dashboard.
  2. Click Add New to create a new query.
  3. Set a name for the query (e.g., “Related Products”).
  4. Choose Query Type: Posts Query.
  5. In the Post Query section, go to the General tab and:
    • Select Post Type: Products (since we’re working with WooCommerce products).
  6. Switch to the Tax Query tab:
    • Click on Add New.
    • Select Taxonomy: product_cat (Product Categories).
    • Set Field: Term ID.
    • Set Terms: Current Terms -> Products Categories.
    • Set Compare operation: IN.
  7. Save the query.

Step 3: Add the Query to the Single Product Page

After creating the query, the next step is to display the related products on the single product page using Elementor.

  1. Go to Templates > Theme Builder and edit your Single Product Page template.
  2. Drag and drop the Listing Grid widget (created with JetEngine) onto the page.
  3. In the Query section of the Listing Grid settings:
    • Select Custom Query.
    • Choose the query you created earlier (“Related Products”).
  4. Adjust the layout and styling as needed.
  5. Save and update the template.

Conclusion

By following these steps, you can dynamically display related products based on the current product’s category using JetEngine Query Builder. This method ensures that your WooCommerce store provides a seamless shopping experience with relevant product recommendations.