Making WordPress.org


Ignore:
Timestamp:
01/15/2019 09:06:15 AM (7 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-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
Note: See TracChangeset for help on using the changeset viewer.