diff --git a/includes/class-newspack-sponsors-core.php b/includes/class-newspack-sponsors-core.php
index 16439ca..3317f8c 100644
--- a/includes/class-newspack-sponsors-core.php
+++ b/includes/class-newspack-sponsors-core.php
@@ -10,6 +10,8 @@
namespace Newspack_Sponsors;
+use Newspack_Sponsors\Newspack_Sponsors_Settings as Settings;
+
defined( 'ABSPATH' ) || exit;
/**
@@ -59,8 +61,10 @@ public static function suppress_ads( $should_display, $post_id ) {
if ( ! is_single() ) {
return $should_display;
}
- $sponsors = get_sponsors_for_post( $post_id );
- if ( $sponsors && count( $sponsors ) ) {
+
+ $suppress_ads = Settings::get_settings( 'suppress' );
+ $sponsors = get_sponsors_for_post( $post_id );
+ if ( boolval( $suppress_ads ) && $sponsors && count( $sponsors ) ) {
return false;
}
return $should_display;
diff --git a/includes/class-newspack-sponsors-settings.php b/includes/class-newspack-sponsors-settings.php
index 93a6b90..9a5f911 100644
--- a/includes/class-newspack-sponsors-settings.php
+++ b/includes/class-newspack-sponsors-settings.php
@@ -40,6 +40,7 @@ public static function get_default_settings() {
),
get_bloginfo( 'name' )
),
+ 'suppress' => false,
];
return $defaults;
@@ -48,14 +49,17 @@ public static function get_default_settings() {
/**
* Get current site-wide settings, or defaults if not set.
*
+ * @param string $setting Key name of a setting to retrieve. If given, only the matching setting's value will be returned.
+ *
* @return array Array of current site-wide settings.
*/
- public static function get_settings() {
+ public static function get_settings( $setting = null ) {
$defaults = self::get_default_settings();
$settings = [
'byline' => get_option( 'newspack_sponsors_default_byline', $defaults['byline'] ),
'flag' => get_option( 'newspack_sponsors_default_flag', $defaults['flag'] ),
'disclaimer' => get_option( 'newspack_sponsors_default_disclaimer', $defaults['disclaimer'] ),
+ 'suppress' => get_option( 'newspack_sponsors_suppress_ads', $defaults['suppress'] ),
];
// Guard against empty strings, which can happen if an option is set and then unset.
@@ -65,6 +69,10 @@ public static function get_settings() {
}
}
+ if ( $setting && isset( $settings[ $setting ] ) ) {
+ return $settings[ $setting ];
+ }
+
return $settings;
}
@@ -95,6 +103,12 @@ public static function get_settings_list() {
'key' => 'newspack_sponsors_default_disclaimer',
'type' => 'textarea',
],
+ [
+ 'label' => __( 'Suppress Ads for All Sponsored Posts', 'newspack-sponsors' ),
+ 'value' => $defaults['suppress'],
+ 'key' => 'newspack_sponsors_suppress_ads',
+ 'type' => 'checkbox',
+ ],
];
}
@@ -166,7 +180,15 @@ public static function newspack_sponsors_settings_callback( $setting ) {
$type = $setting['type'];
$value = ( '' !== get_option( $key, false ) ) ? get_option( $key, false ) : $setting['value'];
- if ( 'textarea' === $type ) {
+ if ( 'checkbox' === $type ) {
+ printf(
+ '',
+ esc_attr( $key ),
+ esc_attr( $key ),
+ ! empty( $value ) ? 'checked' : '',
+ esc_attr( $key )
+ );
+ } elseif ( 'textarea' === $type ) {
printf(
'',
esc_attr( $key ),