All WordPress snippets
Want your own copy?
Fork this repo and build your own snippet collection. Fork on GitHub →
WordPress
Notify the Admin When a User Updates Their Profile
Sends an email to the site admin any time a user saves changes to their profile — useful on multi-author or membership sites.
php
function user_profile_update( $user_id ) {
$user_info = get_userdata( $user_id );
$to = get_option( 'admin_email' );
$subject = 'User Profile Updated';
$message = "Hello Administrator,nnThe " . $user_info->user_nicename . " (" . $user_info->user_email . ") profile has been updated! nn";
$message .= "Site URL: " . get_bloginfo( 'wpurl' ) . "nn";
$message .= "Regards, n" . get_option( 'blogname' );
wp_mail( $to, $subject, $message );
}
add_action( 'profile_update', 'user_profile_update', 10, 2 );
More WordPress snippets
Register and Output a Custom Nav Menu
Adds a new menu location you can assign in Appearance → Menus, shows how to output it in a template, and includes the multi-menu version too.
Define a Reusable Global String
A simple pattern for storing a value — like a phone number or address — in one place and reusing it anywhere in your theme.
Auto-Escape HTML Typed Inside Code Tags
Makes sure any markup typed inside <code> or <tt> tags in the editor gets escaped automatically, so it displays as visible text instead of being rendered as real HTML.