@@ -161,7 +161,7 @@ public function get_growth_stats(\DateTime $starting = null, \DateTime $ending =
161
161
*
162
162
* @see https://developers.convertkit.com/v4.html#convertkit-api-forms
163
163
*
164
- * @return false |array<int,\stdClass>
164
+ * @return mixed |array<int,\stdClass>
165
165
*/
166
166
public function get_forms (
167
167
string $ status = 'active ' ,
@@ -198,7 +198,7 @@ public function get_forms(
198
198
*
199
199
* @see https://developers.convertkit.com/v4.html#convertkit-api-forms
200
200
*
201
- * @return false |array<int,\stdClass>
201
+ * @return mixed |array<int,\stdClass>
202
202
*/
203
203
public function get_landing_pages (
204
204
string $ status = 'active ' ,
@@ -222,21 +222,57 @@ public function get_landing_pages(
222
222
);
223
223
}
224
224
225
+ /**
226
+ * Adds subscribers to forms in bulk.
227
+ *
228
+ * @param array<array<string,string>> $forms_subscribers_ids Array of arrays comprising of `form_id`, `subscriber_id` and optional `referrer` URL.
229
+ * @param string $callback_url URL to notify for large batch size when async processing complete.
230
+ *
231
+ * @since 2.1.0
232
+ *
233
+ * @see https://developers.kit.com/v4.html#bulk-add-subscribers-to-forms
234
+ *
235
+ * @return false|object
236
+ */
237
+ public function add_subscribers_to_forms (array $ forms_subscribers_ids , string $ callback_url = '' )
238
+ {
239
+ // Build parameters.
240
+ $ options = ['additions ' => $ forms_subscribers_ids ];
241
+ if (!empty ($ callback_url )) {
242
+ $ options ['callback_url ' ] = $ callback_url ;
243
+ }
244
+
245
+ // Send request.
246
+ return $ this ->post (
247
+ 'bulk/forms/subscribers ' ,
248
+ $ options
249
+ );
250
+ }
251
+
225
252
/**
226
253
* Adds a subscriber to a form by email address
227
254
*
228
255
* @param integer $form_id Form ID.
229
256
* @param string $email_address Email Address.
257
+ * @param string $referrer Referrer.
230
258
*
231
259
* @see https://developers.convertkit.com/v4.html#add-subscriber-to-form-by-email-address
232
260
*
233
261
* @return false|mixed
234
262
*/
235
- public function add_subscriber_to_form_by_email (int $ form_id , string $ email_address )
263
+ public function add_subscriber_to_form_by_email (int $ form_id , string $ email_address, string $ referrer = '' )
236
264
{
265
+ // Build parameters.
266
+ $ options = ['email_address ' => $ email_address ];
267
+
268
+ if (!empty ($ referrer )) {
269
+ $ options ['referrer ' ] = $ referrer ;
270
+ }
271
+
272
+ // Send request.
237
273
return $ this ->post (
238
274
sprintf ('forms/%s/subscribers ' , $ form_id ),
239
- [ ' email_address ' => $ email_address ]
275
+ $ options
240
276
);
241
277
}
242
278
@@ -245,16 +281,28 @@ public function add_subscriber_to_form_by_email(int $form_id, string $email_addr
245
281
*
246
282
* @param integer $form_id Form ID.
247
283
* @param integer $subscriber_id Subscriber ID.
284
+ * @param string $referrer Referrer URL.
248
285
*
249
286
* @see https://developers.convertkit.com/v4.html#add-subscriber-to-form
250
287
*
251
288
* @since 2.0.0
252
289
*
253
290
* @return false|mixed
254
291
*/
255
- public function add_subscriber_to_form (int $ form_id , int $ subscriber_id )
292
+ public function add_subscriber_to_form (int $ form_id , int $ subscriber_id, string $ referrer = '' )
256
293
{
257
- return $ this ->post (sprintf ('forms/%s/subscribers/%s ' , $ form_id , $ subscriber_id ));
294
+ // Build parameters.
295
+ $ options = [];
296
+
297
+ if (!empty ($ referrer )) {
298
+ $ options ['referrer ' ] = $ referrer ;
299
+ }
300
+
301
+ // Send request.
302
+ return $ this ->post (
303
+ sprintf ('forms/%s/subscribers/%s ' , $ form_id , $ subscriber_id ),
304
+ $ options
305
+ );
258
306
}
259
307
260
308
/**
@@ -456,7 +504,7 @@ public function get_sequence_subscriptions(
456
504
*
457
505
* @see https://developers.convertkit.com/v4.html#list-tags
458
506
*
459
- * @return false |array<int,\stdClass>
507
+ * @return mixed |array<int,\stdClass>
460
508
*/
461
509
public function get_tags (
462
510
bool $ include_total_count = false ,
@@ -863,10 +911,26 @@ public function get_subscriber_id(string $email_address)
863
911
['email_address ' => $ email_address ]
864
912
);
865
913
914
+ if (!$ subscribers instanceof \stdClass) {
915
+ return false ;
916
+ }
917
+
918
+ if (!is_array ($ subscribers ->subscribers )) {
919
+ return false ;
920
+ }
921
+
866
922
if (!count ($ subscribers ->subscribers )) {
867
923
return false ;
868
924
}
869
925
926
+ if (!$ subscribers ->subscribers [0 ] instanceof \stdClass) {
927
+ return false ;
928
+ }
929
+
930
+ if (!is_int ($ subscribers ->subscribers [0 ]->id )) {
931
+ return false ;
932
+ }
933
+
870
934
// Return the subscriber's ID.
871
935
return $ subscribers ->subscribers [0 ]->id ;
872
936
}
@@ -878,7 +942,7 @@ public function get_subscriber_id(string $email_address)
878
942
*
879
943
* @see https://developers.convertkit.com/v4.html#get-a-subscriber
880
944
*
881
- * @return false |integer
945
+ * @return mixed |integer
882
946
*/
883
947
public function get_subscriber (int $ subscriber_id )
884
948
{
@@ -895,7 +959,7 @@ public function get_subscriber(int $subscriber_id)
895
959
*
896
960
* @see https://developers.convertkit.com/v4.html#update-a-subscriber
897
961
*
898
- * @return false| mixed
962
+ * @return mixed
899
963
*/
900
964
public function update_subscriber (
901
965
int $ subscriber_id ,
@@ -930,7 +994,7 @@ public function update_subscriber(
930
994
*
931
995
* @see https://developers.convertkit.com/v4.html#unsubscribe-subscriber
932
996
*
933
- * @return false |object
997
+ * @return mixed |object
934
998
*/
935
999
public function unsubscribe_by_email (string $ email_address )
936
1000
{
@@ -949,7 +1013,7 @@ public function unsubscribe_by_email(string $email_address)
949
1013
*
950
1014
* @see https://developers.convertkit.com/v4.html#unsubscribe-subscriber
951
1015
*
952
- * @return false |object
1016
+ * @return mixed |object
953
1017
*/
954
1018
public function unsubscribe (int $ subscriber_id )
955
1019
{
@@ -967,7 +1031,7 @@ public function unsubscribe(int $subscriber_id)
967
1031
*
968
1032
* @see https://developers.convertkit.com/v4.html#list-tags-for-a-subscriber
969
1033
*
970
- * @return false |array<int,\stdClass>
1034
+ * @return mixed |array<int,\stdClass>
971
1035
*/
972
1036
public function get_subscriber_tags (
973
1037
int $ subscriber_id ,
@@ -1044,7 +1108,7 @@ public function get_broadcasts(
1044
1108
*
1045
1109
* @see https://developers.convertkit.com/v4.html#create-a-broadcast
1046
1110
*
1047
- * @return false |object
1111
+ * @return mixed |object
1048
1112
*/
1049
1113
public function create_broadcast (
1050
1114
string $ subject = '' ,
@@ -1103,7 +1167,7 @@ public function create_broadcast(
1103
1167
*
1104
1168
* @see https://developers.convertkit.com/v4.html#get-a-broadcast
1105
1169
*
1106
- * @return false |object
1170
+ * @return mixed |object
1107
1171
*/
1108
1172
public function get_broadcast (int $ id )
1109
1173
{
@@ -1118,7 +1182,7 @@ public function get_broadcast(int $id)
1118
1182
*
1119
1183
* @see https://developers.convertkit.com/v4.html#get-stats
1120
1184
*
1121
- * @return false |object
1185
+ * @return mixed |object
1122
1186
*/
1123
1187
public function get_broadcast_stats (int $ id )
1124
1188
{
@@ -1151,7 +1215,7 @@ public function get_broadcast_stats(int $id)
1151
1215
*
1152
1216
* @see https://developers.convertkit.com/#create-a-broadcast
1153
1217
*
1154
- * @return false |object
1218
+ * @return mixed |object
1155
1219
*/
1156
1220
public function update_broadcast (
1157
1221
int $ id ,
@@ -1213,7 +1277,7 @@ public function update_broadcast(
1213
1277
*
1214
1278
* @see https://developers.convertkit.com/v4.html#delete-a-broadcast
1215
1279
*
1216
- * @return false |object
1280
+ * @return mixed |object
1217
1281
*/
1218
1282
public function delete_broadcast (int $ id )
1219
1283
{
@@ -1266,7 +1330,7 @@ public function get_webhooks(
1266
1330
*
1267
1331
* @throws \InvalidArgumentException If the event is not supported.
1268
1332
*
1269
- * @return false |object
1333
+ * @return mixed |object
1270
1334
*/
1271
1335
public function create_webhook (string $ url , string $ event , string $ parameter = '' )
1272
1336
{
@@ -1340,7 +1404,7 @@ public function create_webhook(string $url, string $event, string $parameter = '
1340
1404
*
1341
1405
* @see https://developers.convertkit.com/v4.html#delete-a-webhook
1342
1406
*
1343
- * @return false |object
1407
+ * @return mixed |object
1344
1408
*/
1345
1409
public function delete_webhook (int $ id )
1346
1410
{
@@ -1389,7 +1453,7 @@ public function get_custom_fields(
1389
1453
*
1390
1454
* @see https://developers.convertkit.com/v4.html#create-a-custom-field
1391
1455
*
1392
- * @return false |object
1456
+ * @return mixed |object
1393
1457
*/
1394
1458
public function create_custom_field (string $ label )
1395
1459
{
@@ -1409,7 +1473,7 @@ public function create_custom_field(string $label)
1409
1473
*
1410
1474
* @see https://developers.convertkit.com/v4.html#bulk-create-custom-fields
1411
1475
*
1412
- * @return false |object
1476
+ * @return mixed |object
1413
1477
*/
1414
1478
public function create_custom_fields (array $ labels , string $ callback_url = '' )
1415
1479
{
@@ -1444,7 +1508,7 @@ public function create_custom_fields(array $labels, string $callback_url = '')
1444
1508
*
1445
1509
* @see https://developers.convertkit.com/v4.html#update-a-custom-field
1446
1510
*
1447
- * @return false |object
1511
+ * @return mixed |object
1448
1512
*/
1449
1513
public function update_custom_field (int $ id , string $ label )
1450
1514
{
@@ -1463,7 +1527,7 @@ public function update_custom_field(int $id, string $label)
1463
1527
*
1464
1528
* @see https://developers.convertkit.com/#destroy-field
1465
1529
*
1466
- * @return false |object
1530
+ * @return mixed |object
1467
1531
*/
1468
1532
public function delete_custom_field (int $ id )
1469
1533
{
@@ -1510,7 +1574,7 @@ public function get_purchases(
1510
1574
*
1511
1575
* @see https://developers.convertkit.com/v4.html#get-a-purchase
1512
1576
*
1513
- * @return false |object
1577
+ * @return mixed |object
1514
1578
*/
1515
1579
public function get_purchase (int $ purchase_id )
1516
1580
{
@@ -1535,7 +1599,7 @@ public function get_purchase(int $purchase_id)
1535
1599
*
1536
1600
* @see https://developers.convertkit.com/v4.html#create-a-purchase
1537
1601
*
1538
- * @return false |object
1602
+ * @return mixed |object
1539
1603
*/
1540
1604
public function create_purchase (
1541
1605
string $ email_address ,
0 commit comments