From 324fbc3fb26ddda95913c84e2ef309b043bc42c8 Mon Sep 17 00:00:00 2001 From: Florian Brinkmann Date: Fri, 2 Jun 2023 08:43:44 +0200 Subject: [PATCH] chore: add ISO codes link to country spam labels, refs #500 --- src/Admin/Fields/Checkbox.php | 2 +- src/Admin/Fields/Field.php | 16 +++++++++++++++- src/Admin/Fields/Text.php | 2 +- src/Admin/Fields/Textarea.php | 7 ++++--- src/Rules/CountrySpam.php | 25 +++++++++++++++++++++++-- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/Admin/Fields/Checkbox.php b/src/Admin/Fields/Checkbox.php index f8a6e7da..9cc10768 100644 --- a/src/Admin/Fields/Checkbox.php +++ b/src/Admin/Fields/Checkbox.php @@ -20,7 +20,7 @@ public function render() { $label = ! empty( $this->get_label() ) ? sprintf( '', esc_attr( $this->get_name() ), - esc_html( $this->get_label() ) + $this->get_label() ) : ''; printf( diff --git a/src/Admin/Fields/Field.php b/src/Admin/Fields/Field.php index 33b33f3c..cf21136f 100644 --- a/src/Admin/Fields/Field.php +++ b/src/Admin/Fields/Field.php @@ -64,7 +64,21 @@ public function get_name() { * @return string Label of the field. */ public function get_label() { - return isset( $this->option['label'] ) ? $this->option['label'] : ''; + $kses = (array) isset( $this->option['label_kses'] ) ? $this->option['label_kses'] : []; + $label = isset( $this->option['label'] ) ? $this->option['label'] : ''; + if ( ! $kses ) { + return esc_html( $label ); + } + return wp_kses( $label, $kses ); + } + + /** + * Get placeholder. + * + * @return string + */ + public function get_placeholder() { + return isset( $this->option['placeholder'] ) ? $this->option['placeholder'] : ''; } /** diff --git a/src/Admin/Fields/Text.php b/src/Admin/Fields/Text.php index a67605b5..b3d4bc7b 100644 --- a/src/Admin/Fields/Text.php +++ b/src/Admin/Fields/Text.php @@ -27,7 +27,7 @@ public function render() { printf( '

%s

', esc_attr( $this->get_name() ), - esc_html( $this->get_label() ), + $this->get_label(), $this->get_injectable_markup() ); $this->maybe_show_description(); diff --git a/src/Admin/Fields/Textarea.php b/src/Admin/Fields/Textarea.php index 8d994b8d..8bde6f0a 100644 --- a/src/Admin/Fields/Textarea.php +++ b/src/Admin/Fields/Textarea.php @@ -18,10 +18,11 @@ class Textarea extends Field implements RenderElement { */ public function render() { printf( - '

', + '

', esc_attr( $this->get_name() ), - esc_html( $this->get_label() ), - esc_html( $this->get_value() ) + $this->get_label(), + esc_html( $this->get_value() ), + esc_attr( $this->get_placeholder() ) ); $this->maybe_show_description(); } diff --git a/src/Rules/CountrySpam.php b/src/Rules/CountrySpam.php index 2c71ecc1..834c93d8 100644 --- a/src/Rules/CountrySpam.php +++ b/src/Rules/CountrySpam.php @@ -146,10 +146,21 @@ public static function get_description() { } public static function get_options() { + $iso_codes_link = 'https://www.iso.org/obp/ui/#search/code/'; return [ [ 'type' => 'textarea', - 'label' => __( 'Denied ISO country codes for this option.', 'antispam-bee' ), + 'label' => sprintf( /* translators: 1=opening link tag to ISO codes list, 2=closing link tag. */ + __( 'Denied %1$sISO country codes%2$s for this option.', 'antispam-bee' ), + "", + '' + ), + 'label_kses' => [ + 'a' => [ + 'href' => true, + 'target' => true, + ], + ], 'placeholder' => __( 'e.g. BF, SG, YE', 'antispam-bee' ), 'option_name' => 'denied', 'sanitize' => function ( $value ) { @@ -158,7 +169,17 @@ public static function get_options() { ], [ 'type' => 'textarea', - 'label' => __( 'Allowed ISO country codes for this option.', 'antispam-bee' ), + 'label' => sprintf( /* translators: 1=opening link tag to ISO codes list, 2=closing link tag. */ + __( 'Allowed %1$sISO country codes%2$s for this option.', 'antispam-bee' ), + "", + '' + ), + 'label_kses' => [ + 'a' => [ + 'href' => true, + 'target' => true, + ], + ], 'placeholder' => __( 'e.g. BF, SG, YE', 'antispam-bee' ), 'option_name' => 'allowed', 'sanitize' => function ( $value ) {