Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function __construct() {
require_once WP_CONTENT_DIR . '/mu-plugins-private/wporg-mu-plugins/pub/profile-helpers.php';

// Sync with the wp.org username changes.
add_filter( 'update_post_meta', array( $this, 'username_meta_update' ), 10, 4 );
add_filter( 'add_post_meta', array( $this, 'username_meta_add' ), 10, 3 );
add_filter( 'delete_post_meta', array( $this, 'username_meta_delete' ), 10, 3 );
add_filter( 'update_post_meta', array( $this, 'username_meta_update' ), 10, 4 );
add_filter( 'delete_post_meta', array( $this, 'username_meta_delete' ), 10, 3 );
add_action( 'wp_after_insert_post', array( $this, 'maybe_notify_on_post_save' ), 10, 2 );

add_action( 'camptix_rl_buyer_completed_registration', array( $this, 'primary_attendee_registered' ), 10, 2 );
add_action( 'camptix_rl_registration_confirmed', array( $this, 'additional_attendee_confirmed_registration' ), 10, 2 );
Expand Down Expand Up @@ -98,26 +98,7 @@ protected function is_post_notifiable( $post ) {
}

/**
* Add the organizer or speaker badge when the User ID meta is added
*
* @param int $object_id ID of the object metadata is for.
* @param string $meta_key Metadata key.
* @param mixed $meta_value Metadata value. Serialized if non-scalar.
*/
public function username_meta_add( $object_id, $meta_key, $meta_value ) {
if ( '_wcpt_user_id' === $meta_key && $meta_value ) {
$post = get_post( $object_id );
if ( 'publish' !== $post->post_status ) {
return;
}

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

/**
* Maybe add or remove the organizer or speaker badge when the User ID meta is updated
* Remove the old user's badge when a published post's User ID changes, and maybe add mentor activity.
*
* @param int $meta_id ID of the metadata entry to update.
* @param int $object_id ID of the object metadata is for.
Expand All @@ -128,20 +109,13 @@ public function username_meta_update( $meta_id, $object_id, $meta_key, $meta_val
$post = get_post( $object_id );
$prev_value = get_post_meta( $object_id, $meta_key, true );

Comment thread
gedex marked this conversation as resolved.
if ( '_wcpt_user_id' === $meta_key && $meta_value ) {
if ( 'publish' !== $post->post_status ) {
return;
}

$meta_value = absint( $meta_value );
$prev_value = absint( $prev_value );
// The new user gets their badge from maybe_notify_on_post_save(); the old one loses it here.
if ( '_wcpt_user_id' === $meta_key && 'publish' === $post->post_status ) {
$prev_user_id = absint( $prev_value );

if ( $prev_value && $prev_value !== $meta_value ) {
$this->maybe_remove_badge( $post, $prev_value );
if ( $prev_user_id && absint( $meta_value ) !== $prev_user_id ) {
$this->maybe_remove_badge( $post, $prev_user_id );
}

$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 ) {
Expand All @@ -165,6 +139,32 @@ public function username_meta_delete( $meta_ids, $object_id, $meta_key ) {
}
}

/**
* Add the organizer or speaker badge when notifiable post types are saved and User ID meta exists.
*/
public function maybe_notify_on_post_save( int $post_id, WP_Post $post ): void {
if ( wp_is_post_revision( $post ) ) {
return;
}

if ( 'publish' !== get_post_status( $post ) ) {
return;
}

if ( ! $this->is_post_notifiable( $post ) ) {
return;
}

$user_id = get_post_meta( $post_id, '_wcpt_user_id', true );

if ( empty( $user_id ) ) {
return;
}

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

/**
* Makes request to Profile URL to add the speaker or organizer entry to the profile's activity section
*
Expand Down
Loading