Skip to content

Commit e00000c

Browse files
authored
Merge pull request #39 from ConvertKit/remove-subscriber-array-check-function
Replace `check_if_subscriber_in_array()` function
2 parents 4aff3b7 + cfd5a86 commit e00000c

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

src/ConvertKit_API.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,13 @@ public function get_subscriber_id(string $email_address)
438438
return false;
439439
}
440440

441-
$subscriber_id = $this::check_if_subscriber_in_array($email_address, $subscribers->subscribers);
442-
443-
if ($subscriber_id) {
444-
return $subscriber_id;
441+
if ($subscribers->total_subscribers === 0) {
442+
$this->create_log('No subscribers');
443+
return false;
445444
}
446445

447-
$this->create_log('Subscriber not found');
448-
449-
return false;
446+
// Return the subscriber's ID.
447+
return $subscribers->subscribers[0]->id;
450448
}
451449

452450

@@ -761,26 +759,4 @@ public function make_request(string $endpoint, string $method, array $args = [])
761759
$this->create_log('Failed to finish request.');
762760
return false;
763761
}
764-
765-
766-
/**
767-
* Looks for subscriber with email in array
768-
*
769-
* @param string $email_address Email Address.
770-
* @param array $subscribers Subscribers.
771-
*
772-
* @return false|integer false if not found, else subscriber object
773-
*/
774-
private function check_if_subscriber_in_array(string $email_address, array $subscribers)
775-
{
776-
foreach ($subscribers as $subscriber) {
777-
if ($subscriber->email_address === $email_address) {
778-
$this->create_log('Subscriber found!');
779-
return $subscriber->id;
780-
}
781-
}
782-
783-
$this->create_log('Subscriber not found on current page.');
784-
return false;
785-
}
786762
}

0 commit comments

Comments
 (0)