Making WordPress.org

Changeset 8374


Ignore:
Timestamp:
02/28/2019 03:34:07 PM (7 years ago)
Author:
vedjain
Message:

WCPT: Multiple minor fixes. See description.

  1. Added check while sending declined / scheduled notifications for WordCamp / Meetup, so that we do not send duplicate notifications for same event.
  2. Removed meetup organizer reminder cron because we are not using it anymore. This was already disabled, and this patch just removes dead code from codebase.
  3. Applied code standard and fixes in multiple places.
Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt
Files:
4 edited

Legend:

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

    r8262 r8374  
    259259     * @return string
    260260     */
    261     public function set_locale_to_en_US() {
     261    public function set_locale_to_en_us() {
    262262        return 'en_US';
    263263    }
     
    280280
    281281        // Ensure status labels are in English.
    282         add_filter( 'locale', array( $this, 'set_locale_to_en_US' ) );
     282        add_filter( 'locale', array( $this, 'set_locale_to_en_us' ) );
    283283
    284284        $old_status = get_post_status_object( $old_status );
     
    302302
    303303        // Remove the temporary locale change.
    304         remove_filter( 'locale', array( $this, 'set_locale_to_en_US' ) );
     304        remove_filter( 'locale', array( $this, 'set_locale_to_en_us' ) );
    305305    }
    306306
     
    315315
    316316    /**
    317      * Schedule notificaiton for declined application. Currently supports WordCamp and Meetup
     317     * Schedule notification for declined application. Currently supports WordCamp and Meetup.
    318318     *
    319319     * @param WP_Post $event Event object.
     
    331331     * @param string $label
    332332     * @param string $location
     333     *
     334     * @return null|bool|string
    333335     */
    334336    public static function send_decline_notification( $event_id, $label, $location ) {
     337        $declined_notification_key = 'sent_declined_notification';
     338        if ( get_post_meta( $event_id, $declined_notification_key, true ) ) {
     339            return null;
     340        }
     341
    335342        $message = sprintf(
    336343            'A %s application for %s has been declined, and the applicant has been informed via email.',
     
    340347
    341348        $attachment = create_event_status_attachment( $message, $event_id, '' );
    342         wcpt_slack_notify( COMMUNITY_TEAM_SLACK, $attachment );
     349
     350        $notification_sent = wcpt_slack_notify( COMMUNITY_TEAM_SLACK, $attachment );
     351        if ( $notification_sent ) {
     352            update_post_meta( $event_id, $declined_notification_key, true );
     353        }
     354        return $notification_sent;
    343355    }
    344356
     
    443455
    444456        // Don't add/remove meta on trash, untrash, restore, etc.
     457        // phpcs:ignore WordPress.Security.NonceVerification.Missing
    445458        if ( empty( $_POST['action'] ) || 'editpost' !== $_POST['action'] ) {
    446459            return;
     
    453466            }
    454467        }
    455 
    456468
    457469        $meta_keys = $this->meta_keys();
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-event/class-event-application.php

    r8104 r8374  
    6464        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We do not verify nonce for frontend forms because WP Super Cache may cache an expired nonce token.
    6565        if ( isset( $_POST['submit-application'] ) ) {
     66            // phpcs:ignore WordPress.Security.NonceVerification.Missing
    6667            $this->submit_application( $_POST );
    6768        } else {
     
    237238
    238239    /**
    239      * Notify in community slack channel that we've received an application
     240     * Notify in community slack channel that we've received an application.
    240241     */
    241242    public function notify_new_application_in_slack() {
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-meetup/class-meetup-admin.php

    r8193 r8374  
    511511         * @param WP_Post $meetup Meetup post object.
    512512         *
    513          * @return bool|string
     513         * @return null|bool|string
    514514         */
    515515        public static function notify_new_meetup_group_in_slack( $meetup ) {
    516 
     516            $new_group_notification_key = 'sent_new_group_notification';
     517            if ( get_post_meta( $meetup->ID, $new_group_notification_key, true ) ) {
     518                return null;
     519            }
    517520            // Not translating strings here because these will be sent to Slack.
    518521            $city            = get_post_meta( $meetup->ID, 'Meetup Location', true );
     
    523526            $message = sprintf(
    524527                "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" : "",
     528                empty( $city ) ? '' : " in $city,",
     529                empty( $organizer_slack ) ? '' : " organized by @$organizer_slack",
    527530                $meetup_link
    528531            );
     
    530533            $attachment = create_event_status_attachment( $message, $meetup->ID, $title );
    531534
    532             return wcpt_slack_notify( COMMUNITY_EVENTS_SLACK, $attachment );
     535            $notification_sent = wcpt_slack_notify( COMMUNITY_EVENTS_SLACK, $attachment );
     536            if ( $notification_sent ) {
     537                update_post_meta( $meetup->ID, $new_group_notification_key, true );
     538            }
     539            return $notification_sent;
    533540        }
    534541
     
    783790                }
    784791            }
    785             // Disabling the new organizer notification because its a lot of work, and not always possible to find someone's wporg username from their meetup profile
    786             // self::new_meetup_organizers_notify( $new_meetup_org_data );
    787         }
    788 
    789         /**
    790          * Send email containing new meetup organizers to WordCamp Support team. Also adds a tag - `Needs to update Organizer list`
    791          *
    792          * @param array $new_meetup_org_data
    793          */
    794         public static function new_meetup_organizers_notify( $new_meetup_org_data ) {
    795             if ( empty( $new_meetup_org_data ) ) {
    796                 return;
    797             }
    798 
    799             $template = <<<HTML
    800 Hi,
    801 <br><br>
    802 New organizers have been added for following meetups. Please update their wporg usernames in their meetup tracker page.
    803 <br><br>
    804 HTML;
    805             $count = 0;
    806             foreach ( $new_meetup_org_data as $post_id => $new_meetup_org ) {
    807                 $count ++;
    808                 $title = get_the_title( $post_id );
    809                 $meetup_tracker_url = get_site_url() . "/wp-admin/post.php?post=$post_id&action=edit";
    810                 $template = $template . "$count. <a href='$meetup_tracker_url' rel='noreferrer' target='_blank' >$title</a> : ";
    811                 $meetup_group_url = get_post_meta( $post_id, 'Meetup URL', true );
    812                 $meetup_members = array();
    813                 foreach ( $new_meetup_org as $organizer ) {
    814                     $organizer_id = esc_html( $organizer['id'] );
    815                     $organizer_name = esc_html( $organizer['name'] );
    816                     $meetup_members[] = "<a href='$meetup_group_url/members/$organizer_id' target='_blank' rel='noreferrer' >$organizer_name</a>";
    817                 }
    818                 $template = $template . join( ', ', $meetup_members ) . '<br>';
    819 
    820                 // Add a tag for meetup.
    821                 wp_set_object_terms( $post_id, 'Needs to update Organizer list', 'meetup_tags', true );
    822             }
    823             wp_mail(
    824                 array( 'support@wordcamp.org' ),
    825                 'New Meetup organizer added',
    826                 $template,
    827                 array(
    828                     'From:         noreply@wordcamp.org',
    829                     'Content-Type: text/html; charset=UTF-8',
    830                 )
    831             );
    832         }
     792        }
     793
    833794    }
    834795
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r8328 r8374  
    744744         * @param WP_Post $wordcamp
    745745         *
    746          * @return null|bool
     746         * @return null|bool|string
    747747         */
    748748        public static function notify_new_wordcamp_in_slack( $wordcamp ) {
     749            $scheduled_notification_key = 'sent_scheduled_notification';
     750            if ( get_post_meta( $wordcamp->ID, $scheduled_notification_key, true ) ) {
     751                return null;
     752            }
     753
    749754            // Not translating any string because they will be sent to slack.
    750755            $city             = get_post_meta( $wordcamp->ID, 'Location', true );
     
    762767            $attachment = create_event_status_attachment( $message, $wordcamp->ID, $title );
    763768
    764             return wcpt_slack_notify( COMMUNITY_EVENTS_SLACK, $attachment );
     769            $notification_sent = wcpt_slack_notify( COMMUNITY_EVENTS_SLACK, $attachment );
     770            if ( $notification_sent ) {
     771                update_post_meta( $wordcamp->ID, $scheduled_notification_key, true );
     772            }
     773            return $notification_sent;
    765774        }
    766775
Note: See TracChangeset for help on using the changeset viewer.