Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions includes/blocks/class-convertkit-block-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,40 @@ public function render( $atts, $content = '' ) {
);

// Get the subscriber's tags, to see if they subscribed to this tag.
$tags = $api->get_subscriber_tags( $subscriber_id );
if ( is_numeric( $subscriber_id ) ) {
$tags = $api->get_subscriber_tags( $subscriber_id );

// Bail if an error occurred.
if ( is_wp_error( $tags ) ) {
if ( $settings->debug_enabled() ) {
return '<!-- Kit Custom Content: ' . $tags->get_error_message() . ' -->';
// Bail if an error occurred.
if ( is_wp_error( $tags ) ) {
if ( $settings->debug_enabled() ) {
return '<!-- Kit Custom Content: ' . $tags->get_error_message() . ' -->';
}

return '';
}
} else {
// Subscriber ID is a signed subscriber ID.
// Get tags that the subscriber has access to via the profile() method.
$result = $api->profile( $subscriber_id );

// If an error occurred, the subscriber ID is invalid.
if ( is_wp_error( $result ) ) {
if ( $settings->debug_enabled() ) {
return '<!-- Kit Custom Content: ' . $result->get_error_message() . ' -->';
}

return '';
}

return '';
// Build tags array.
$tags = array(
'tags' => array(),
);
foreach ( $result['tags'] as $tag_id ) {
$tags['tags'][] = array(
'id' => $tag_id,
);
}
}

// Bail if the subscriber has no tags.
Expand Down
80 changes: 80 additions & 0 deletions tests/EndToEnd/tags/PageShortcodeCustomContentCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,86 @@ public function testCustomContentShortcodeWithValidTagParameterAndValidSubscribe
$I->see('KitCustomContent');
}

/**
* Test the [convertkit_content] shortcode works when a valid Tag ID is specified,
* and an invalid signed subscriber ID is used.
*
* @since 3.4.0
*
* @param EndToEndTester $I Tester.
*/
public function testCustomContentShortcodeWithValidTagParameterAndInvalidSignedSubscriberID(EndToEndTester $I)
Comment thread
n7studios marked this conversation as resolved.
{
// Create Page with Shortcode.
$I->havePageInDatabase(
[
'post_name' => 'kit-custom-content-shortcode-valid-tag-param-and-invalid-signed-subscriber-id',
'post_content' => '[convertkit_content tag="' . $_ENV['CONVERTKIT_API_TAG_ID'] . '"]KitCustomContent[/convertkit_content]',
]
);

// Load the Page on the frontend site.
$I->amOnPage('/kit-custom-content-shortcode-valid-tag-param-and-invalid-signed-subscriber-id');

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);

// Confirm that the Custom Content is not yet displayed.
$I->dontSee('KitCustomContent');

// Set cookie with invalid signed subscriber ID.
$I->setRestrictContentCookie($I, 'invalid-signed-subscriber-id');

// Reload the page.
$I->amOnPage('/kit-custom-content-shortcode-valid-tag-param-and-invalid-signed-subscriber-id');

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);

// Confirm that the Custom Content is now displayed.
$I->dontSee('KitCustomContent');
}

/**
* Test the [convertkit_content] shortcode works when a valid Tag ID is specified,
* and a valid signed subscriber ID is used who is subscribed to the tag.
*
* @since 3.4.0
*
* @param EndToEndTester $I Tester.
*/
public function testCustomContentShortcodeWithValidTagParameterAndValidSignedSubscriberID(EndToEndTester $I)
{
// Create Page with Shortcode.
$I->havePageInDatabase(
[
'post_name' => 'kit-custom-content-shortcode-valid-tag-param-and-valid-signed-subscriber-id',
'post_content' => '[convertkit_content tag="' . $_ENV['CONVERTKIT_API_TAG_ID'] . '"]KitCustomContent[/convertkit_content]',
]
);

// Load the Page on the frontend site.
$I->amOnPage('/kit-custom-content-shortcode-valid-tag-param-and-valid-signed-subscriber-id');

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);

// Confirm that the Custom Content is not yet displayed.
$I->dontSee('KitCustomContent');

// Set cookie with signed subscriber ID.
$I->setRestrictContentCookie($I, $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']);

// Reload the page.
$I->amOnPage('/kit-custom-content-shortcode-valid-tag-param-and-valid-signed-subscriber-id');

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);

// Confirm that the Custom Content is now displayed.
$I->see('KitCustomContent');
}

/**
* Deactivate and reset Plugin(s) after each test, if the test passes.
* We don't use _after, as this would provide a screenshot of the Plugin
Expand Down