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-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.