Making WordPress.org

Changeset 8083


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/

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt
Files:
1 added
8 edited

Legend:

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

    r8080 r8083  
    5656        add_action( 'transition_post_status', array( $this, 'log_status_changes' ), 10, 3 );
    5757
     58        add_action( 'transition_post_status', array( $this, 'notify_application_status_in_slack' ), 10, 3 );
     59
    5860        add_filter( 'redirect_post_location', array( $this, 'add_admin_notices_to_redirect_url' ), 10, 2 );
    5961
    6062        // Admin notices
    6163        add_action( 'admin_notices', array( $this, 'print_admin_notices' ) );
     64
     65        add_action( 'send_decline_notification_action',  'Event_Admin::send_decline_notification', 10, 3 );
     66
    6267    }
    6368
     
    275280            add_post_meta( $post->ID, "_status_change_log_$post->post_type $log_id", time() );
    276281        }
     282    }
     283
     284    /**
     285     * Hooked to `transition_post_status`, will send notifications to community slack channels based whenever an application status changes to something that we are interested in. Most likely would be when an application is declined or accepted.
     286     *
     287     * @param string  $new_status New status
     288     * @param string  $old_status Old Status
     289     * @param WP_Post $event
     290     */
     291    abstract public function notify_application_status_in_slack( $new_status, $old_status, WP_Post $event );
     292
     293    /**
     294     * Schedule notificaiton for declined application. Currently supports WordCamp and Meetup
     295     *
     296     * @param WP_Post $event Event object
     297     * @param string  $label Could be WordCamp or Meetup
     298     * @param string  $location
     299     *
     300     * @return bool|string
     301     */
     302    public static function schedule_decline_notification( $event, $label, $location ) {
     303        wp_schedule_single_event( time() + DAY_IN_SECONDS, 'send_decline_notification_action', array( $event->ID, $label, $location ) );
     304    }
     305
     306    /**
     307     * Send declined notification to community team slack channel.
     308     *
     309     * @param int    $event_id
     310     * @param string $label
     311     * @param string $location
     312     */
     313    public static function send_decline_notification( $event_id, $label, $location ) {
     314        $message = sprintf(
     315            "A %s application for %s has been declined, and the applicant has been informed via email.",
     316            $label,
     317            $location
     318        );
     319
     320        $attachment = create_event_status_attachment( $message, $event_id, '' );
     321        wcpt_slack_notify( COMMUNITY_TEAM_SLACK, $attachment );
    277322    }
    278323
  • 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}
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-loader.php

    r7607 r8083  
    5151        require_once ( WCPT_DIR . 'wcpt-meetup/meetup.php' );
    5252        require_once ( WCPT_DIR . 'wcpt-meetup/class-meetup-admin.php' );
     53        require_once ( WCPT_DIR . 'wcpt-event/class-event-admin.php' ); // required for declined application cron to work.
    5354
    5455        // Require admin files.
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/class-meetup-admin.php

    r7889 r8083  
    99
    1010require_once WCPT_DIR . 'wcpt-event/class-event-admin.php';
    11 
    12 if ( ! class_exists( 'MeetupAdmin' ) ) :
     11require_once WCPT_DIR . 'wcpt-event/notification.php';
     12
     13
     14if ( ! class_exists( 'Meetup_Admin' ) ) :
    1315
    1416    /**
     
    477479            $this->update_meetup_organizers( $organizers_list, $post );
    478480
     481        }
     482
     483        /**
     484         * Send notification to slack when a Meetup becomes active in the chapter or is declined.
     485         *
     486         * @param string  $new_status
     487         * @param string  $old_status
     488         * @param WP_Post $meetup
     489         *
     490         * @return null|bool Will be null if notification was not enabled, or false if notifcation was attempted but failed. true if notification was successful
     491         */
     492        public function notify_application_status_in_slack( $new_status, $old_status, WP_Post $meetup ) {
     493
     494            $notification_enabled = apply_filters( 'meetup_application_notification_enabled', true );
     495
     496            if ( ! $notification_enabled ) {
     497                return null;
     498            }
     499
     500            if ( 'wcpt-mtp-active' === $new_status ) {
     501                return $this->notify_new_meetup_group_in_slack( $meetup );
     502            } elseif ( 'wcpt-mtp-rejected' === $new_status ) {
     503                $location = get_post_meta( $meetup->ID, 'Meetup Location', true );
     504                return $this->schedule_decline_notification( $meetup, $this->get_event_label(), $location );
     505            }
     506        }
     507
     508        /**
     509         * Send notification when a new Meetup groups is added to the chapter.
     510         *
     511         * @param WP_Post $meetup Meetup post object
     512         *
     513         * @return bool|string
     514         */
     515        public static function notify_new_meetup_group_in_slack( $meetup ) {
     516
     517            // Not translating strings here because these will be sent to Slack.
     518            $city            = get_post_meta( $meetup->ID, 'Meetup Location', true );
     519            $organizer_slack = get_post_meta( $meetup->ID, 'Slack', true );
     520            $meetup_link     = get_post_meta( $meetup->ID, 'Meetup URL', true );
     521            $title           = "New meetup group added";
     522
     523            $message = sprintf(
     524                "Let's welcome the new WordPress meetup group%s%s, to the chapter! :tada: :community: :wordpress:\n%s",
     525                isset( $city ) ? " in $city," : "",
     526                isset( $organizer_slack ) ? " organized by @$organizer_slack" : "",
     527                $meetup_link
     528            );
     529
     530            $attachment = create_event_status_attachment( $message, $meetup->ID, $title );
     531
     532            return wcpt_slack_notify( COMMUNITY_EVENTS_SLACK, $attachment );
    479533        }
    480534
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/class-meetup-application.php

    r7887 r8083  
    271271    public function get_event_location() {
    272272        if ( isset( $this->post->ID ) ) {
    273             return get_post_meta( $this->post->ID, 'q_city', true );
    274         }
     273            return get_post_meta( $this->post->ID, 'Meetup Location', true );
     274        }
     275    }
     276
     277    /**
     278     * Public report URL for Meetup Applications
     279     */
     280    public static function get_application_report_url() {
     281        return "https://central.wordcamp.org/reports/meetup-applications/";
    275282    }
    276283
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/meetup.php

    r7607 r8083  
    33namespace WordPress_Community\Applications\Meetup;
    44
    5 require_once 'class-meetup-application.php';
     5require_once WCPT_DIR . 'wcpt-meetup/class-meetup-application.php';
    66use WordPress_Community\Applications\Meetup_Application;
    77
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/class-wordcamp-application.php

    r7619 r8083  
    1515
    1616    static function get_event_label() {
    17         __( 'WordCamp', 'wordcamporg' );
     17        return __( 'WordCamp', 'wordcamporg' );
    1818    }
    1919
     
    158158
    159159    /**
     160     * Gets default status of new WordCamp application
     161     *
     162     * @return string
     163     */
     164    public static function get_default_status() {
     165        return WCPT_DEFAULT_STATUS;
     166    }
     167
     168    /**
     169     * Public report URL for WordCamp applications.
     170     *
     171     * @return string
     172     */
     173    public static function get_application_report_url() {
     174        return "https://central.wordcamp.org/reports/application-status/";
     175    }
     176
     177    /**
    160178     * Create a WordCamp post from an application
    161179     *
     
    186204        add_post_meta( $post_id, '_application_data', $data );
    187205        add_post_meta( $post_id, '_application_submitter_ip_address', $_SERVER['REMOTE_ADDR'] );
     206
    188207
    189208        add_post_meta(
     
    231250    function get_organizer_email() {
    232251        if ( isset( $this->post ) && isset( $this->post->ID ) ) {
    233             return get_post_meta( $this->post->ID, 'q_1079059_email' );
     252            return get_post_meta( $this->post->ID, 'Email Address', true );
    234253        }
    235254    }
     
    242261    function get_event_location() {
    243262        if ( isset( $this->post ) && isset( $this->post->ID ) ) {
    244             return get_post_meta( $this->post->ID, 'q_1079103_wordcamp_location' );
     263            return get_post_meta( $this->post->ID, 'Location', true );
    245264        }
    246265    }
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r7853 r8083  
    66
    77require_once WCPT_DIR . 'wcpt-event/class-event-admin.php';
     8require_once WCPT_DIR . 'wcpt-event/notification.php';
    89
    910if ( ! class_exists( 'WordCamp_Admin' ) ) :
     
    708709
    709710        /**
     711         * Send notification to slack when a WordCamp is scheduled or declined. Runs whenever status of an applications changes
     712         *
     713         * @param string  $new_status
     714         * @param string  $old_status
     715         * @param WP_Post $wordcamp
     716         *
     717         * @return null|bool
     718         */
     719        public function notify_application_status_in_slack( $new_status, $old_status, WP_Post $wordcamp ) {
     720
     721            $notification_enabled = apply_filters( 'wordcamp_application_notification_enabled', true );
     722
     723            if ( ! $notification_enabled ) {
     724                return null;
     725            }
     726
     727            if ( 'wcpt-scheduled' === $new_status ) {
     728                return $this->notify_new_wordcamp_in_slack( $wordcamp );
     729            } elseif ( 'wcpt-rejected' === $new_status ) {
     730                $location = get_post_meta( $wordcamp->ID, 'Location', true );
     731                return $this->schedule_decline_notification( $wordcamp, 'WordCamp', $location );
     732            }
     733        }
     734
     735        /**
     736         * Send notification when a new WordCamp comes in scheduled status.
     737         *
     738         * @param WP_Post $wordcamp
     739         *
     740         * @return null|bool
     741         */
     742        public static function notify_new_wordcamp_in_slack( $wordcamp ) {
     743            // Not translating any string because they will be sent to slack.
     744            $city             = get_post_meta( $wordcamp->ID, 'Location', true );
     745            $start_date       = get_post_meta( $wordcamp->ID, 'Start Date (YYYY-mm-dd)', true );
     746            $wordcamp_url     = get_post_meta( $wordcamp->ID, 'URL', true );
     747            $title            = 'New WordCamp scheduled!!!';
     748
     749            $message = sprintf(
     750                "<%s|WordCamp $city> has been scheduled for a start date of %s. :tada: :community: :wordpress:\n\n%s",
     751                $wordcamp_url,
     752                date( 'F j, Y', $start_date ),
     753                $wordcamp_url
     754            );
     755
     756            $attachment = create_event_status_attachment( $message, $wordcamp->ID, $title );
     757
     758            return wcpt_slack_notify( COMMUNITY_EVENTS_SLACK, $attachment );
     759        }
     760
     761        /**
    710762         * Enforce a valid post status for WordCamps.
    711763         *
Note: See TracChangeset for help on using the changeset viewer.