Skip to content

Commit

Permalink
Change custom_status_changed event to not fire for reorders
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgeatches committed Oct 10, 2024
1 parent 9178ddd commit 951e254
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 5 additions & 7 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,19 +656,17 @@ public static function update_custom_status( int $status_id, array $args = [] ):
return $updated_term;
}

$slug = isset( $args['slug'] ) ? $args['slug'] : $old_status->slug;
$updated_status = self::get_custom_status_by( 'id', $status_id );

/**
* Fires after a custom status is updated in the database.
*
* @param int $term_id The ID of the status being updated
* @param string $slug The slug of the status being updated
* @param WP_Term $updated_status The updated status WP_Term object.
* @param array $update_args The arguments used to update the status.
*/
do_action( 'vw_update_custom_status', $status_id, $slug );
do_action( 'vw_update_custom_status', $updated_status, $args );

$status_result = self::get_custom_status_by( 'id', $status_id );

return $status_result;
return $updated_status;
}

/**
Expand Down
18 changes: 13 additions & 5 deletions modules/telemetry/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use VIPWorkflow\Modules\CustomStatus;
use VIPWorkflow\Modules\Shared\PHP\HelperUtilities;
use WP_Post;
use WP_Term;

class Telemetry {
/**
Expand Down Expand Up @@ -92,13 +93,20 @@ public static function record_delete_custom_status( int $term_id, string $slug )
/**
* Record an event when a custom status is updated
*
* @param int $term_id The custom status term ID
* @param string $slug The status slug
* @param WP_Term $updated_status The updated status WP_Term object.
* @param array $update_args The arguments used to update the status.
*/
public static function record_update_custom_status( int $status_id, string $slug ): void {
public static function record_update_custom_status( WP_Term $updated_status, array $update_args ): void {
$is_position_update = 1 === count( $update_args ) && isset( $update_args['position'] );
if ( $is_position_update ) {
// Ignore position changes, as they fire for every custom status when statuses are reordered
return;
}

self::$tracks->record_event( 'custom_status_changed', [
'status_id' => $status_id,
'slug' => $slug,
'term_id' => $updated_status->term_id,
'name' => $updated_status->name,
'slug' => $updated_status->slug,
] );
}

Expand Down

0 comments on commit 951e254

Please sign in to comment.