@@ -40,6 +40,7 @@ public static function get_default_settings() {
40
40
),
41
41
get_bloginfo ( 'name ' )
42
42
),
43
+ 'suppress ' => false ,
43
44
];
44
45
45
46
return $ defaults ;
@@ -48,14 +49,17 @@ public static function get_default_settings() {
48
49
/**
49
50
* Get current site-wide settings, or defaults if not set.
50
51
*
52
+ * @param string $setting Key name of a setting to retrieve. If given, only the matching setting's value will be returned.
53
+ *
51
54
* @return array Array of current site-wide settings.
52
55
*/
53
- public static function get_settings () {
56
+ public static function get_settings ( $ setting = null ) {
54
57
$ defaults = self ::get_default_settings ();
55
58
$ settings = [
56
59
'byline ' => get_option ( 'newspack_sponsors_default_byline ' , $ defaults ['byline ' ] ),
57
60
'flag ' => get_option ( 'newspack_sponsors_default_flag ' , $ defaults ['flag ' ] ),
58
61
'disclaimer ' => get_option ( 'newspack_sponsors_default_disclaimer ' , $ defaults ['disclaimer ' ] ),
62
+ 'suppress ' => get_option ( 'newspack_sponsors_suppress_ads ' , $ defaults ['suppress ' ] ),
59
63
];
60
64
61
65
// Guard against empty strings, which can happen if an option is set and then unset.
@@ -65,6 +69,10 @@ public static function get_settings() {
65
69
}
66
70
}
67
71
72
+ if ( $ setting && isset ( $ settings [ $ setting ] ) ) {
73
+ return $ settings [ $ setting ];
74
+ }
75
+
68
76
return $ settings ;
69
77
}
70
78
@@ -95,6 +103,12 @@ public static function get_settings_list() {
95
103
'key ' => 'newspack_sponsors_default_disclaimer ' ,
96
104
'type ' => 'textarea ' ,
97
105
],
106
+ [
107
+ 'label ' => __ ( 'Suppress Ads for All Sponsored Posts ' , 'newspack-sponsors ' ),
108
+ 'value ' => $ defaults ['suppress ' ],
109
+ 'key ' => 'newspack_sponsors_suppress_ads ' ,
110
+ 'type ' => 'checkbox ' ,
111
+ ],
98
112
];
99
113
}
100
114
@@ -166,7 +180,15 @@ public static function newspack_sponsors_settings_callback( $setting ) {
166
180
$ type = $ setting ['type ' ];
167
181
$ value = ( '' !== get_option ( $ key , false ) ) ? get_option ( $ key , false ) : $ setting ['value ' ];
168
182
169
- if ( 'textarea ' === $ type ) {
183
+ if ( 'checkbox ' === $ type ) {
184
+ printf (
185
+ '<input type="checkbox" id="%s" name="%s" %s /> ' ,
186
+ esc_attr ( $ key ),
187
+ esc_attr ( $ key ),
188
+ ! empty ( $ value ) ? 'checked ' : '' ,
189
+ esc_attr ( $ key )
190
+ );
191
+ } elseif ( 'textarea ' === $ type ) {
170
192
printf (
171
193
'<textarea id="%s" name="%s" class="widefat" rows="4">%s</textarea> ' ,
172
194
esc_attr ( $ key ),
0 commit comments