Skip to content

Commit

Permalink
Participation: Add activity when mentor assigned to WordCamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Jun 22, 2022
1 parent a341503 commit 58f9e8d
Showing 1 changed file with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,29 @@ public function username_meta_add( $object_id, $meta_key, $meta_value ) {
* @param mixed $meta_value Metadata value. Serialized if non-scalar.
*/
public function username_meta_update( $meta_id, $object_id, $meta_key, $meta_value ) {
$post = get_post( $object_id );
$prev_value = get_post_meta( $object_id, $meta_key, true );

if ( '_wcpt_user_id' === $meta_key && $meta_value ) {
$post = get_post( $object_id );
if ( 'publish' !== $post->post_status ) {
return;
}

$meta_value = absint( $meta_value );
$prev_value = absint( $prev_value );

$prev_value = absint( get_post_meta( $object_id, $meta_key, true ) );
if ( $prev_value && $prev_value !== $meta_value ) {
$this->maybe_remove_badge( $post, $prev_value );
}

$this->add_activity( $post, $meta_value );
$this->add_badge( $post, $meta_value );
}

if ( 'Mentor WordPress.org User Name' === $meta_key && $meta_value && $prev_value !== $meta_value ) {
// Username has already been validated by `Event_Admin::metabox_save()`.
$this->add_activity( $post, $meta_value, 'mentor_assign' );
}
}

/**
Expand All @@ -161,13 +168,16 @@ public function username_meta_delete( $meta_ids, $object_id, $meta_key ) {
/**
* Makes request to Profile URL to add the speaker or organizer entry to the profile's activity section
*
* @param WP_Post $post Speaker/Organizer Post Object.
* @param int $user_id User ID to add badge for.
* @param WP_Post $post Speaker/Organizer Post Object.
* @param int $user_id User ID to add badge for.
* @param null|string $activity_type The type of activity. Optional for back-compat, but ideally this should
* always be used to avoid ambiguity and assumptions.
*/
protected function add_activity( $post, $user_id ) {
protected function add_activity( $post, $user_id, $activity_type = null ) {
$published_activity_key = $this->get_published_activity_key( $post );

if ( ! get_user_meta( $user_id, $published_activity_key ) ) {
Profiles\api( $this->get_post_activity_payload( $post, $user_id ) );
Profiles\api( $this->get_post_activity_payload( $post, $user_id, $activity_type ) );
update_user_meta( $user_id, $published_activity_key, true );
}
}
Expand Down Expand Up @@ -343,7 +353,7 @@ public function attendee_checked_in( $meta_id, $attendee_id, $meta_key, $meta_va
* @return array|false
*/
protected function get_post_activity_payload( $post, $user_id = null, $activity_type = null ) {
$wordcamp = get_wordcamp_post();
$wordcamp = 'wordcamp' === $post->post_type ? $post : get_wordcamp_post();

if ( ! $user_id ) {
return false;
Expand Down Expand Up @@ -389,6 +399,19 @@ protected function get_post_activity_payload( $post, $user_id = null, $activity_
}
break;

// Unlike the others, this one runs on Central and $wordcamp === $post.
case 'wordcamp':
if ( $post->URL ) {
$activity['url'] = sanitize_url( $post->URL );
} else {
unset( $activity['url'] );
}

$activity['type'] = $activity_type;
$activity['wordcamp_id'] = $post->_site_id;
$activity['wordcamp_name'] = $post->post_title;
break;

default:
$activity = false;
break;
Expand Down

0 comments on commit 58f9e8d

Please sign in to comment.