# Comment Notifications to a Per-Language Moderator

> Sends comment moderation emails to a different moderator depending on the language of the post, using WPML, Polylang or each post's language box, so every comment reaches someone who reads it.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: comments, moderation, email
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/i18n-comment-notify-by-language/

## Code

```php
$wpide_moderators = array( // Language code => moderator email.
    'fr' => 'moderation-fr@example.com',
    'de' => 'moderation-de@example.com',
);

$wpide_post_lang = function ( $post_id ) {
    if ( has_filter( 'wpml_post_language_details' ) ) {
        $details = apply_filters( 'wpml_post_language_details', null, $post_id );
        if ( is_array( $details ) && ! empty( $details['language_code'] ) ) {
            return $details['language_code'];
        }
    }

    if ( function_exists( 'pll_get_post_language' ) ) {
        $lang = pll_get_post_language( $post_id );
        if ( $lang ) {
            return $lang;
        }
    }

    $meta = get_post_meta( $post_id, '_wpide_lang', true );

    return $meta ? strtolower( strtok( $meta, '-' ) ) : '';
};

add_filter( 'comment_moderation_recipients', function ( $emails, $comment_id ) use ( $wpide_moderators, $wpide_post_lang ) {
    $comment = get_comment( $comment_id );
    $lang    = $comment ? $wpide_post_lang( (int) $comment->comment_post_ID ) : '';

    return isset( $wpide_moderators[ $lang ] ) ? array( $wpide_moderators[ $lang ] ) : $emails;
}, 10, 2 );
```

## Notes

Map language codes to email addresses; posts in other languages keep the default recipients.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Comment Notifications to a Per-Language Moderator" 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/
