Making WordPress.org


Ignore:
Timestamp:
07/29/2016 07:34:51 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Participation Notifier: Strip trailing whitespace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php

    r2743 r3750  
    3333         *       hook when they're ready to send the notification, rather than this plugin having to be aware of (and
    3434         *       coupled to) the internal logic of those plugins.
    35          * 
     35         *
    3636         * @param string  $new_status
    3737         * @param string  $old_status
     
    7474         * Updates the activity and associations of a profile when the WordPress.org username on a published speaker
    7575         * or organizer post changes.
    76          * 
    77          * @todo The handler doesn't support removing activity, but maybe do that here if support is added.
    78          * 
     76         *
     77         * @todo The handler doesn't support removing activity, but maybe do that here if support is added.
     78         *
    7979         * @param WP_Post $post
    8080         */
     
    8787                        return;
    8888                }
    89                
     89
     90                // todo change this to use an if/elseif/elseif structure, just to be safe
     91
    9092                // A new username was added, so add the activity and association.
    9193                if ( $new_user_id && ! $previous_user_id ) {
     
    9395                        $this->remote_post( self::PROFILES_HANDLER_URL, $this->get_post_association_payload( $post, 'add' ) );
    9496                }
    95                
     97
    9698                // The username was removed, so remove the association.
    9799                if ( ! $new_user_id && $previous_user_id ) {
     
    124126                        // Get the $user_id from post meta instead of $_POST in case it changed during the unpublish update.
    125127                        // This makes sure that the association is removed from the same user that it was originally added to.
    126                        
     128
    127129                        $user_id = $this->get_saved_wporg_user_id( $post );
    128130                        $this->remote_post( self::PROFILES_HANDLER_URL, $this->get_post_association_payload( $post, 'remove', $user_id ) );
     
    188190        /**
    189191         * Builds the payload for an activity notification based on a new post
    190          * 
     192         *
    191193         * @param WP_Post $post
    192194         * @param int     $user_id
     
    211213                                'wordcamp_id'   => get_current_blog_id(),
    212214                                'wordcamp_name' => get_wordcamp_name(),
    213                                 'wordcamp_date' => empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ? false : date( 'F jS', $wordcamp->meta['Start Date (YYYY-mm-dd)' ][0] ), 
     215                                'wordcamp_date' => empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ? false : date( 'F jS', $wordcamp->meta['Start Date (YYYY-mm-dd)' ][0] ),
    214216                                'url'           => site_url(),
    215217                        );
    216        
     218
    217219                        switch( $post->post_type ) {
    218220                                case 'wcb_speaker':
    219221                                        $activity['speaker_id']   = $post->ID;
    220222                                break;
    221        
     223
    222224                                case 'wcb_organizer':
    223225                                        $activity['organizer_id'] = $post->ID;
     
    243245                                        }
    244246                                break;
    245        
     247
    246248                                default:
    247249                                        $activity = false;
     
    255257        /**
    256258         * Build the payload for an association notification based on a new or updated post
    257          * 
     259         *
    258260         * @param WP_Post $post
    259261         * @param string  $command 'add' | 'remove'
     
    263265        protected function get_post_association_payload( $post, $command, $user_id = null ) {
    264266                $association = false;
    265                
     267
    266268                if ( ! $user_id ) {
    267269                        $user_id = $this->get_new_wporg_user_id( $post );
     
    278280                                'url'           => site_url(),
    279281                        );
    280                        
     282
    281283                        switch( $post->post_type ) {
    282284                                case 'wcb_speaker':
    283285                                        $association['association'] = 'wordcamp-speaker';
    284286                                break;
    285        
     287
    286288                                case 'wcb_organizer':
    287289                                        $association['association'] = 'wordcamp-organizer';
     
    297299                return apply_filters( 'wpn_post_association_payload', $association, $post, $command, $user_id );
    298300        }
    299        
     301
    300302        /**
    301303         * Get the current WordPress.org user_id associated with a custom post
     
    303305         * This is called during the context of a post being updated, so the new username is the one submitted in
    304306         * the $_POST request, or the currently logged in user, as opposed to the user_id saved in the database.
    305          * 
     307         *
    306308         * @param WP_Post $post
    307309         * @return false|int
     
    350352         *
    351353         * This reduces the amount of duplicated code in the callers, makes them more readable, and logs errors to aid in debugging
    352          * 
     354         *
    353355         * @param string $url
    354356         * @param array  $body The value intended to be passed to wp_remote_post() as $args['body']
     
    360362                if ( $body ) {
    361363                        $response = wp_remote_post( $url, array( 'body' => $body ) );
    362                
     364
    363365                        if ( is_wp_error( $response ) ) {
    364366                                $error = sprintf(
     
    369371                        } elseif ( 200 != $response['response']['code'] || 1 != (int) $response['body'] ) {
    370372                                // error_log() has a message limit of 1024 bytes, so we truncate $response['body'] to make sure that $body doesn't get truncated.
    371                                
     373
    372374                                $error = sprintf(
    373375                                        'Received HTTP code: %s and body: %s. Request was: %s',
     
    377379                                );
    378380                        }
    379                        
     381
    380382                        if ( $error ) {
    381383                                error_log( sprintf( '%s error for %s: %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ), sanitize_text_field( $error ) ) );
    382                                
     384
    383385                                if ( $to = apply_filters( 'wpn_error_email_addresses', array() ) ) {
    384386                                        wp_mail( $to, sprintf( '%s error for %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ) ), sanitize_text_field( $error ) );
     
    386388                        }
    387389                }
    388                
     390
    389391                return $response;
    390392        }
Note: See TracChangeset for help on using the changeset viewer.