Changeset 8083
- Timestamp:
- 01/15/2019 09:06:15 AM (6 years ago)
- 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 56 56 add_action( 'transition_post_status', array( $this, 'log_status_changes' ), 10, 3 ); 57 57 58 add_action( 'transition_post_status', array( $this, 'notify_application_status_in_slack' ), 10, 3 ); 59 58 60 add_filter( 'redirect_post_location', array( $this, 'add_admin_notices_to_redirect_url' ), 10, 2 ); 59 61 60 62 // Admin notices 61 63 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 62 67 } 63 68 … … 275 280 add_post_meta( $post->ID, "_status_change_log_$post->post_type $log_id", time() ); 276 281 } 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 ); 277 322 } 278 323 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/class-event-application.php
r7619 r8083 7 7 8 8 namespace WordPress_Community\Applications; 9 require_once WCPT_DIR . 'wcpt-event/notification.php'; 9 10 10 11 /** … … 85 86 public function submit_application() { 86 87 $application_data = $this->validate_data( $_POST ); 88 87 89 if ( $this->is_rate_limited() ) { 88 90 $message = __( 'You have submitted too many applications recently. Please wait and try again in a few hours.', 'wordcamporg' ); … … 93 95 } else { 94 96 $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 96 104 $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' ); 97 105 $notice_classes = 'notice-success'; … … 175 183 176 184 /** 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 /** 177 199 * Display a notice to applicant while submitting the form. 178 200 * … … 192 214 * 193 215 * @param string $email_address 194 * @param string $ meetup_city195 */ 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 ) { 197 219 //translators: Name of the event. Egs WordCamp. 198 220 $subject = sprintf( __( "We've received your %s application", 'wpct' ), $this->get_event_label() ); … … 204 226 'wpct' 205 227 ), 206 $this->get_event_label(), sanitize_text_field( $ meetup_city )228 $this->get_event_label(), sanitize_text_field( $event_city ) 207 229 ); 208 230 209 231 wp_mail( $email_address, $subject, $message, $headers ); 210 232 } 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 } 211 262 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-loader.php
r7607 r8083 51 51 require_once ( WCPT_DIR . 'wcpt-meetup/meetup.php' ); 52 52 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. 53 54 54 55 // Require admin files. -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/class-meetup-admin.php
r7889 r8083 9 9 10 10 require_once WCPT_DIR . 'wcpt-event/class-event-admin.php'; 11 12 if ( ! class_exists( 'MeetupAdmin' ) ) : 11 require_once WCPT_DIR . 'wcpt-event/notification.php'; 12 13 14 if ( ! class_exists( 'Meetup_Admin' ) ) : 13 15 14 16 /** … … 477 479 $this->update_meetup_organizers( $organizers_list, $post ); 478 480 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 ); 479 533 } 480 534 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/class-meetup-application.php
r7887 r8083 271 271 public function get_event_location() { 272 272 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/"; 275 282 } 276 283 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/meetup.php
r7607 r8083 3 3 namespace WordPress_Community\Applications\Meetup; 4 4 5 require_once 'class-meetup-application.php';5 require_once WCPT_DIR . 'wcpt-meetup/class-meetup-application.php'; 6 6 use WordPress_Community\Applications\Meetup_Application; 7 7 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/class-wordcamp-application.php
r7619 r8083 15 15 16 16 static function get_event_label() { 17 __( 'WordCamp', 'wordcamporg' );17 return __( 'WordCamp', 'wordcamporg' ); 18 18 } 19 19 … … 158 158 159 159 /** 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 /** 160 178 * Create a WordCamp post from an application 161 179 * … … 186 204 add_post_meta( $post_id, '_application_data', $data ); 187 205 add_post_meta( $post_id, '_application_submitter_ip_address', $_SERVER['REMOTE_ADDR'] ); 206 188 207 189 208 add_post_meta( … … 231 250 function get_organizer_email() { 232 251 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 ); 234 253 } 235 254 } … … 242 261 function get_event_location() { 243 262 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 ); 245 264 } 246 265 } -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php
r7853 r8083 6 6 7 7 require_once WCPT_DIR . 'wcpt-event/class-event-admin.php'; 8 require_once WCPT_DIR . 'wcpt-event/notification.php'; 8 9 9 10 if ( ! class_exists( 'WordCamp_Admin' ) ) : … … 708 709 709 710 /** 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 /** 710 762 * Enforce a valid post status for WordCamps. 711 763 *
Note: See TracChangeset
for help on using the changeset viewer.