Making WordPress.org

Changeset 1182


Ignore:
Timestamp:
01/23/2015 09:45:46 PM (12 years ago)
Author:
nacin
Message:

Trac mentions: Restrict notifications to individuals who have posted to a Trac before. see #830.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/mentions-handler.php

    r1181 r1182  
    2323$user        = get_user_by( 'login', $user_login );
    2424
    25 if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM trac_users WHERE user_login = %s", $user_login ) ) ) {
     25function wporg_user_has_visited_trac( $user_login ) {
     26        global $wpdb;
     27        return (bool) $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM trac_users WHERE user_login = %s", $user_login ) );
     28}
     29
     30if ( ! wporg_user_has_visited_trac( $user_login ) ) {
    2631        $wpdb->insert( 'trac_users', compact( 'user_login' ) );
    2732}
     33
     34add_filter( 'wporg_notifications_notify_username', function( $notify, $username ) use ( $type, $payload, $wpdb ) {
     35        if ( $type === 'ticket' ) {
     36                // Don't need a query to say we can notify the owner and reporter.
     37                if ( $username === $payload->owner || $username === $payload->reporter ) {
     38                        return true;
     39                }
     40        }
     41
     42        if ( wporg_user_has_visited_trac( $username ) ) {
     43                return true;
     44        }
     45        return $notify;
     46}, 10, 2 );
    2847
    2948$notif->match_notify( array(
Note: See TracChangeset for help on using the changeset viewer.