# Email the Admin When Someone Else Publishes

> Emails the site admin whenever a post or page is published by a user who is not an administrator, so you can review new content as soon as it goes live.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, alerts, editorial
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-alert-published-by-others/

## Code

```php
$wpide_publish_alert_types = array( 'post', 'page' );

add_action( 'transition_post_status', function ( $new, $old, $post ) use ( $wpide_publish_alert_types ) {
    if ( 'publish' !== $new || 'publish' === $old || ! in_array( $post->post_type, $wpide_publish_alert_types, true ) || wp_is_post_revision( $post ) ) {
        return;
    }

    $author = get_userdata( (int) $post->post_author );
    if ( ! $author || user_can( $author, 'manage_options' ) ) {
        return;
    }

    wp_mail(
        get_option( 'admin_email' ),
        sprintf( '[%s] New %s by %s: %s', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $post->post_type, $author->display_name, wp_strip_all_tags( get_the_title( $post ) ) ),
        sprintf( "%s just published \"%s\".\n\nView: %s\nEdit: %s", $author->display_name, wp_strip_all_tags( get_the_title( $post ) ), get_permalink( $post ), admin_url( 'post.php?post=' . $post->ID . '&action=edit' ) )
    );
}, 10, 3 );
```

## Notes

Covers posts and pages by default; scheduled posts trigger the email when they actually go live.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Email the Admin When Someone Else Publishes" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
