Skip to content

Commit

Permalink
chore: add ISO codes link to country spam labels, refs #500
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbrinkmann committed Jun 2, 2023
1 parent 967f9b8 commit 324fbc3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Admin/Fields/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function render() {
$label = ! empty( $this->get_label() ) ? sprintf(
'<label for="%s">%s</label>',
esc_attr( $this->get_name() ),
esc_html( $this->get_label() )
$this->get_label()
) : '';

printf(
Expand Down
16 changes: 15 additions & 1 deletion src/Admin/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Fields/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function render() {
printf(
'<p><label for="%s">%s</label></p><p>%s</p>',
esc_attr( $this->get_name() ),
esc_html( $this->get_label() ),
$this->get_label(),
$this->get_injectable_markup()
);
$this->maybe_show_description();
Expand Down
7 changes: 4 additions & 3 deletions src/Admin/Fields/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class Textarea extends Field implements RenderElement {
*/
public function render() {
printf(
'<p><label for="%1$s">%2$s</label></p><p><textarea name="%1$s" id="%1$s">%3$s</textarea></p>',
'<p><label for="%1$s">%2$s</label></p><p><textarea name="%1$s" id="%1$s" placeholder="%4$s">%3$s</textarea></p>',
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();
}
Expand Down
25 changes: 23 additions & 2 deletions src/Rules/CountrySpam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
"<a href='{$iso_codes_link}' target='_blank'>",
'</a>'
),
'label_kses' => [
'a' => [
'href' => true,
'target' => true,
],
],
'placeholder' => __( 'e.g. BF, SG, YE', 'antispam-bee' ),
'option_name' => 'denied',
'sanitize' => function ( $value ) {
Expand All @@ -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' ),
"<a href='{$iso_codes_link}' target='_blank'>",
'</a>'
),
'label_kses' => [
'a' => [
'href' => true,
'target' => true,
],
],
'placeholder' => __( 'e.g. BF, SG, YE', 'antispam-bee' ),
'option_name' => 'allowed',
'sanitize' => function ( $value ) {
Expand Down

0 comments on commit 324fbc3

Please sign in to comment.