PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 All 197 releases
← All changes | vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php +791 -55 3.3.5 → 3.4.4 View file →
@@ -155,13 +155,14 @@
155 155
156 156 /**
157 157 * List forms.
158 158 *
159 - * @param string $status Form status (active|archived|trashed|all).
160 - * @param boolean $include_total_count To include the total count of records in the response, use true.
161 - * @param string $after_cursor Return results after the given pagination cursor.
162 - * @param string $before_cursor Return results before the given pagination cursor.
163 - * @param integer $per_page Number of results to return.
159 + * @param string $status Form status (active|archived|trashed|all).
160 + * @param array<string> $include Additional fields to include: subscriber_count.
161 + * @param boolean $include_total_count To include the total count of records in the response, use true.
162 + * @param string $after_cursor Return results after the given pagination cursor.
163 + * @param string $before_cursor Return results before the given pagination cursor.
164 + * @param integer $per_page Number of results to return.
164 165 *
165 166 * @see https://developers.kit.com/api-reference/forms/list-forms
166 167 *
167 168 * @return mixed|array<int,\stdClass>
@@ -167,20 +168,28 @@
167 168 * @return mixed|array<int,\stdClass>
168 169 */
169 170 public function get_forms(
170 171 string $status = 'active',
172 + array $include = [],
171 173 bool $include_total_count = false,
172 174 string $after_cursor = '',
173 175 string $before_cursor = '',
174 176 int $per_page = 100
175 177 ) {
178 + // Build parameters.
179 + $options = [
180 + 'type' => 'embed',
181 + 'status' => $status,
182 + ];
183 +
184 + if (!empty($include)) {
185 + $options['include'] = implode(',', $include);
186 + }
187 +
176 188 return $this->get(
177 189 'forms',
178 190 $this->build_total_count_and_pagination_params(
179 - [
180 - 'type' => 'embed',
181 - 'status' => $status,
182 - ],
191 + $options,
183 192 $include_total_count,
184 193 $after_cursor,
185 194 $before_cursor,
186 195 $per_page
@@ -329,8 +338,9 @@
329 338 * @param \DateTime|null $created_after Filter subscribers who have been created after this date.
330 339 * @param \DateTime|null $created_before Filter subscribers who have been created before this date.
331 340 * @param \DateTime|null $added_after Filter subscribers who have been added to the form after this date.
332 341 * @param \DateTime|null $added_before Filter subscribers who have been added to the form before this date.
342 + * @param boolean $slim When true, omits expensive optional fields from the response.
333 343 * @param boolean $include_total_count To include the total count of records in the response, use true.
334 344 * @param string $after_cursor Return results after the given pagination cursor.
335 345 * @param string $before_cursor Return results before the given pagination cursor.
336 346 * @param integer $per_page Number of results to return.
@@ -345,8 +355,9 @@
345 355 ?\DateTime $created_after = null,
346 356 ?\DateTime $created_before = null,
347 357 ?\DateTime $added_after = null,
348 358 ?\DateTime $added_before = null,
359 + bool $slim = false,
349 360 bool $include_total_count = false,
350 361 string $after_cursor = '',
351 362 string $before_cursor = '',
352 363 int $per_page = 100
@@ -351,9 +362,9 @@
351 362 string $before_cursor = '',
352 363 int $per_page = 100
353 364 ) {
354 365 // Build parameters.
355 - $options = [];
366 + $options = ['slim' => $slim];
356 367
357 368 if (!empty($subscriber_state)) {
358 369 $options['status'] = $subscriber_state;
359 370 }
@@ -385,12 +396,13 @@
385 396
386 397 /**
387 398 * List sequences
388 399 *
389 - * @param boolean $include_total_count To include the total count of records in the response, use true.
390 - * @param string $after_cursor Return results after the given pagination cursor.
391 - * @param string $before_cursor Return results before the given pagination cursor.
392 - * @param integer $per_page Number of results to return.
400 + * @param array<string> $include Additional fields to include: stats.
401 + * @param boolean $include_total_count To include the total count of records in the response, use true.
402 + * @param string $after_cursor Return results after the given pagination cursor.
403 + * @param string $before_cursor Return results before the given pagination cursor.
404 + * @param integer $per_page Number of results to return.
393 405 *
394 406 * @see https://developers.kit.com/api-reference/sequences/list-sequences
395 407 *
396 408 * @return false|mixed
@@ -395,17 +407,25 @@
395 407 *
396 408 * @return false|mixed
397 409 */
398 410 public function get_sequences(
411 + array $include = [],
399 412 bool $include_total_count = false,
400 413 string $after_cursor = '',
401 414 string $before_cursor = '',
402 415 int $per_page = 100
403 416 ) {
417 + // Build parameters.
418 + $options = [];
419 +
420 + if (!empty($include)) {
421 + $options['include'] = implode(',', $include);
422 + }
423 +
404 424 return $this->get(
405 425 'sequences',
406 426 $this->build_total_count_and_pagination_params(
407 - [],
427 + $options,
408 428 $include_total_count,
409 429 $after_cursor,
410 430 $before_cursor,
411 431 $per_page
@@ -413,8 +433,168 @@
413 433 );
414 434 }
415 435
416 436 /**
437 + * Create a sequence
438 + *
439 + * @param string $name The name of the sequence.
440 + * @param string $email_address The sending email address to use. Uses the account's sending email address if not provided.
441 + * @param integer $email_template_id Id of the email template to use.
442 + * @param array<string> $send_days The days of the week to send the sequence on. Must be one of: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`.
443 + * @param integer $send_hour The hour of the day to send the sequence at. Must be an integer between 0 and 23.
444 + * @param string $time_zone The timezone to use for the sequence. Must be a valid IANA timezone string.
445 + * @param boolean $active Use `true` to activate the sequence, `false` to deactivate it.
446 + * @param boolean $repeat When `true`, subscribers can restart the sequence multiple times.
447 + * @param boolean $hold When `true`, subscribers added via Visual Automations stay in the sequence after receiving the last email.
448 + * @param array<string,string|array<integer>> $exclude_subscriber_sources The subscriber sources to exclude from the sequence. Uses the account's default exclude subscriber sources if not provided.
449 + *
450 + * @see https://developers.kit.com/api-reference/sequences/create-a-sequence
451 + *
452 + * @return mixed|object
453 + */
454 + public function create_sequence(
455 + string $name,
456 + string $email_address = '',
457 + int $email_template_id = 0,
458 + array $send_days = [],
459 + int $send_hour = 0,
460 + string $time_zone = '',
461 + bool $active = true,
462 + bool $repeat = false,
463 + bool $hold = false,
464 + array $exclude_subscriber_sources = []
465 + ) {
466 + $options = [
467 + 'name' => $name,
468 + 'email_address' => $email_address,
469 + 'email_template_id' => $email_template_id,
470 + 'send_hour' => $send_hour,
471 + 'time_zone' => $time_zone,
472 + 'active' => $active,
473 + 'repeat' => $repeat,
474 + 'hold' => $hold,
475 + ];
476 + if (count($send_days)) {
477 + $options['send_days'] = $send_days;
478 + }
479 + if (count($exclude_subscriber_sources)) {
480 + $options['exclude_subscriber_sources'] = $exclude_subscriber_sources;
481 + }
482 +
483 + // Iterate through options, removing blank entries.
484 + foreach ($options as $key => $value) {
485 + if (is_string($value) && strlen($value) === 0) {
486 + unset($options[$key]);
487 + }
488 + }
489 +
490 + // Send request.
491 + return $this->post(
492 + 'sequences',
493 + $options
494 + );
495 + }
496 +
497 + /**
498 + * Get a sequence.
499 + *
500 + * @param integer $id Sequence ID.
501 + * @param array<string> $include Additional fields to include: stats.
502 + *
503 + * @see https://developers.kit.com/api-reference/sequences/get-a-sequence
504 + *
505 + * @return mixed|object
506 + */
507 + public function get_sequence(
508 + int $id,
509 + array $include = []
510 + ) {
511 + // Build parameters.
512 + $options = [];
513 +
514 + if (!empty($include)) {
515 + $options['include'] = implode(',', $include);
516 + }
517 +
518 + return $this->get(sprintf('sequences/%s', $id), $options);
519 + }
520 +
521 + /**
522 + * Updates a sequence
523 + *
524 + * @param integer $sequence_id Sequence ID.
525 + * @param string $name The name of the sequence.
526 + * @param string $email_address The sending email address to use. Uses the account's sending email address if not provided.
527 + * @param integer $email_template_id Id of the email template to use.
528 + * @param array<string> $send_days The days of the week to send the sequence on. Must be one of: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`.
529 + * @param integer $send_hour The hour of the day to send the sequence at. Must be an integer between 0 and 23.
530 + * @param string $time_zone The timezone to use for the sequence. Must be a valid IANA timezone string.
531 + * @param boolean $active Use `true` to activate the sequence, `false` to deactivate it.
532 + * @param boolean $repeat When `true`, subscribers can restart the sequence multiple times.
533 + * @param boolean $hold When `true`, subscribers added via Visual Automations stay in the sequence after receiving the last email.
534 + * @param array<string,string|array<integer>> $exclude_subscriber_sources The subscriber sources to exclude from the sequence. Uses the account's default exclude subscriber sources if not provided.
535 + *
536 + * @see https://developers.kit.com/api-reference/sequences/create-a-sequence
537 + *
538 + * @return mixed|object
539 + */
540 + public function update_sequence(
541 + int $sequence_id,
542 + string $name = '',
543 + string $email_address = '',
544 + int $email_template_id = 0,
545 + array $send_days = [],
546 + int $send_hour = 0,
547 + string $time_zone = '',
548 + bool $active = true,
549 + bool $repeat = false,
550 + bool $hold = false,
551 + array $exclude_subscriber_sources = []
552 + ) {
553 + $options = [
554 + 'name' => $name,
555 + 'email_address' => $email_address,
556 + 'email_template_id' => $email_template_id,
557 + 'send_days' => $send_days,
558 + 'send_hour' => $send_hour,
559 + 'time_zone' => $time_zone,
560 + 'active' => $active,
561 + 'repeat' => $repeat,
562 + 'hold' => $hold,
563 + ];
564 + if (count($exclude_subscriber_sources)) {
565 + $options['exclude_subscriber_sources'] = $exclude_subscriber_sources;
566 + }
567 +
568 + // Iterate through options, removing blank entries.
569 + foreach ($options as $key => $value) {
570 + if (is_string($value) && strlen($value) === 0) {
571 + unset($options[$key]);
572 + }
573 + }
574 +
575 + // Send request.
576 + return $this->put(
577 + sprintf('sequences/%s', $sequence_id),
578 + $options
579 + );
580 + }
581 +
582 + /**
583 + * Deletes a sequence.
584 + *
585 + * @param integer $id Sequence ID.
586 + *
587 + * @see https://developers.kit.com/api-reference/sequences/delete-a-sequence
588 + *
589 + * @return mixed|object
590 + */
591 + public function delete_sequence(int $id)
592 + {
593 + return $this->delete(sprintf('sequences/%s', $id));
594 + }
595 +
596 + /**
417 597 * Adds subscriber to sequence by email address
418 598 *
419 599 * @param integer $sequence_id Sequence ID.
420 600 * @param string $email_address Email Address.
@@ -510,14 +690,372 @@
510 690 );
511 691 }
512 692
513 693 /**
694 + * List sequence emails
695 + *
696 + * @param integer $sequence_id Sequence ID.
697 + * @param array<string> $include Additional fields to include: stats.
698 + * @param boolean $include_total_count To include the total count of records in the response, use true.
699 + * @param string $after_cursor Return results after the given pagination cursor.
700 + * @param string $before_cursor Return results before the given pagination cursor.
701 + * @param integer $per_page Number of results to return.
702 + *
703 + * @see https://developers.kit.com/api-reference/sequence-emails/list-sequence-emails
704 + *
705 + * @return false|mixed
706 + */
707 + public function get_sequence_emails(
708 + int $sequence_id,
709 + array $include = [],
710 + bool $include_total_count = false,
711 + string $after_cursor = '',
712 + string $before_cursor = '',
713 + int $per_page = 100
714 + ) {
715 + // Build parameters.
716 + $options = [];
717 +
718 + if (!empty($include)) {
719 + $options['include'] = implode(',', $include);
720 + }
721 +
722 + return $this->get(
723 + sprintf('sequences/%s/emails', $sequence_id),
724 + $this->build_total_count_and_pagination_params(
725 + $options,
726 + $include_total_count,
727 + $after_cursor,
728 + $before_cursor,
729 + $per_page
730 + )
731 + );
732 + }
733 +
734 + /**
735 + * Create a sequence email
736 + *
737 + * @param integer $sequence_id Sequence ID.
738 + * @param string $subject Subject line of the email.
739 + * @param integer $delay_value Number of days or hours to wait before sending this email after the previous one.
740 + * @param string $delay_unit Unit for the send delay. Use `days` for schedule-aware delivery, `hours` for a fixed hourly delay.
741 + * @param string|null $preview_text Preview text shown in email clients before the email is opened.
742 + * @param string|null $content HTML body content of the email.
743 + * @param integer|null $email_template_id ID of the email template to use for layout and styling.
744 + * @param boolean $published Whether the email is active and will be sent to subscribers.
745 + * @param array<string>|null $send_days Days of the week this email may be sent. Defaults to all 7 days (inherits the sequence schedule). Pass a subset to restrict delivery, or null to reset to all days.
746 + * @param integer|null $position Zero-based position of the email in the sequence. Assigned automatically after the last email if omitted.
747 + *
748 + * @see https://developers.kit.com/api-reference/sequence-emails/create-a-sequence-email
749 + *
750 + * @return mixed|object
751 + */
752 + public function create_sequence_email(
753 + int $sequence_id,
754 + string $subject,
755 + int $delay_value,
756 + string $delay_unit,
757 + ?string $preview_text = null,
758 + ?string $content = null,
759 + ?int $email_template_id = null,
760 + bool $published = false,
761 + ?array $send_days = null,
762 + ?int $position = null
763 + ) {
764 + $options = [
765 + 'subject' => $subject,
766 + 'delay_value' => $delay_value,
767 + 'delay_unit' => $delay_unit,
768 + 'published' => $published,
769 + 'send_days' => $send_days,
770 + ];
771 +
772 + if (!empty($preview_text)) {
773 + $options['preview_text'] = $preview_text;
774 + }
775 + if (!empty($content)) {
776 + $options['content'] = $content;
777 + }
778 + if (!empty($email_template_id)) {
779 + $options['email_template_id'] = $email_template_id;
780 + }
781 + if (!empty($position)) {
782 + $options['position'] = $position;
783 + }
784 +
785 + // Send request.
786 + return $this->post(
787 + sprintf('sequences/%s/emails', $sequence_id),
788 + $options
789 + );
790 + }
791 +
792 + /**
793 + * Get a sequence email.
794 + *
795 + * @param integer $sequence_id Sequence ID.
796 + * @param integer $email_id Email ID.
797 + * @param array<string> $include Additional fields to include: stats.
798 + *
799 + * @see https://developers.kit.com/api-reference/sequence-emails/get-a-sequence-email
800 + *
801 + * @return mixed|object
802 + */
803 + public function get_sequence_email(
804 + int $sequence_id,
805 + int $email_id,
806 + array $include = []
807 + ) {
808 + // Build parameters.
809 + $options = [];
810 +
811 + if (!empty($include)) {
812 + $options['include'] = implode(',', $include);
813 + }
814 +
815 + return $this->get(sprintf('sequences/%s/emails/%s', $sequence_id, $email_id), $options);
816 + }
817 +
818 + /**
819 + * Updates a sequence
820 + *
821 + * @param integer $sequence_id Sequence ID.
822 + * @param integer $email_id Sequence Email ID.
823 + * @param string|null $subject Subject line of the email.
824 + * @param integer|null $delay_value Number of days or hours to wait before sending this email after the previous one.
825 + * @param string|null $delay_unit Unit for the send delay. Use `days` for schedule-aware delivery, `hours` for a fixed hourly delay.
826 + * @param string|null $preview_text Preview text shown in email clients before the email is opened.
827 + * @param string|null $content HTML body content of the email.
828 + * @param integer|null $email_template_id ID of the email template to use for layout and styling.
829 + * @param boolean|null $published Whether the email is active and will be sent to subscribers.
830 + * @param array<string>|null $send_days Days of the week this email may be sent. Defaults to all 7 days (inherits the sequence schedule). Pass a subset to restrict delivery, or null to reset to all days.
831 + * @param integer|null $position Zero-based position of the email in the sequence. Assigned automatically after the last email if omitted.
832 + *
833 + * @see https://developers.kit.com/api-reference/sequences/create-a-sequence
834 + *
835 + * @return mixed|object
836 + */
837 + public function update_sequence_email(
838 + int $sequence_id,
839 + int $email_id,
840 + ?string $subject = null,
841 + ?int $delay_value = null,
842 + ?string $delay_unit = null,
843 + ?string $preview_text = null,
844 + ?string $content = null,
845 + ?int $email_template_id = null,
846 + ?bool $published = null,
847 + ?array $send_days = null,
848 + ?int $position = null
849 + ) {
850 + // Build parameters.
851 + $options = ['send_days' => $send_days];
852 +
853 + if (!is_null($subject)) {
854 + $options['subject'] = $subject;
855 + }
856 + if (!is_null($delay_value)) {
857 + $options['delay_value'] = $delay_value;
858 + }
859 + if (!is_null($delay_unit)) {
860 + $options['delay_unit'] = $delay_unit;
861 + }
862 + if (!is_null($preview_text)) {
863 + $options['preview_text'] = $preview_text;
864 + }
865 + if (!is_null($content)) {
866 + $options['content'] = $content;
867 + }
868 + if (!is_null($email_template_id)) {
869 + $options['email_template_id'] = $email_template_id;
870 + }
871 + if (!is_null($published)) {
872 + $options['published'] = $published;
873 + }
874 + if (!is_null($send_days)) {
875 + $options['send_days'] = $send_days;
876 + }
877 + if (!is_null($position)) {
878 + $options['position'] = $position;
879 + }
880 +
881 + // Send request.
882 + return $this->put(
883 + sprintf('sequences/%s/emails/%s', $sequence_id, $email_id),
884 + $options
885 + );
886 + }
887 +
888 + /**
889 + * Deletes a sequence email.
890 + *
891 + * @param integer $sequence_id Sequence ID.
892 + * @param integer $email_id Email ID.
893 + *
894 + * @see https://developers.kit.com/api-reference/sequence-emails/delete-a-sequence-email
895 + *
896 + * @return mixed|object
897 + */
898 + public function delete_sequence_email(int $sequence_id, int $email_id)
899 + {
900 + return $this->delete(sprintf('sequences/%s/emails/%s', $sequence_id, $email_id));
901 + }
902 +
903 + /**
904 + * List snippets
905 + *
906 + * @param boolean $archived When `true`, returns only archived snippets. Defaults to `false`.
907 + * @param boolean $include_content When `true`, includes both the content and document fields for each snippet in the response. Defaults to `false`.
908 + * @param string|null $snippet_type Filter snippets by type. Use inline for text snippets or block for rich-text block snippets.
909 + * @param boolean $include_total_count To include the total count of records in the response, use true.
910 + * @param string $after_cursor Return results after the given pagination cursor.
911 + * @param string $before_cursor Return results before the given pagination cursor.
912 + * @param integer $per_page Number of results to return.
913 + *
914 + * @see https://developers.kit.com/api-reference/snippets/list-snippets
915 + *
916 + * @return false|mixed
917 + */
918 + public function get_snippets(
919 + bool $archived = false,
920 + bool $include_content = false,
921 + ?string $snippet_type = null,
922 + bool $include_total_count = false,
923 + string $after_cursor = '',
924 + string $before_cursor = '',
925 + int $per_page = 100
926 + ) {
927 + $options = [
928 + 'archived' => $archived,
929 + 'include_content' => $include_content,
930 + ];
931 + if (!is_null($snippet_type)) {
932 + $options['snippet_type'] = $snippet_type;
933 + }
934 + return $this->get(
935 + 'snippets',
936 + $this->build_total_count_and_pagination_params(
937 + $options,
938 + $include_total_count,
939 + $after_cursor,
940 + $before_cursor,
941 + $per_page
942 + )
943 + );
944 + }
945 +
946 + /**
947 + * Create a snippet
948 + *
949 + * @param string $name Name of the snippet.
950 + * @param string $snippet_type Type of snippet. Must be one of: `inline`, `block`.
951 + * @param string $content Content of the snippet.
952 + *
953 + * @see https://developers.kit.com/api-reference/snippets/create-a-snippet
954 + *
955 + * @return mixed|object
956 + */
957 + public function create_snippet(
958 + string $name,
959 + string $snippet_type,
960 + string $content
961 + ) {
962 + $options = [
963 + 'name' => $name,
964 + 'snippet_type' => $snippet_type,
965 + ];
966 +
967 + switch ($snippet_type) {
968 + case 'inline':
969 + $options['content'] = $content;
970 + break;
971 +
972 + case 'block':
973 + default:
974 + $options['document_attributes'] = ['value_html' => $content];
975 + break;
976 + }
977 +
978 + // Send request.
979 + return $this->post(
980 + 'snippets',
981 + $options
982 + );
983 + }
984 +
985 + /**
986 + * Get a snippet.
987 + *
988 + * @param integer $id Snippet ID.
989 + *
990 + * @see https://developers.kit.com/api-reference/snippets/get-a-snippet
991 + *
992 + * @return mixed|object
993 + */
994 + public function get_snippet(int $id)
995 + {
996 + return $this->get(sprintf('snippets/%s', $id));
997 + }
998 +
999 + /**
1000 + * Updates a snippet
1001 + *
1002 + * @param integer $snippet_id Snippet ID.
1003 + * @param string $name Name of the snippet.
1004 + * @param string $snippet_type Type of snippet. Must be one of: `inline`, `block`.
1005 + * @param boolean $archived Pass `true` to archive or `false` to restore the snippet.
1006 + * @param string $content Content of the snippet.
1007 + *
1008 + * @see https://developers.kit.com/api-reference/snippets/update-a-snippet
1009 + *
1010 + * @return mixed|object
1011 + */
1012 + public function update_snippet(
1013 + int $snippet_id,
1014 + string $name = '',
1015 + string $snippet_type = '',
1016 + bool $archived = false,
1017 + string $content = ''
1018 + ) {
1019 + $options = [
1020 + 'name' => $name,
1021 + 'snippet_type' => $snippet_type,
1022 + 'archived' => $archived,
1023 + ];
1024 +
1025 + switch ($snippet_type) {
1026 + case 'inline':
1027 + $options['content'] = $content;
1028 + break;
1029 +
1030 + case 'block':
1031 + default:
1032 + $options['document_attributes'] = ['value_html' => $content];
1033 + break;
1034 + }
1035 +
1036 + // Iterate through options, removing blank entries.
1037 + foreach ($options as $key => $value) {
1038 + if (is_string($value) && strlen($value) === 0) {
1039 + unset($options[$key]);
1040 + }
1041 + }
1042 +
1043 + // Send request.
1044 + return $this->put(
1045 + sprintf('snippets/%s', $snippet_id),
1046 + $options
1047 + );
1048 + }
1049 +
1050 + /**
514 1051 * List tags.
515 1052 *
516 - * @param boolean $include_total_count To include the total count of records in the response, use true.
517 - * @param string $after_cursor Return results after the given pagination cursor.
518 - * @param string $before_cursor Return results before the given pagination cursor.
519 - * @param integer $per_page Number of results to return.
1053 + * @param array<string> $include Additional fields to include: subscriber_count.
1054 + * @param boolean $include_total_count To include the total count of records in the response, use true.
1055 + * @param string $after_cursor Return results after the given pagination cursor.
1056 + * @param string $before_cursor Return results before the given pagination cursor.
1057 + * @param integer $per_page Number of results to return.
520 1058 *
521 1059 * @see https://developers.kit.com/api-reference/tags/list-tags
522 1060 *
523 1061 * @since 2.0.0
@@ -524,17 +1062,25 @@
524 1062 *
525 1063 * @return mixed|array<int,\stdClass>
526 1064 */
527 1065 public function get_tags(
1066 + array $include = [],
528 1067 bool $include_total_count = false,
529 1068 string $after_cursor = '',
530 1069 string $before_cursor = '',
531 1070 int $per_page = 100
532 1071 ) {
1072 + // Build parameters.
1073 + $options = [];
1074 +
1075 + if (!empty($include)) {
1076 + $options['include'] = implode(',', $include);
1077 + }
1078 +
533 1079 return $this->get(
534 1080 'tags',
535 1081 $this->build_total_count_and_pagination_params(
536 - [],
1082 + $options,
537 1083 $include_total_count,
538 1084 $after_cursor,
539 1085 $before_cursor,
540 1086 $per_page
@@ -594,8 +1140,43 @@
594 1140 );
595 1141 }
596 1142
597 1143 /**
1144 + * Bulk delete tags.
1145 + *
1146 + * @param array<int> $tag_ids Tag IDs.
1147 + * @param string $callback_url URL to notify for large batch size when async processing complete.
1148 + *
1149 + * @since 2.6.0
1150 + *
1151 + * @see https://developers.kit.com/api-reference/tags/bulk-delete-tags
1152 + *
1153 + * @return false|mixed
1154 + */
1155 + public function delete_tags(array $tag_ids, string $callback_url = '')
1156 + {
1157 + // Build parameters.
1158 + $options = [
1159 + 'tags' => [],
1160 + ];
1161 + foreach ($tag_ids as $i => $tag_id) {
1162 + $options['tags'][] = [
1163 + 'id' => (int) $tag_id,
1164 + ];
1165 + }
1166 +
1167 + if (!empty($callback_url)) {
1168 + $options['callback_url'] = $callback_url;
1169 + }
1170 +
1171 + // Send request.
1172 + return $this->delete(
1173 + 'bulk/tags',
1174 + $options
1175 + );
1176 + }
1177 +
1178 + /**
598 1179 * Updates the name of a tag.
599 1180 *
600 1181 * @param integer $tag_id Tag ID.
601 1182 * @param string $name New name.
@@ -722,8 +1303,9 @@
722 1303 * @param \DateTime|null $created_after Filter subscribers who have been created after this date.
723 1304 * @param \DateTime|null $created_before Filter subscribers who have been created before this date.
724 1305 * @param \DateTime|null $tagged_after Filter subscribers who have been tagged after this date.
725 1306 * @param \DateTime|null $tagged_before Filter subscribers who have been tagged before this date.
1307 + * @param boolean $slim When true, omits expensive optional fields from the response.
726 1308 * @param boolean $include_total_count To include the total count of records in the response, use true.
727 1309 * @param string $after_cursor Return results after the given pagination cursor.
728 1310 * @param string $before_cursor Return results before the given pagination cursor.
729 1311 * @param integer $per_page Number of results to return.
@@ -738,8 +1320,9 @@
738 1320 ?\DateTime $created_after = null,
739 1321 ?\DateTime $created_before = null,
740 1322 ?\DateTime $tagged_after = null,
741 1323 ?\DateTime $tagged_before = null,
1324 + bool $slim = false,
742 1325 bool $include_total_count = false,
743 1326 string $after_cursor = '',
744 1327 string $before_cursor = '',
745 1328 int $per_page = 100
@@ -744,9 +1327,9 @@
744 1327 string $before_cursor = '',
745 1328 int $per_page = 100
746 1329 ) {
747 1330 // Build parameters.
748 - $options = [];
1331 + $options = ['slim' => $slim];
749 1332
750 1333 if (!empty($subscriber_state)) {
751 1334 $options['status'] = $subscriber_state;
752 1335 }
@@ -809,8 +1392,59 @@
809 1392 );
810 1393 }
811 1394
812 1395 /**
1396 + * List posts.
1397 + *
1398 + * @param boolean $include_content To include the content field on each post in the response, use true.
1399 + * @param boolean $include_total_count To include the total count of records in the response, use true.
1400 + * @param string $after_cursor Return results after the given pagination cursor.
1401 + * @param string $before_cursor Return results before the given pagination cursor.
1402 + * @param integer $per_page Number of results to return.
1403 + *
1404 + * @since 2.5.0
1405 + *
1406 + * @see https://developers.kit.com/api-reference/posts/list-posts
1407 + *
1408 + * @return false|mixed
1409 + */
1410 + public function get_posts(
1411 + bool $include_content = false,
1412 + bool $include_total_count = false,
1413 + string $after_cursor = '',
1414 + string $before_cursor = '',
1415 + int $per_page = 100
1416 + ) {
1417 + // Send request.
1418 + return $this->get(
1419 + 'posts',
1420 + $this->build_total_count_and_pagination_params(
1421 + ['include_content' => $include_content],
1422 + $include_total_count,
1423 + $after_cursor,
1424 + $before_cursor,
1425 + $per_page
1426 + )
1427 + );
1428 + }
1429 +
1430 + /**
1431 + * Get a post.
1432 + *
1433 + * @param integer $id Post ID.
1434 + *
1435 + * @since 2.5.0
1436 + *
1437 + * @see https://developers.kit.com/api-reference/posts/get-a-post
1438 + *
1439 + * @return mixed|object
1440 + */
1441 + public function get_post(int $id)
1442 + {
1443 + return $this->get(sprintf('posts/%s', $id));
1444 + }
1445 +
1446 + /**
813 1447 * List subscribers.
814 1448 *
815 1449 * @param string $subscriber_state Subscriber State (active|bounced|cancelled|complained|inactive).
816 1450 * @param string $email_address Search susbcribers by email address. This is an exact match search.
@@ -819,8 +1453,10 @@
819 1453 * @param \DateTime|null $updated_after Filter subscribers who have been updated after this date.
820 1454 * @param \DateTime|null $updated_before Filter subscribers who have been updated before this date.
821 1455 * @param string $sort_field Sort Field (id|updated_at|cancelled_at).
822 1456 * @param string $sort_order Sort Order (asc|desc).
1457 + * @param array<string> $include Additional fields to include: attribution, tags, location, canceled_at.
1458 + * @param boolean $slim When true, omits expensive optional fields from the response.
823 1459 * @param boolean $include_total_count To include the total count of records in the response, use true.
824 1460 * @param string $after_cursor Return results after the given pagination cursor.
825 1461 * @param string $before_cursor Return results before the given pagination cursor.
826 1462 * @param integer $per_page Number of results to return.
@@ -839,8 +1475,10 @@
839 1475 ?\DateTime $updated_after = null,
840 1476 ?\DateTime $updated_before = null,
841 1477 string $sort_field = 'id',
842 1478 string $sort_order = 'desc',
1479 + array $include = [],
1480 + bool $slim = false,
843 1481 bool $include_total_count = false,
844 1482 string $after_cursor = '',
845 1483 string $before_cursor = '',
846 1484 int $per_page = 100
@@ -845,9 +1483,9 @@
845 1483 string $before_cursor = '',
846 1484 int $per_page = 100
847 1485 ) {
848 1486 // Build parameters.
849 - $options = [];
1487 + $options = ['slim' => $slim];
850 1488
851 1489 if (!empty($subscriber_state)) {
852 1490 $options['status'] = $subscriber_state;
853 1491 }
@@ -871,8 +1509,11 @@
871 1509 }
872 1510 if (!empty($sort_order)) {
873 1511 $options['sort_order'] = $sort_order;
874 1512 }
1513 + if (!empty($include)) {
1514 + $options['include'] = implode(',', $include);
1515 + }
875 1516
876 1517 // Send request.
877 1518 return $this->get(
878 1519 'subscribers',
@@ -960,19 +1601,24 @@
960 1601
961 1602 /**
962 1603 * Filter subscribers based on engagement.
963 1604 *
964 - * @param array<int, array<string, mixed>> $all Array of filter conditions where ALL must be met (AND logic). Each condition can have.
965 - * - 'type' (string).
966 - * - 'count_greater_than' (int|null).
967 - * - 'count_less_than' (int|null).
968 - * - 'after' (\DateTime|null).
969 - * - 'before' (\DateTime|null).
970 - * - 'any' (array<int|string, mixed>|null).
971 - * @param boolean $include_total_count To include the total count of records in the response, use true.
972 - * @param string $after_cursor Return results after the given pagination cursor.
973 - * @param string $before_cursor Return results before the given pagination cursor.
974 - * @param integer $per_page Number of results to return.
1605 + * @param list<array<string, mixed>> $all Array of filter conditions where ALL must be met (AND logic). Each condition can have.
1606 + * - 'type' (string).
1607 + * - 'count_greater_than' (int|null).
1608 + * - 'count_less_than' (int|null).
1609 + * - 'after' (?\DateTime).
1610 + * - 'before' (?\DateTime).
1611 + * - 'states' (array<string>).
1612 + * - 'any' (array<int|string, mixed>|null).
1613 + * @param string $counting_mode Controls how engagement-filter count thresholds are tallied.
1614 + * - 'raw' (default) counts every event — five opens of the same email = five.
1615 + * - 'unique_email' counts distinct emails on which the action occurred.
1616 + * @param list<array<string, mixed>> $include Array of additional fields to embed on each subscriber row.
1617 + * @param boolean $include_total_count To include the total count of records in the response, use true.
1618 + * @param string $after_cursor Return results after the given pagination cursor.
1619 + * @param string $before_cursor Return results before the given pagination cursor.
1620 + * @param integer $per_page Number of results to return.
975 1621 *
976 1622 * @since 2.4.0
977 1623 *
978 1624 * @see https://developers.kit.com/api-reference/subscribers/filter-subscribers-based-on-engagement
@@ -980,8 +1626,10 @@
980 1626 * @return mixed
981 1627 */
982 1628 public function filter_subscribers(
983 1629 array $all = [],
1630 + string $counting_mode = 'raw',
1631 + array $include = [],
984 1632 bool $include_total_count = false,
985 1633 string $after_cursor = '',
986 1634 string $before_cursor = '',
987 1635 int $per_page = 100
@@ -990,16 +1638,28 @@
990 1638
991 1639 foreach ($all as $condition) {
992 1640 $option = [];
993 1641
994 - if (array_key_exists('count_greater_than', $condition) && $condition['count_greater_than'] !== null) {
995 - $option['count_greater_than'] = $condition['count_greater_than'];
1642 + if (array_key_exists('type', $condition) && !empty($condition['type'])) {
1643 + $option['type'] = $condition['type'];
996 1644 }
997 1645
998 - if (array_key_exists('count_less_than', $condition) && $condition['count_less_than'] !== null) {
999 - $option['count_less_than'] = $condition['count_less_than'];
1646 + if (array_key_exists('count_greater_than', $condition) && is_numeric($condition['count_greater_than'])) {
1647 + $option['count_greater_than'] = (int) $condition['count_greater_than'];
1000 1648 }
1001 1649
1650 + if (array_key_exists('count_greater_than_or_equal', $condition) && is_numeric($condition['count_greater_than_or_equal'])) {
1651 + $option['count_greater_than_or_equal'] = (int) $condition['count_greater_than_or_equal'];
1652 + }
1653 +
1654 + if (array_key_exists('count_less_than', $condition) && is_numeric($condition['count_less_than'])) {
1655 + $option['count_less_than'] = (int) $condition['count_less_than'];
1656 + }
1657 +
1658 + if (array_key_exists('count_less_than_or_equal', $condition) && is_numeric($condition['count_less_than_or_equal'])) {
1659 + $option['count_less_than_or_equal'] = (int) $condition['count_less_than_or_equal'];
1660 + }
1661 +
1002 1662 if (array_key_exists('after', $condition) && $condition['after'] instanceof \DateTime) {
1003 1663 $option['after'] = $condition['after']->format('Y-m-d');
1004 1664 }
1005 1665
@@ -1006,8 +1666,36 @@
1006 1666 if (array_key_exists('before', $condition) && $condition['before'] instanceof \DateTime) {
1007 1667 $option['before'] = $condition['before']->format('Y-m-d');
1008 1668 }
1009 1669
1670 + if (array_key_exists('states', $condition) && !empty($condition['states'])) {
1671 + $option['states'] = (array) $condition['states'];
1672 + }
1673 +
1674 + if (array_key_exists('subscriber_custom_field_id', $condition) && is_numeric($condition['subscriber_custom_field_id'])) {
1675 + $option['subscriber_custom_field_id'] = (int) $condition['subscriber_custom_field_id'];
1676 + }
1677 +
1678 + if (array_key_exists('value', $condition) && $condition['value'] !== null) {
1679 + $option['value'] = $condition['value'];
1680 + }
1681 +
1682 + if (array_key_exists('comparison', $condition) && $condition['comparison'] !== null) {
1683 + $option['comparison'] = $condition['comparison'];
1684 + }
1685 +
1686 + if (array_key_exists('latitude', $condition) && is_numeric($condition['latitude'])) {
1687 + $option['latitude'] = (float) $condition['latitude'];
1688 + }
1689 +
1690 + if (array_key_exists('longitude', $condition) && is_numeric($condition['longitude'])) {
1691 + $option['longitude'] = (float) $condition['longitude'];
1692 + }
1693 +
1694 + if (array_key_exists('radius', $condition) && $condition['radius'] !== null) {
1695 + $option['radius'] = $condition['radius'];
1696 + }
1697 +
1010 1698 if (array_key_exists('any', $condition) && !empty($condition['any'])) {
1011 1699 $option['any'] = (array) $condition['any'];
1012 1700 }
1013 1701
@@ -1016,9 +1704,13 @@
1016 1704
1017 1705 return $this->post(
1018 1706 'subscribers/filter',
1019 1707 $this->build_total_count_and_pagination_params(
1020 - ['all' => $options],
1708 + [
1709 + 'all' => $options,
1710 + 'counting_mode' => $counting_mode,
1711 + 'include' => $include,
1712 + ],
1021 1713 $include_total_count,
1022 1714 $after_cursor,
1023 1715 $before_cursor,
1024 1716 $per_page
@@ -1202,12 +1894,16 @@
1202 1894
1203 1895 /**
1204 1896 * List broadcasts.
1205 1897 *
1206 - * @param boolean $include_total_count To include the total count of records in the response, use true.
1207 - * @param string $after_cursor Return results after the given pagination cursor.
1208 - * @param string $before_cursor Return results before the given pagination cursor.
1209 - * @param integer $per_page Number of results to return.
1898 + * @param \DateTime|null $sent_after Get broadcasts sent after the given date.
1899 + * @param \DateTime|null $sent_before Get broadcasts sent before the given date.
1900 + * @param boolean $slim When true, omits expensive optional fields from the response.
1901 + * @param string|null $status Get broadcasts with the given status (draft, scheduled, sending, completed, aborted).
1902 + * @param boolean $include_total_count To include the total count of records in the response, use true.
1903 + * @param string $after_cursor Return results after the given pagination cursor.
1904 + * @param string $before_cursor Return results before the given pagination cursor.
1905 + * @param integer $per_page Number of results to return.
1210 1906 *
1211 1907 * @see https://developers.kit.com/api-reference/broadcasts/list-broadcasts
1212 1908 *
1213 1909 * @return false|mixed
@@ -1212,18 +1908,35 @@
1212 1908 *
1213 1909 * @return false|mixed
1214 1910 */
1215 1911 public function get_broadcasts(
1912 + ?\DateTime $sent_after = null,
1913 + ?\DateTime $sent_before = null,
1914 + bool $slim = false,
1915 + ?string $status = null,
1216 1916 bool $include_total_count = false,
1217 1917 string $after_cursor = '',
1218 1918 string $before_cursor = '',
1219 1919 int $per_page = 100
1220 1920 ) {
1921 + // Build parameters.
1922 + $options = ['slim' => $slim];
1923 +
1924 + if (!is_null($status)) {
1925 + $options['status'] = $status;
1926 + }
1927 + if (!is_null($sent_after)) {
1928 + $options['sent_after'] = $sent_after->format('Y-m-d');
1929 + }
1930 + if (!is_null($sent_before)) {
1931 + $options['sent_before'] = $sent_before->format('Y-m-d');
1932 + }
1933 +
1221 1934 // Send request.
1222 1935 return $this->get(
1223 1936 'broadcasts',
1224 1937 $this->build_total_count_and_pagination_params(
1225 - [],
1938 + $options,
1226 1939 $include_total_count,
1227 1940 $after_cursor,
1228 1941 $before_cursor,
1229 1942 $per_page
@@ -1359,9 +2072,9 @@
1359 2072 // Send request.
1360 2073 return $this->get(
1361 2074 sprintf('broadcasts/%s/clicks', $id),
1362 2075 $this->build_total_count_and_pagination_params(
1363 - [],
2076 + array(),
1364 2077 false,
1365 2078 $after_cursor,
1366 2079 $before_cursor,
1367 2080 $per_page
@@ -1371,12 +2084,15 @@
1371 2084
1372 2085 /**
1373 2086 * List stats for a list of broadcasts.
1374 2087 *
1375 - * @param boolean $include_total_count To include the total count of records in the response, use true.
1376 - * @param string $after_cursor Return results after the given pagination cursor.
1377 - * @param string $before_cursor Return results before the given pagination cursor.
1378 - * @param integer $per_page Number of results to return.
2088 + * @param \DateTime|null $sent_after Get broadcasts sent after the given date.
2089 + * @param \DateTime|null $sent_before Get broadcasts sent before the given date.
2090 + * @param string|null $status Get broadcasts with the given status (draft, scheduled, sending, completed, aborted).
2091 + * @param boolean $include_total_count To include the total count of records in the response, use true.
2092 + * @param string $after_cursor Return results after the given pagination cursor.
2093 + * @param string $before_cursor Return results before the given pagination cursor.
2094 + * @param integer $per_page Number of results to return.
1379 2095 *
1380 2096 * @since 2.2.1
1381 2097 *
1382 2098 * @see https://developers.kit.com/api-reference/broadcasts/get-stats-for-a-list-of-broadcasts
@@ -1383,18 +2099,34 @@
1383 2099 *
1384 2100 * @return false|mixed
1385 2101 */
1386 2102 public function get_broadcasts_stats(
2103 + ?\DateTime $sent_after = null,
2104 + ?\DateTime $sent_before = null,
2105 + ?string $status = null,
1387 2106 bool $include_total_count = false,
1388 2107 string $after_cursor = '',
1389 2108 string $before_cursor = '',
1390 2109 int $per_page = 100
1391 2110 ) {
2111 + // Build parameters.
2112 + $options = [];
2113 +
2114 + if (!is_null($status)) {
2115 + $options['status'] = $status;
2116 + }
2117 + if (!is_null($sent_after)) {
2118 + $options['sent_after'] = $sent_after->format('Y-m-d');
2119 + }
2120 + if (!is_null($sent_before)) {
2121 + $options['sent_before'] = $sent_before->format('Y-m-d');
2122 + }
2123 +
1392 2124 // Send request.
1393 2125 return $this->get(
1394 - 'broadcasts/stats',
2126 + 'broadcasts',
1395 2127 $this->build_total_count_and_pagination_params(
1396 - [],
2128 + $options,
1397 2129 $include_total_count,
1398 2130 $after_cursor,
1399 2131 $before_cursor,
1400 2132 $per_page
@@ -1401,9 +2133,8 @@
1401 2133 )
1402 2134 );
1403 2135 }
1404 2136
1405 -
1406 2137 /**
1407 2138 * Update a broadcast.
1408 2139 *
1409 2140 * @param integer $id Broadcast ID.
@@ -1950,8 +2681,13 @@
1950 2681 if (strpos($element->getAttribute($attribute), '//fonts.googleapis.com') !== false) {
1951 2682 continue;
1952 2683 }
1953 2684
2685 + // Skip if the attribute's value is an anchor.
2686 + if (strpos($element->getAttribute($attribute), '#') !== false) {
2687 + continue;
2688 + }
2689 +
1954 2690 // Remove element if it's rocket-loader.min.js. Including it prevents landing page redirects from working.
1955 2691 if (strpos($element->getAttribute($attribute), 'rocket-loader.min.js') !== false) {
1956 2692 if ($element->parentNode instanceof \DOMNode) {
1957 2693 $element->parentNode->removeChild($element);
@@ -2052,10 +2788,10 @@
2052 2788
2053 2789 /**
2054 2790 * Performs a PUT request to the API.
2055 2791 *
2056 - * @param string $endpoint API Endpoint.
2057 - * @param array<string, bool|integer|string|array<string, int|string>|string> $args Request arguments.
2792 + * @param string $endpoint API Endpoint.
2793 + * @param array<string, bool|integer|float|string|null|array<int|string, array<int>|boolean|integer|float|string>> $args Request arguments.
2058 2794 *
2059 2795 * @return false|mixed
2060 2796 */
2061 2797 public function put(string $endpoint, array $args = [])
@@ -2065,10 +2801,10 @@
2065 2801
2066 2802 /**
2067 2803 * Performs a DELETE request to the API.
2068 2804 *
2069 - * @param string $endpoint API Endpoint.
2070 - * @param array<string, int|string|array<string, int|string>|string> $args Request arguments.
2805 + * @param string $endpoint API Endpoint.
2806 + * @param array<string, bool|integer|float|string|null|array<int|string, array<string, int|string>|boolean|integer|float|string>> $args Request arguments.
2071 2807 *
2072 2808 * @return false|mixed
2073 2809 */
2074 2810 public function delete(string $endpoint, array $args = [])