Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created August 5, 2025 17:35
Show Gist options
  • Save greenhornet79/418cd85d1999940ef747d2eb7db5a331 to your computer and use it in GitHub Desktop.
Save greenhornet79/418cd85d1999940ef747d2eb7db5a331 to your computer and use it in GitHub Desktop.
<?php
add_shortcode('leaky_paywall_read_banner', 'leaky_paywall_read_banner');
function leaky_paywall_read_banner()
{
$restriction = new Leaky_Paywall_Restrictions();
$articles_read = $restriction->get_content_viewed_by_user();
$articles_read_count = 0;
$total_articles = '3';
if (!empty($articles_read)) {
foreach ($articles_read as $type) {
$articles_read_count = $articles_read_count + count($type);
}
}
ob_start(); ?>
<div class="leaky-paywall-read-banner-shortcode">
<h2>Exclusive</h2>
<p>You've read <?php echo $articles_read_count; ?> of <?php echo $total_articles; ?> exclusive articles this month. Unlock unlimited articles by <a href="#">creating a (free) account.</a></p>
</div>
<style>
.leaky-paywall-read-banner-shortcode {
background: linen;
padding: 15px;
}
</style>
<?php $content = ob_get_contents();
ob_end_clean();
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment