diff --git a/includes/class-settings.php b/includes/class-settings.php index 6fc1ab1..dabfa37 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -150,11 +150,13 @@ class Settings extends SCLiveticker { * @since 1.3.0 moved from Admin to Settings class */ public static function settings_enable_ajax_field(): void { - $checked = self::$options['enable_ajax']; - - echo ' '; - esc_html_e( 'Enable', 'stklcode-liveticker' ); - echo '
' . esc_html__( 'Disable this option to not use AJAX update. This means all liveticker widgets and shortcodes are only updated once on site load.', 'stklcode-liveticker' ) . '
'; + self::render_checkbox( + 'enable-ajax', + '[enable_ajax]', + self::$options['enable_ajax'], + __( 'Disable this option to not use AJAX update. This means all liveticker widgets and shortcodes are only updated once on site load.', 'stklcode-liveticker' ), + __( 'Enable AJAX updates', 'stklcode-liveticker' ) + ); } /** @@ -183,11 +185,13 @@ class Settings extends SCLiveticker { * @since 1.3.0 moved from Admin to Settings class */ public static function settings_enable_css_field(): void { - $checked = self::$options['enable_css']; - - echo ' '; - esc_html_e( 'Enable', 'stklcode-liveticker' ); - echo '' . esc_html__( 'Disable this option to remove the default styling CSS file.', 'stklcode-liveticker' ) . '
'; + self::render_checkbox( + 'enable-css', + '[enable_css]', + self::$options['enable_css'], + __( 'Disable this option to remove the default styling CSS file.', 'stklcode-liveticker' ), + __( 'Enable default stylesheet', 'stklcode-liveticker' ) + ); } /** @@ -199,11 +203,13 @@ class Settings extends SCLiveticker { * @since 1.3.0 moved from Admin to Settings class */ public static function settings_show_feed_field(): void { - $checked = self::$options['show_feed']; - - echo ' '; - esc_html_e( 'Enable', 'stklcode-liveticker' ); - echo '' . esc_html__( 'Can be overwritten in shortcode.', 'stklcode-liveticker' ) . '
'; + self::render_checkbox( + 'show-feed', + '[show_feed]', + self::$options['show_feed'], + __( 'Can be overwritten in shortcode.', 'stklcode-liveticker' ), + __( 'Show RSS feed in shortcode', 'stklcode-liveticker' ) + ); } /** @@ -215,11 +221,13 @@ class Settings extends SCLiveticker { * @since 1.3.0 moved from Admin to Settings class */ public static function settings_enable_shortcode_field(): void { - $checked = self::$options['enable_shortcode']; - - echo ' '; - esc_html_e( 'Enable', 'stklcode-liveticker' ); - echo '' . esc_html__( 'Enable shortcode processing in tick content.', 'stklcode-liveticker' ) . '
'; + self::render_checkbox( + 'enable-shortcode', + '[enable_shortcode]', + self::$options['enable_shortcode'], + __( 'Enable shortcode processing in tick content.', 'stklcode-liveticker' ), + __( 'Allow shortcodes in tick content', 'stklcode-liveticker' ) + ); } /** @@ -231,11 +239,13 @@ class Settings extends SCLiveticker { * @since 1.3.0 moved from Admin to Settings class */ public static function settings_embedded_script_field(): void { - $checked = self::$options['embedded_script']; - - echo ' '; - esc_html_e( 'Enable', 'stklcode-liveticker' ); - echo '' . esc_html__( 'Allow embedded script evaluation in tick contents. This might be useful for embedded content, e.g. social media integrations.', 'stklcode-liveticker' ) . '
'; + self::render_checkbox( + 'embedded-script', + '[embedded_script]', + self::$options['embedded_script'], + __( 'Allow embedded script evaluation in tick contents. This might be useful for embedded content, e.g. social media integrations.', 'stklcode-liveticker' ), + __( 'Allow JavaScript in tick content', 'stklcode-liveticker' ) + ); } /** @@ -260,4 +270,34 @@ class Settings extends SCLiveticker { return $result; } + + /** + * Render a checkbox field. + * + * @param string $id Field ID. + * @param string $name Option name. + * @param mixed $value Current value. + * @param string $description Description text. + * @param string $screen_reader_text Screen reader text. + * + * @return void + */ + private static function render_checkbox( + string $id, + string $name, + $value, + string $description, + string $screen_reader_text + ) { + ?> + +