Making WordPress.org


Ignore:
Timestamp:
08/06/2020 07:44:59 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Add a notification email to committers when a new committer or support rep is added.

Fixes #5351.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r10000 r10121  
    33
    44use WP_User;
     5use WordPressdotorg\Plugin_Directory\Email\Committer_Added_Notification;
     6use WordPressdotorg\Plugin_Directory\Email\Support_Rep_Added_Notification;
    57
    68/**
     
    205207                        $plugin_slug
    206208                );
     209
     210                // Only notify if the current process is interactive - a user is logged in.
     211                $should_notify = (bool) get_current_user_id();
     212                // Don't notify if a plugin admin is taking action on a plugin they're not (yet) a committer for.
     213                if ( current_user_can( 'plugin_approve' ) && ! in_array( wp_get_current_user()->user_login, $existing_committers, true ) ) {
     214                        $should_notify = false;
     215                }
     216
     217                if ( $should_notify ) {
     218                        $existing_committers[] = $user->user_login;
     219
     220                        $email = new Committer_Added_Notification(
     221                                $plugin_slug,
     222                                $existing_committers,
     223                                [
     224                                        'committer' => $user,
     225                                ]
     226                        );
     227                        $email->send();
     228                }
    207229
    208230                return $result;
     
    353375                );
    354376
     377                $committers = self::get_plugin_committers( $plugin_slug );
     378
     379                // Only notify if the current process is interactive - a user is logged in.
     380                $should_notify = (bool) get_current_user_id();
     381                // Don't notify if a plugin admin is taking action on a plugin they're not a committer for.
     382                if ( current_user_can( 'plugin_approve' ) && ! in_array( wp_get_current_user()->user_login, $committers, true ) ) {
     383                        $should_notify = false;
     384                }
     385
     386                if ( $should_notify ) {
     387                        $email = new Support_Rep_Added_Notification(
     388                                $plugin_slug,
     389                                $committers,
     390                                [
     391                                        'rep' => $user,
     392                                ]
     393                        );
     394                        $email->send();
     395                }
     396
    355397                return $result;
    356398        }
Note: See TracChangeset for help on using the changeset viewer.