Making WordPress.org


Ignore:
Timestamp:
01/15/2019 09:06:15 AM (6 years ago)
Author:
vedjain
Message:

WCPT: Send notifications to community-events or community-team slack channel on status changes in WordCamp/Meetup applications

Whenever a WordCamp/Meetup application is received, accepted or declined, we will send out notifications. This will help in surfacing interesting changes happening in the community.
This is also discussed in https://make.wordpress.org/community/2018/12/24/slack-notifications-for-wordcamp-and-meetup-application-updates/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/class-event-application.php

    r7619 r8083  
    77
    88namespace WordPress_Community\Applications;
     9require_once WCPT_DIR . 'wcpt-event/notification.php';
    910
    1011/**
     
    8586    public function submit_application() {
    8687        $application_data = $this->validate_data( $_POST );
     88
    8789        if ( $this->is_rate_limited() ) {
    8890            $message        = __( 'You have submitted too many applications recently. Please wait and try again in a few hours.', 'wordcamporg' );
     
    9395        } else {
    9496            $this->create_post( $application_data );
    95             $this->notify_applicant_application_received( $this->get_organizer_email(), $this->get_event_location() );
     97            $this->notify_applicant_application_received(
     98                    $this->get_organizer_email(),
     99                    $this->get_event_location()
     100            );
     101
     102            $this->notify_new_application_in_slack();
     103
    96104            $message        = __( "Thank you for your application! We've received it, and we'll contact you once we've had a chance to review it.", 'wordcamporg' );
    97105            $notice_classes = 'notice-success';
     
    175183
    176184    /**
     185     * Get default status for a new application.
     186     *
     187     * @return string|null
     188     */
     189    abstract public static function get_default_status();
     190
     191    /**
     192     * Get publicly accessible report url for a event. Should return null if such report is published.
     193     *
     194     * @return string|null
     195     */
     196    abstract public static function get_application_report_url();
     197
     198    /**
    177199     * Display a notice to applicant while submitting the form.
    178200     *
     
    192214     *
    193215     * @param string $email_address
    194      * @param string $meetup_city
    195      */
    196     public function notify_applicant_application_received( $email_address, $meetup_city ) {
     216     * @param string $event_city
     217     */
     218    public function notify_applicant_application_received( $email_address, $event_city ) {
    197219        //translators: Name of the event. Egs WordCamp.
    198220        $subject = sprintf( __( "We've received your %s application", 'wpct' ), $this->get_event_label() );
     
    204226                'wpct'
    205227            ),
    206             $this->get_event_label(), sanitize_text_field( $meetup_city )
     228            $this->get_event_label(), sanitize_text_field( $event_city )
    207229        );
    208230
    209231        wp_mail( $email_address, $subject, $message, $headers );
    210232    }
     233
     234    /**
     235     * Notify in community slack channel that we've received an application
     236     */
     237    public function notify_new_application_in_slack() {
     238
     239        // Not translating because this will be sent to community events slack channel.
     240        $message = sprintf( "A %s application for %s has been received.", $this->get_event_label(), $this->get_event_location() );
     241
     242        $public_report_url = $this->get_application_report_url();
     243        if ( isset( $public_report_url ) ) {
     244            // `<%s|here> is syntax for slack message to hyperlink text `here` with url provided in `%s`
     245            $message = sprintf( "%s Public status can be followed on <%s|%s application report page>.", $message, $public_report_url, $this->get_event_label() );
     246        }
     247
     248        $default_status = $this->get_default_status();
     249        $queue_size = wp_count_posts( $post_type=$this->get_event_type() )->$default_status;
     250        if ( isset( $queue_size ) ) {
     251            $singular = "is $queue_size application";
     252            $plural   = "are $queue_size applications";
     253            $message = sprintf(
     254                    "%s\n _There %s in vetting queue._",
     255                    $message,
     256                    1 === $queue_size ? $singular : $plural );
     257        }
     258
     259        $attachment = create_event_attachment( $message,  sprintf( "New %s application ", $this->get_event_label() ) );
     260        return wcpt_slack_notify( COMMUNITY_TEAM_SLACK, $attachment );
     261    }
    211262}
Note: See TracChangeset for help on using the changeset viewer.