DRY duplicate code

This commit is contained in:
Jeremy Dormitzer 2018-09-13 19:52:13 -06:00
parent 3e34f4743b
commit aa3af478c6
3 changed files with 14 additions and 17 deletions

View File

@ -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(

View File

@ -1,6 +1,8 @@
<?php
namespace deliver;
require_once plugin_dir_path( __FILE__ ) . 'activities.php';
function deliver_activity( $activity ) {
$recipients = array();
for ( $field as array( 'to', 'bto', 'cc', 'bcc', 'audience' ) ) {
@ -12,7 +14,7 @@ function deliver_activity( $activity ) {
if ( array_key_exists( 'actor', $activity ) ) {
$recipients = remove_actor_inbox_from_recipients( $activity['actor'], $recipients );
}
$activity = strip_private_fields( $activity );
$activity = \activities\strip_private_fields( $activity );
post_activity_to_inboxes( $activity, $recipients );
}
@ -84,14 +86,4 @@ function post_activity_to_inboxes( $activity, $recipients ) {
wp_remote_post( $inbox, $args );
}
}
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;
}
?>

View File

@ -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;
}