Skip to content

Commit

Permalink
Change post_custom_status_changed event to record when a post moves f…
Browse files Browse the repository at this point in the history
…rom a custom status to 'publish'
  • Loading branch information
alecgeatches committed Oct 10, 2024
1 parent 951e254 commit fbfac94
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modules/telemetry/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ public static function init(): void {
*/
public static function record_custom_status_change( string $new_status, string $old_status, WP_Post $post ): void {
if ( ! in_array( $post->post_type, HelperUtilities::get_supported_post_types() ) ) {
// This isn't a supported post type
return;
} elseif ( $old_status === $new_status ) {
// The status hasn't changed
return;
} elseif ( in_array( $new_status, [ 'inherit', 'auto-draft' ] ) ) {
// The status hasn't changed, or it moved into an auto-generated status
return;
}

if ( in_array( $new_status, [ $old_status, 'inherit', 'auto-draft', 'publish' ] ) ) {
$status_slugs = wp_list_pluck( CustomStatus::get_custom_statuses(), 'slug' );

if ( ! in_array( $new_status, $status_slugs, true ) && ! in_array( $old_status, $status_slugs, true ) ) {
// The status isn't moving to or from a custom status
return;
}

Expand Down

0 comments on commit fbfac94

Please sign in to comment.