Changeset 3750
- Timestamp:
- 07/29/2016 07:34:51 PM (9 years ago)
- 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 33 33 * hook when they're ready to send the notification, rather than this plugin having to be aware of (and 34 34 * coupled to) the internal logic of those plugins. 35 * 35 * 36 36 * @param string $new_status 37 37 * @param string $old_status … … 74 74 * Updates the activity and associations of a profile when the WordPress.org username on a published speaker 75 75 * 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 * 79 79 * @param WP_Post $post 80 80 */ … … 87 87 return; 88 88 } 89 89 90 // todo change this to use an if/elseif/elseif structure, just to be safe 91 90 92 // A new username was added, so add the activity and association. 91 93 if ( $new_user_id && ! $previous_user_id ) { … … 93 95 $this->remote_post( self::PROFILES_HANDLER_URL, $this->get_post_association_payload( $post, 'add' ) ); 94 96 } 95 97 96 98 // The username was removed, so remove the association. 97 99 if ( ! $new_user_id && $previous_user_id ) { … … 124 126 // Get the $user_id from post meta instead of $_POST in case it changed during the unpublish update. 125 127 // This makes sure that the association is removed from the same user that it was originally added to. 126 128 127 129 $user_id = $this->get_saved_wporg_user_id( $post ); 128 130 $this->remote_post( self::PROFILES_HANDLER_URL, $this->get_post_association_payload( $post, 'remove', $user_id ) ); … … 188 190 /** 189 191 * Builds the payload for an activity notification based on a new post 190 * 192 * 191 193 * @param WP_Post $post 192 194 * @param int $user_id … … 211 213 'wordcamp_id' => get_current_blog_id(), 212 214 '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] ), 214 216 'url' => site_url(), 215 217 ); 216 218 217 219 switch( $post->post_type ) { 218 220 case 'wcb_speaker': 219 221 $activity['speaker_id'] = $post->ID; 220 222 break; 221 223 222 224 case 'wcb_organizer': 223 225 $activity['organizer_id'] = $post->ID; … … 243 245 } 244 246 break; 245 247 246 248 default: 247 249 $activity = false; … … 255 257 /** 256 258 * Build the payload for an association notification based on a new or updated post 257 * 259 * 258 260 * @param WP_Post $post 259 261 * @param string $command 'add' | 'remove' … … 263 265 protected function get_post_association_payload( $post, $command, $user_id = null ) { 264 266 $association = false; 265 267 266 268 if ( ! $user_id ) { 267 269 $user_id = $this->get_new_wporg_user_id( $post ); … … 278 280 'url' => site_url(), 279 281 ); 280 282 281 283 switch( $post->post_type ) { 282 284 case 'wcb_speaker': 283 285 $association['association'] = 'wordcamp-speaker'; 284 286 break; 285 287 286 288 case 'wcb_organizer': 287 289 $association['association'] = 'wordcamp-organizer'; … … 297 299 return apply_filters( 'wpn_post_association_payload', $association, $post, $command, $user_id ); 298 300 } 299 301 300 302 /** 301 303 * Get the current WordPress.org user_id associated with a custom post … … 303 305 * This is called during the context of a post being updated, so the new username is the one submitted in 304 306 * the $_POST request, or the currently logged in user, as opposed to the user_id saved in the database. 305 * 307 * 306 308 * @param WP_Post $post 307 309 * @return false|int … … 350 352 * 351 353 * This reduces the amount of duplicated code in the callers, makes them more readable, and logs errors to aid in debugging 352 * 354 * 353 355 * @param string $url 354 356 * @param array $body The value intended to be passed to wp_remote_post() as $args['body'] … … 360 362 if ( $body ) { 361 363 $response = wp_remote_post( $url, array( 'body' => $body ) ); 362 364 363 365 if ( is_wp_error( $response ) ) { 364 366 $error = sprintf( … … 369 371 } elseif ( 200 != $response['response']['code'] || 1 != (int) $response['body'] ) { 370 372 // 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 372 374 $error = sprintf( 373 375 'Received HTTP code: %s and body: %s. Request was: %s', … … 377 379 ); 378 380 } 379 381 380 382 if ( $error ) { 381 383 error_log( sprintf( '%s error for %s: %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ), sanitize_text_field( $error ) ) ); 382 384 383 385 if ( $to = apply_filters( 'wpn_error_email_addresses', array() ) ) { 384 386 wp_mail( $to, sprintf( '%s error for %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ) ), sanitize_text_field( $error ) ); … … 386 388 } 387 389 } 388 390 389 391 return $response; 390 392 }
Note: See TracChangeset
for help on using the changeset viewer.