Skip to content

Commit ed9fa2a

Browse files
committed
✨ Introduce generic checkbox settings field
1 parent 9f7aa08 commit ed9fa2a

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

inc/class-admin-fields.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
class Admin_Fields {
1212
use Singleton;
1313

14+
/**
15+
* Checkbox field callback.
16+
*
17+
* @param array $args The field arguments
18+
*/
19+
public function checkbox( array $args ) {
20+
$settings_name = self::get_settings_name( $args );
21+
$options = Helper::get_option( $settings_name, true );
22+
?>
23+
<label for="<?php echo \esc_attr( $args['label_for'] ); ?>"><input type="checkbox" id="<?php echo \esc_attr( $args['label_for'] ); ?>" name="<?php echo \esc_attr( $settings_name ); ?>[<?php echo \esc_attr( $args['label_for'] ); ?>]" value="1"<?php \checked( isset( $options[ $args['label_for'] ] ) ); ?>>
24+
<?php echo \esc_html( isset( $args['label'] ) ? $args['label'] : '' ); ?>
25+
</label>
26+
<?php
27+
}
28+
1429
/**
1530
* Country field callback.
1631
*
@@ -228,16 +243,22 @@ public function phone( array $args ) {
228243
/**
229244
* Press Law Checkbox field callback.
230245
*
246+
* @deprecated 2.2.0 Use epiphyt\Impressum\Admin_Fields::checkbox() instead
247+
*
231248
* @param array $args The field arguments
232249
*/
233250
public function press_law_checkbox( array $args ) {
234-
$settings_name = self::get_settings_name( $args );
235-
$options = Helper::get_option( $settings_name, true );
236-
?>
237-
<label for="<?php echo \esc_attr( $args['label_for'] ); ?>"><input type="checkbox" id="<?php echo \esc_attr( $args['label_for'] ); ?>" name="<?php echo \esc_attr( $settings_name ); ?>[<?php echo \esc_attr( $args['label_for'] ); ?>]" value="1"<?php \checked( isset( $options[ $args['label_for'] ] ) ); ?>>
238-
<?php \esc_html_e( 'I have journalistic/editorial content on my website', 'impressum' ); ?>
239-
</label>
240-
<?php
251+
\_doing_it_wrong(
252+
__METHOD__,
253+
\sprintf(
254+
/* translators: alternative method */
255+
\esc_html__( 'Use %s instead', 'impressum' ),
256+
'epiphyt\Impressum\Admin_Fields::checkbox()'
257+
),
258+
'2.2.0'
259+
);
260+
261+
self::checkbox( $args );
241262
}
242263

243264
/**

inc/class-impressum.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,12 @@ public function load_settings() {
292292
],
293293
'args' => [
294294
'class' => 'impressum_row impressum_press_law_checkbox',
295+
'label' => \__( 'I have journalistic/editorial content on my website', 'impressum' ),
295296
'label_for' => 'press_law_checkbox',
296297
'required' => false,
297298
'setting' => 'impressum_imprint_options',
298299
],
299-
'callback' => 'press_law_checkbox',
300+
'callback' => 'checkbox',
300301
'no_output' => true,
301302
'page' => 'impressum_imprint',
302303
'section' => 'impressum_section_imprint',

0 commit comments

Comments
 (0)