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-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
Note: See TracChangeset for help on using the changeset viewer.