From e9b74c992eae7e4ffc91b986bfb397a56068f62f Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 17 Dec 2024 16:52:57 +0000 Subject: [PATCH 1/5] Add `referrer` support to `add_subscriber_to_form` and `add_subscriber_to_form_by_email` --- src/class-convertkit-api-traits.php | 197 +++++++++++++++---------- tests/wpunit/APITest.php | 220 ++++++++++++++++++++++++++++ 2 files changed, 343 insertions(+), 74 deletions(-) diff --git a/src/class-convertkit-api-traits.php b/src/class-convertkit-api-traits.php index 9c3fe8a..22ddc15 100644 --- a/src/class-convertkit-api-traits.php +++ b/src/class-convertkit-api-traits.php @@ -65,7 +65,7 @@ trait ConvertKit_API_Traits * * @see https://developers.kit.com/v4.html#get-current-account * - * @return WP_Error|array + * @return false|mixed */ public function get_account() { @@ -77,7 +77,7 @@ public function get_account() * * @see https://developers.kit.com/v4.html#list-colors * - * @return WP_Error|array + * @return false|mixed */ public function get_account_colors() { @@ -91,7 +91,7 @@ public function get_account_colors() * * @see https://developers.kit.com/v4.html#list-colors * - * @return WP_Error|array + * @return false|mixed */ public function update_account_colors(array $colors) { @@ -106,7 +106,7 @@ public function update_account_colors(array $colors) * * @see https://developers.kit.com/v4.html#get-creator-profile * - * @return WP_Error|array + * @return false|mixed */ public function get_creator_profile() { @@ -118,7 +118,7 @@ public function get_creator_profile() * * @see https://developers.kit.com/v4.html#get-email-stats * - * @return WP_Error|array + * @return false|mixed */ public function get_email_stats() { @@ -133,7 +133,7 @@ public function get_email_stats() * * @see https://developers.kit.com/v4.html#get-growth-stats * - * @return WP_Error|array + * @return false|mixed */ public function get_growth_stats(\DateTime $starting = null, \DateTime $ending = null) { @@ -159,7 +159,7 @@ public function get_growth_stats(\DateTime $starting = null, \DateTime $ending = * * @see https://developers.kit.com/v4.html#convertkit-api-forms * - * @return WP_Error|array + * @return mixed|array */ public function get_forms( string $status = 'active', @@ -196,7 +196,7 @@ public function get_forms( * * @see https://developers.kit.com/v4.html#convertkit-api-forms * - * @return WP_Error|array + * @return mixed|array */ public function get_landing_pages( string $status = 'active', @@ -220,21 +220,57 @@ public function get_landing_pages( ); } + /** + * Adds subscribers to forms in bulk. + * + * @param array> $forms_subscribers_ids Array of arrays comprising of `form_id`, `subscriber_id` and optional `referrer` URL. + * @param string $callback_url URL to notify for large batch size when async processing complete. + * + * @since 2.1.0 + * + * @see https://developers.kit.com/v4.html#bulk-add-subscribers-to-forms + * + * @return false|object + */ + public function add_subscribers_to_forms(array $forms_subscribers_ids, string $callback_url = '') + { + // Build parameters. + $options = ['additions' => $forms_subscribers_ids]; + if (!empty($callback_url)) { + $options['callback_url'] = $callback_url; + } + + // Send request. + return $this->post( + 'bulk/forms/subscribers', + $options + ); + } + /** * Adds a subscriber to a form by email address * * @param integer $form_id Form ID. * @param string $email_address Email Address. + * @param string $referrer Referrer. * * @see https://developers.kit.com/v4.html#add-subscriber-to-form-by-email-address * - * @return WP_Error|array + * @return false|mixed */ - public function add_subscriber_to_form_by_email(int $form_id, string $email_address) + public function add_subscriber_to_form_by_email(int $form_id, string $email_address, string $referrer = '') { + // Build parameters. + $options = ['email_address' => $email_address]; + + if (!empty($referrer)) { + $options['referrer'] = $referrer; + } + + // Send request. return $this->post( sprintf('forms/%s/subscribers', $form_id), - ['email_address' => $email_address] + $options ); } @@ -243,31 +279,28 @@ public function add_subscriber_to_form_by_email(int $form_id, string $email_addr * * @param integer $form_id Form ID. * @param integer $subscriber_id Subscriber ID. + * @param string $referrer Referrer URL. * * @see https://developers.kit.com/v4.html#add-subscriber-to-form * * @since 2.0.0 * - * @return WP_Error|array + * @return false|mixed */ - public function add_subscriber_to_form(int $form_id, int $subscriber_id) + public function add_subscriber_to_form(int $form_id, int $subscriber_id, string $referrer = '') { - return $this->post(sprintf('forms/%s/subscribers/%s', $form_id, $subscriber_id)); - } + // Build parameters. + $options = []; - /** - * Adds a subscriber to a legacy form by subscriber ID - * - * @param integer $form_id Legacy Form ID. - * @param integer $subscriber_id Subscriber ID. - * - * @since 2.0.0 - * - * @return WP_Error|array - */ - public function add_subscriber_to_legacy_form(int $form_id, int $subscriber_id) - { - return $this->post(sprintf('landing_pages/%s/subscribers/%s', $form_id, $subscriber_id)); + if (!empty($referrer)) { + $options['referrer'] = $referrer; + } + + // Send request. + return $this->post( + sprintf('forms/%s/subscribers/%s', $form_id, $subscriber_id), + $options + ); } /** @@ -286,7 +319,7 @@ public function add_subscriber_to_legacy_form(int $form_id, int $subscriber_id) * * @see https://developers.kit.com/v4.html#list-subscribers-for-a-form * - * @return WP_Error|array + * @return false|mixed */ public function get_form_subscriptions( int $form_id, @@ -342,7 +375,7 @@ public function get_form_subscriptions( * * @see https://developers.kit.com/v4.html#list-sequences * - * @return WP_Error|array + * @return false|mixed */ public function get_sequences( bool $include_total_count = false, @@ -370,7 +403,7 @@ public function get_sequences( * * @see https://developers.kit.com/v4.html#add-subscriber-to-sequence-by-email-address * - * @return WP_Error|array + * @return false|mixed */ public function add_subscriber_to_sequence_by_email(int $sequence_id, string $email_address) { @@ -390,7 +423,7 @@ public function add_subscriber_to_sequence_by_email(int $sequence_id, string $em * * @since 2.0.0 * - * @return WP_Error|array + * @return false|mixed */ public function add_subscriber_to_sequence(int $sequence_id, int $subscriber_id) { @@ -413,7 +446,7 @@ public function add_subscriber_to_sequence(int $sequence_id, int $subscriber_id) * * @see https://developers.kit.com/v4.html#list-subscribers-for-a-sequence * - * @return WP_Error|array + * @return false|mixed */ public function get_sequence_subscriptions( int $sequence_id, @@ -469,7 +502,7 @@ public function get_sequence_subscriptions( * * @see https://developers.kit.com/v4.html#list-tags * - * @return WP_Error|array + * @return mixed|array */ public function get_tags( bool $include_total_count = false, @@ -498,7 +531,7 @@ public function get_tags( * * @see https://developers.kit.com/v4.html#create-a-tag * - * @return WP_Error|array + * @return false|mixed */ public function create_tag(string $tag) { @@ -518,7 +551,7 @@ public function create_tag(string $tag) * * @see https://developers.kit.com/v4.html#bulk-create-tags * - * @return WP_Error|array + * @return false|mixed */ public function create_tags(array $tags, string $callback_url = '') { @@ -551,7 +584,7 @@ public function create_tags(array $tags, string $callback_url = '') * * @see https://developers.kit.com/v4.html#tag-a-subscriber-by-email-address * - * @return WP_Error|array + * @return false|mixed */ public function tag_subscriber_by_email(int $tag_id, string $email_address) { @@ -569,7 +602,7 @@ public function tag_subscriber_by_email(int $tag_id, string $email_address) * * @see https://developers.kit.com/v4.html#tag-a-subscriber * - * @return WP_Error|array + * @return false|mixed */ public function tag_subscriber(int $tag_id, int $subscriber_id) { @@ -586,7 +619,7 @@ public function tag_subscriber(int $tag_id, int $subscriber_id) * * @see https://developers.kit.com/v4.html#remove-tag-from-subscriber * - * @return WP_Error|array + * @return false|mixed */ public function remove_tag_from_subscriber(int $tag_id, int $subscriber_id) { @@ -603,7 +636,7 @@ public function remove_tag_from_subscriber(int $tag_id, int $subscriber_id) * * @see https://developers.kit.com/v4.html#remove-tag-from-subscriber-by-email-address * - * @return WP_Error|array + * @return false|mixed */ public function remove_tag_from_subscriber_by_email(int $tag_id, string $email_address) { @@ -629,7 +662,7 @@ public function remove_tag_from_subscriber_by_email(int $tag_id, string $email_a * * @see https://developers.kit.com/v4.html#list-subscribers-for-a-tag * - * @return WP_Error|array + * @return false|mixed */ public function get_tag_subscriptions( int $tag_id, @@ -687,7 +720,7 @@ public function get_tag_subscriptions( * * @see https://developers.kit.com/v4.html#convertkit-api-email-templates * - * @return WP_Error|array + * @return false|mixed */ public function get_email_templates( bool $include_total_count = false, @@ -728,7 +761,7 @@ public function get_email_templates( * * @see https://developers.kit.com/v4.html#list-subscribers * - * @return WP_Error|array + * @return false|mixed */ public function get_subscribers( string $subscriber_state = 'active', @@ -867,7 +900,7 @@ public function create_subscribers(array $subscribers, string $callback_url = '' * * @see https://developers.kit.com/v4.html#get-a-subscriber * - * @return bool|WP_Error|integer + * @return false|integer */ public function get_subscriber_id(string $email_address) { @@ -876,12 +909,28 @@ public function get_subscriber_id(string $email_address) ['email_address' => $email_address] ); - if (!count($subscribers->subscribers)) { + if (!is_array($subscribers)) { + return false; + } + + if (!is_array($subscribers['subscribers'])) { + return false; + } + + if (!count($subscribers['subscribers'])) { + return false; + } + + if (!is_array($subscribers->subscribers[0])) { + return false; + } + + if (!is_int($subscribers->subscribers[0]['id'])) { return false; } // Return the subscriber's ID. - return $subscribers->subscribers[0]->id; + return $subscribers->subscribers[0]['id']; } /** @@ -891,7 +940,7 @@ public function get_subscriber_id(string $email_address) * * @see https://developers.kit.com/v4.html#get-a-subscriber * - * @return bool|WP_Error|array + * @return mixed|integer */ public function get_subscriber(int $subscriber_id) { @@ -908,7 +957,7 @@ public function get_subscriber(int $subscriber_id) * * @see https://developers.kit.com/v4.html#update-a-subscriber * - * @return WP_Error|array + * @return mixed */ public function update_subscriber( int $subscriber_id, @@ -943,7 +992,7 @@ public function update_subscriber( * * @see https://developers.kit.com/v4.html#unsubscribe-subscriber * - * @return bool|WP_Error|array + * @return mixed|object */ public function unsubscribe_by_email(string $email_address) { @@ -962,7 +1011,7 @@ public function unsubscribe_by_email(string $email_address) * * @see https://developers.kit.com/v4.html#unsubscribe-subscriber * - * @return bool|WP_Error|array + * @return mixed|object */ public function unsubscribe(int $subscriber_id) { @@ -980,7 +1029,7 @@ public function unsubscribe(int $subscriber_id) * * @see https://developers.kit.com/v4.html#list-tags-for-a-subscriber * - * @return WP_Error|array + * @return mixed|array */ public function get_subscriber_tags( int $subscriber_id, @@ -1011,7 +1060,7 @@ public function get_subscriber_tags( * * @see https://developers.kit.com/v4.html#list-broadcasts * - * @return WP_Error|array + * @return false|mixed */ public function get_broadcasts( bool $include_total_count = false, @@ -1057,7 +1106,7 @@ public function get_broadcasts( * * @see https://developers.kit.com/v4.html#create-a-broadcast * - * @return bool|WP_Error|array + * @return mixed|object */ public function create_broadcast( string $subject = '', @@ -1116,7 +1165,7 @@ public function create_broadcast( * * @see https://developers.kit.com/v4.html#get-a-broadcast * - * @return bool|WP_Error|array + * @return mixed|object */ public function get_broadcast(int $id) { @@ -1131,7 +1180,7 @@ public function get_broadcast(int $id) * * @see https://developers.kit.com/v4.html#get-stats * - * @return bool|WP_Error|array + * @return mixed|object */ public function get_broadcast_stats(int $id) { @@ -1164,7 +1213,7 @@ public function get_broadcast_stats(int $id) * * @see https://developers.kit.com/#create-a-broadcast * - * @return bool|WP_Error|array + * @return mixed|object */ public function update_broadcast( int $id, @@ -1226,7 +1275,7 @@ public function update_broadcast( * * @see https://developers.kit.com/v4.html#delete-a-broadcast * - * @return bool|WP_Error|array + * @return mixed|object */ public function delete_broadcast(int $id) { @@ -1245,7 +1294,7 @@ public function delete_broadcast(int $id) * * @see https://developers.kit.com/v4.html#list-webhooks * - * @return WP_Error|array + * @return false|mixed */ public function get_webhooks( bool $include_total_count = false, @@ -1279,7 +1328,7 @@ public function get_webhooks( * * @throws \InvalidArgumentException If the event is not supported. * - * @return bool|WP_Error|array + * @return mixed|object */ public function create_webhook(string $url, string $event, string $parameter = '') { @@ -1353,7 +1402,7 @@ public function create_webhook(string $url, string $event, string $parameter = ' * * @see https://developers.kit.com/v4.html#delete-a-webhook * - * @return bool|WP_Error|array + * @return mixed|object */ public function delete_webhook(int $id) { @@ -1372,7 +1421,7 @@ public function delete_webhook(int $id) * * @see https://developers.kit.com/v4.html#list-custom-fields * - * @return WP_Error|array + * @return false|mixed */ public function get_custom_fields( bool $include_total_count = false, @@ -1402,7 +1451,7 @@ public function get_custom_fields( * * @see https://developers.kit.com/v4.html#create-a-custom-field * - * @return bool|WP_Error|array + * @return mixed|object */ public function create_custom_field(string $label) { @@ -1422,7 +1471,7 @@ public function create_custom_field(string $label) * * @see https://developers.kit.com/v4.html#bulk-create-custom-fields * - * @return bool|WP_Error|array + * @return mixed|object */ public function create_custom_fields(array $labels, string $callback_url = '') { @@ -1457,7 +1506,7 @@ public function create_custom_fields(array $labels, string $callback_url = '') * * @see https://developers.kit.com/v4.html#update-a-custom-field * - * @return bool|WP_Error|array + * @return mixed|object */ public function update_custom_field(int $id, string $label) { @@ -1476,7 +1525,7 @@ public function update_custom_field(int $id, string $label) * * @see https://developers.kit.com/#destroy-field * - * @return bool|WP_Error|array + * @return mixed|object */ public function delete_custom_field(int $id) { @@ -1495,7 +1544,7 @@ public function delete_custom_field(int $id) * * @see https://developers.kit.com/v4.html#list-purchases * - * @return WP_Error|array + * @return false|mixed */ public function get_purchases( bool $include_total_count = false, @@ -1523,7 +1572,7 @@ public function get_purchases( * * @see https://developers.kit.com/v4.html#get-a-purchase * - * @return bool|WP_Error|array + * @return mixed|object */ public function get_purchase(int $purchase_id) { @@ -1548,7 +1597,7 @@ public function get_purchase(int $purchase_id) * * @see https://developers.kit.com/v4.html#create-a-purchase * - * @return bool|WP_Error|array + * @return mixed|object */ public function create_purchase( string $email_address, @@ -1610,7 +1659,7 @@ public function create_purchase( * * @see https://developers.kit.com/v4.html#convertkit-api-segments * - * @return WP_Error|array + * @return false|mixed */ public function get_segments( bool $include_total_count = false, @@ -1760,7 +1809,7 @@ private function build_total_count_and_pagination_params( * @param string $endpoint API Endpoint. * @param array|string> $args Request arguments. * - * @return WP_Error|array + * @return false|mixed */ public function get(string $endpoint, array $args = []) { @@ -1773,7 +1822,7 @@ public function get(string $endpoint, array $args = []) * @param string $endpoint API Endpoint. * @param array>> $args Request arguments. * - * @return WP_Error|array + * @return false|mixed */ public function post(string $endpoint, array $args = []) { @@ -1786,7 +1835,7 @@ public function post(string $endpoint, array $args = []) * @param string $endpoint API Endpoint. * @param array|string> $args Request arguments. * - * @return WP_Error|array + * @return false|mixed */ public function put(string $endpoint, array $args = []) { @@ -1799,7 +1848,7 @@ public function put(string $endpoint, array $args = []) * @param string $endpoint API Endpoint. * @param array|string> $args Request arguments. * - * @return WP_Error|array + * @return false|mixed */ public function delete(string $endpoint, array $args = []) { @@ -1815,7 +1864,7 @@ public function delete(string $endpoint, array $args = []) * * @throws \Exception If JSON encoding arguments failed. * - * @return WP_Error|array + * @return false|mixed */ abstract public function request(string $endpoint, string $method, array $args = []); diff --git a/tests/wpunit/APITest.php b/tests/wpunit/APITest.php index c39d4d7..c6558af 100644 --- a/tests/wpunit/APITest.php +++ b/tests/wpunit/APITest.php @@ -1526,6 +1526,116 @@ public function testAddSubscriberToFormByEmail() ); } + /** + * Test that add_subscriber_to_form_by_email() returns the expected data + * when a referrer is specified. + * + * @since 2.1.0 + * + * @return void + */ + public function testAddSubscriberToFormByEmailWithReferrer() + { + // Create subscriber. + $emailAddress = $this->generateEmailAddress(); + $subscriber = $this->api->create_subscriber($emailAddress); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + $this->subscriber_ids[] = $subscriber['subscriber']['id']; + + // Add subscriber to form. + $result = $this->api->add_subscriber_to_form_by_email( + (int) $_ENV['CONVERTKIT_API_FORM_ID'], + $emailAddress, + 'https://mywebsite.com/bfpromo/', + ); + + $this->assertNotInstanceOf(WP_Error::class, $result); + $this->assertIsArray($result); + $this->assertArrayHasKey('subscriber', $result); + $this->assertArrayHasKey('id', $result['subscriber']); + $this->assertEquals( + $result['subscriber']['email_address'], + $emailAddress + ); + + // Assert referrer data set for form subscriber. + $this->assertEquals( + $result['subscriber']['referrer'], + 'https://mywebsite.com/bfpromo/' + ); + } + + /** + * Test that add_subscriber_to_form_by_email() returns the expected data + * when a referrer is specified that includes UTM parameters. + * + * @since 2.1.0 + * + * @return void + */ + public function testAddSubscriberToFormByEmailWithReferrerUTMParams() + { + // Define referrer. + $referrerUTMParams = [ + 'utm_source' => 'facebook', + 'utm_medium' => 'cpc', + 'utm_campaign' => 'black_friday', + 'utm_term' => 'car_owners', + 'utm_content' => 'get_10_off', + ]; + $referrer = 'https://mywebsite.com/bfpromo/?' . http_build_query($referrerUTMParams); + + // Create subscriber. + $emailAddress = $this->generateEmailAddress(); + $subscriber = $this->api->create_subscriber($emailAddress); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + $this->subscriber_ids[] = $subscriber['subscriber']['id']; + + // Add subscriber to form. + $result = $this->api->add_subscriber_to_form_by_email( + (int) $_ENV['CONVERTKIT_API_FORM_ID'], + $emailAddress, + $referrer, + ); + + $this->assertNotInstanceOf(WP_Error::class, $result); + $this->assertIsArray($result); + $this->assertArrayHasKey('subscriber', $result); + $this->assertArrayHasKey('id', $result['subscriber']); + $this->assertEquals( + $result['subscriber']['email_address'], + $emailAddress + ); + + // Assert referrer data set for form subscriber. + $this->assertEquals( + $result['subscriber']['referrer'], + $referrer + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['source'], + $referrerUTMParams['utm_source'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['medium'], + $referrerUTMParams['utm_medium'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['campaign'], + $referrerUTMParams['utm_campaign'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['term'], + $referrerUTMParams['utm_term'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['content'], + $referrerUTMParams['utm_content'] + ); + } + /** * Test that add_subscriber_to_form_by_email() returns a WP_Error when an invalid * form is specified. @@ -1594,6 +1704,116 @@ public function testAddSubscriberToForm() $this->assertEquals($result['subscriber']['id'], $subscriber['subscriber']['id']); } + /** + * Test that add_subscriber_to_form() returns the expected data + * when a referrer is specified. + * + * @since 2.1.0 + * + * @return void + */ + public function testAddSubscriberToFormWithReferrer() + { + // Create subscriber. + $emailAddress = $this->generateEmailAddress(); + $subscriber = $this->api->create_subscriber($emailAddress); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + $this->subscriber_ids[] = $subscriber['subscriber']['id']; + + // Add subscriber to form. + $result = $this->api->add_subscriber_to_form( + (int) $_ENV['CONVERTKIT_API_FORM_ID'], + $subscriber['subscriber']['id'], + 'https://mywebsite.com/bfpromo/', + ); + + $this->assertNotInstanceOf(WP_Error::class, $result); + $this->assertIsArray($result); + $this->assertArrayHasKey('subscriber', $result); + $this->assertArrayHasKey('id', $result['subscriber']); + $this->assertEquals( + $result['subscriber']['id'], + $subscriber['subscriber']['id'] + ); + + // Assert referrer data set for form subscriber. + $this->assertEquals( + $result['subscriber']['referrer'], + 'https://mywebsite.com/bfpromo/' + ); + } + + /** + * Test that add_subscriber_to_form() returns the expected data + * when a referrer is specified that includes UTM parameters. + * + * @since 2.1.0 + * + * @return void + */ + public function testAddSubscriberToFormWithReferrerUTMParams() + { + // Define referrer. + $referrerUTMParams = [ + 'utm_source' => 'facebook', + 'utm_medium' => 'cpc', + 'utm_campaign' => 'black_friday', + 'utm_term' => 'car_owners', + 'utm_content' => 'get_10_off', + ]; + $referrer = 'https://mywebsite.com/bfpromo/?' . http_build_query($referrerUTMParams); + + // Create subscriber. + $emailAddress = $this->generateEmailAddress(); + $subscriber = $this->api->create_subscriber($emailAddress); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + $this->subscriber_ids[] = $subscriber['subscriber']['id']; + + // Add subscriber to form. + $result = $this->api->add_subscriber_to_form( + (int) $_ENV['CONVERTKIT_API_FORM_ID'], + $subscriber['subscriber']['id'], + $referrer, + ); + + $this->assertNotInstanceOf(WP_Error::class, $result); + $this->assertIsArray($result); + $this->assertArrayHasKey('subscriber', $result); + $this->assertArrayHasKey('id', $result['subscriber']); + $this->assertEquals( + $result['subscriber']['id'], + $subscriber['subscriber']['id'] + ); + + // Assert referrer data set for form subscriber. + $this->assertEquals( + $result['subscriber']['referrer'], + $referrer + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['source'], + $referrerUTMParams['utm_source'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['medium'], + $referrerUTMParams['utm_medium'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['campaign'], + $referrerUTMParams['utm_campaign'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['term'], + $referrerUTMParams['utm_term'] + ); + $this->assertEquals( + $result['subscriber']['referrer_utm_parameters']['content'], + $referrerUTMParams['utm_content'] + ); + } + /** * Test that add_subscriber_to_form() returns a WP_Error when an invalid * form ID is specified. From 20d7fd52582966d3fb896aa5eec4c1950f4bef5d Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 17 Dec 2024 17:00:41 +0000 Subject: [PATCH 2/5] Reinstate missing `add_subscriber_to_legacy_form` method --- src/class-convertkit-api-traits.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/class-convertkit-api-traits.php b/src/class-convertkit-api-traits.php index 22ddc15..63f2aa0 100644 --- a/src/class-convertkit-api-traits.php +++ b/src/class-convertkit-api-traits.php @@ -303,6 +303,21 @@ public function add_subscriber_to_form(int $form_id, int $subscriber_id, string ); } + /** + * Adds a subscriber to a legacy form by subscriber ID + * + * @param integer $form_id Legacy Form ID. + * @param integer $subscriber_id Subscriber ID. + * + * @since 2.0.0 + * + * @return WP_Error|array + */ + public function add_subscriber_to_legacy_form(int $form_id, int $subscriber_id) + { + return $this->post(sprintf('landing_pages/%s/subscribers/%s', $form_id, $subscriber_id)); + } + /** * List subscribers for a form * From e562ef24a471c1bc063f6e918cbb44be4d32d74c Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 17 Dec 2024 17:18:37 +0000 Subject: [PATCH 3/5] Run tests against `latest` WordPress stable version --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 709e443..ded4e07 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - wp-versions: [ '6.7-RC4' ] #[ 'latest', '6.1.1' ] + wp-versions: [ 'latest' ] #[ 'latest', '6.1.1' ] php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] #[ '7.4', '8.0', '8.1', '8.2' ] # Steps to install, configure and run tests From d34caae005efea71800703a8839cecf1dfaa0791 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 17 Dec 2024 17:42:04 +0000 Subject: [PATCH 4/5] Fix errant test reference to `convertkit.com` on Landing Page --- tests/wpunit/APITest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wpunit/APITest.php b/tests/wpunit/APITest.php index c6558af..491e6ad 100644 --- a/tests/wpunit/APITest.php +++ b/tests/wpunit/APITest.php @@ -6388,7 +6388,7 @@ public function testGetLegacyFormHTML() { $result = $this->api->get_form_html($_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], $_ENV['CONVERTKIT_API_KEY']); $this->assertNotInstanceOf(WP_Error::class, $result); - $this->assertStringContainsString('
', $result); + $this->assertStringContainsString('', $result); // Assert that the API class' manually added UTF-8 Content-Type has been removed prior to output. $this->assertStringNotContainsString('', $result); From f4ce8456e48b0156faaaec60c6a99106d9cc7961 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 17 Dec 2024 18:02:40 +0000 Subject: [PATCH 5/5] Add a delay to tests to avoid 429 rate limit --- tests/wpunit/APITest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/wpunit/APITest.php b/tests/wpunit/APITest.php index 491e6ad..27f2d03 100644 --- a/tests/wpunit/APITest.php +++ b/tests/wpunit/APITest.php @@ -95,6 +95,9 @@ public function setUp(): void $_ENV['CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA'], $_ENV['CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA'] ); + + // Wait a second to avoid hitting a 429 rate limit. + sleep(1); } /**