From aa3af478c617ce80947ec77bdd6fa0ebb47cdb0b Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 13 Sep 2018 19:52:13 -0600 Subject: [PATCH] DRY duplicate code --- inc/activities.php | 10 ++++++++++ inc/deliver.php | 14 +++----------- inc/outbox.php | 7 +------ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/inc/activities.php b/inc/activities.php index 7eb0dc4..c6177b2 100644 --- a/inc/activities.php +++ b/inc/activities.php @@ -16,6 +16,16 @@ function get_activity( $id ) { return $activity; } +function strip_private_fields( $activity ) { + if ( array_key_exists( 'bto', $activity ) ) { + unset( $activity['bto'] ); + } + if ( array_key_exists( 'bcc', $activity ) ) { + unset( $activity['bcc'] ); + } + return $activity; +} + function persist_activity( $activity ) { global $wpdb; $wpdb->insert( diff --git a/inc/deliver.php b/inc/deliver.php index e1e64b5..5a31ed3 100644 --- a/inc/deliver.php +++ b/inc/deliver.php @@ -1,6 +1,8 @@ diff --git a/inc/outbox.php b/inc/outbox.php index a9b66b2..7bf600c 100644 --- a/inc/outbox.php +++ b/inc/outbox.php @@ -88,12 +88,7 @@ function handle_activity( $actor, $activity ) { function deliver_activity( $activity ) { \deliver\deliver_activity( $activity ); - if ( array_key_exists( 'bto', $activity ) ) { - unset( $activity['bto'] ); - } - if ( array_key_exists( 'bcc', $activity ) ) { - unset( $activity['bcc'] ); - } + $activity = \activities\strip_private_fields( $activity ); return $activity; }