I need bit of help, so I am looking into a plugin created for newsletter where default is it shows ad but it has option to remove ads by checking the check box. Default is to send ads in newsletter but if you don't want to send ads through newsletter then check the box. The problem is, it seems like checkbox selected is not being picked up. Some help would be appreciated.
The custom field in wp:
'label' => 'Hide newsletter ads',
'name' => 'hide_ads',
'type' => 'checkbox',
'instructions' => 'Checking the checkbox will remove ads',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Hide newsletter ads' => 'Hide newsletter ads',
),
'allow_custom' => 0,
'default_value' => array(
),
'layout' => 'block',
'toggle' => 0,
'return_format' => 'value',
'save_custom' => 0,
),
This is the php code for it:
<!doctype html>
<html lang="en-GB">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="x-apple-disable-message-reformatting">
<title><?php the_title(); ?></title>
<style>
<?php require ABSPATH . 'path/newsletter.css'; ?>
</style>
<!--[if mso]>
<style type="text/css">
.outlook-fallback-font {
font-family: 'Lucida Bright', 'Cambria', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
</style>
<![endif]-->
</head>
<?php
$hide_newsletter_ads = get_field('hide_ads');
echo $hide_newsletter_ads;
?>
<body itemscope itemtype="http://schema.org/EmailMessage">
<div class="wrap">
<?php
if (!$hide_newsletter_ads) {
include ABSPATH . 'path/ad-banner.php';
}
?>
<div class="header">
<a href="<?php bloginfo( 'url' ); ?>">
<img src="<?php echo get_home_url().'logo.png' ?>" alt="News"
/>
</a>
</div>
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<?php if ( get_field( 'newsletter_summary' ) ) { ?>
<div class="newsletter-summary"><?php the_field( 'newsletter_summary' ); ?></div>
<?php } ?>
<?php if ( have_rows( 'newsletter_content' ) ) : ?>
<?php
// Loop through the ACF blocks
$count = 0;
while ( have_rows( 'newsletter_content' ) ) :
the_row();
if ( get_row_layout() === 'story' ) :
?>
<?php if ( 0 === $count ) { ?>
<span class="date outlook-fallback-font"><?php the_time( 'd M Y' ); ?></span>
<?php } ?>
<?php if ( get_sub_field( 'story_heading' ) ) : ?>
<h1><?php the_sub_field( 'story_heading' ); ?></h1>
<?php endif; ?>
<div class="content">
<?php the_sub_field( 'story_content' ); ?>
</div>
<?php
endif;
if ( 'post_list' === get_row_layout() ) :
?>
<?php
$posts = get_sub_field( 'post_list' );
if ( $posts ) :
?>
</div>
<div class="story-list">
<h2><span class="wrap"><?php the_sub_field( 'post_list_heading' ); ?></span></h2>
<div class="wrap-table">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<?php
// Output story cards
foreach ( $posts as $i => $post ) {
if ( 0 === $i % 2 ) {
echo '<tr>';
}
$class = ( 0 === $i % 2 ) ? 'odd' : 'even';
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 640, 345 ) );
$image_srcset = wp_get_attachment_image_srcset( get_post_thumbnail_id( $post->ID ) );
echo sprintf(
'<td class="story-cell %4$s" valign="top">
<a href="%1$s" class="story-card outlook-fallback-font">
<img src="%3$s" alt="" height="120" style="height: 150px; object-fit: cover;" />
<span>%2$s</span>
</a>
</td>',
esc_url( get_permalink( $post->ID ) . '?utm_source=newsletter&utm_medium=email&utm_campaign=newsletter' ), // permalink
esc_html( get_the_title( $post->ID ) ), // title
// esc_attr( $image_src[0] ), // image - src
esc_attr( $image_src[0] ), // image - src
esc_attr( $class ) // class
);
if ( 0 !== $i % 2 || count( $posts ) === ( $i + 1 ) ) {
echo '</tr>';
}
}
?>
</table>
</div>
</div>
<div class="wrap">
<?php
endif;
endif;
if (!$hide_newsletter_ads) {
(0 === $count) {
include ABSPATH . 'path/mpu-1.php';
}
if (1 === $count) {
include ABSPATH . 'path/mpu-2.php';
}
}
$count++;
endwhile;
endif;
?>
<div class="footer">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left">
© <?php echo esc_html( date( 'Y' ) ); ?>
</td>
<td class="footer-link">
<a href="<?php echo get_permalink( get_page_by_path( 'privacy-policy' ) ); ?>">Privacy Policy</a> ·
<a href="%unsubscribe_url%">Unsubscribe</a>
</td>
</tr>
</table>
</div>
</div>
<?php
endwhile;
endif;
?>