Skip to content

esc_html__ instead of __ #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions includes/MslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ public function __call( $method, $args ) {
);

if ( isset( $checkboxes[ $method ] ) ) {
echo ( new Group() )->add( new Checkbox( $method, $this->options->$method ) )->add(
new Label(
$method,
$checkboxes[ $method ]
)
)->render();
echo ( new Group() )
->add( new Checkbox( $method, $this->options->$method ) )
->add( new Label( $method, $checkboxes[ $method ] ) )
->render();
} else {
$value = ! empty( $this->options->$method ) ? $this->options->$method : '';
echo ( new Text( $method, $value ) )->render();
Expand All @@ -146,7 +144,7 @@ public function has_problems(): bool {
} elseif ( 1 == count( $this->options->get_available_languages() ) ) {
/* translators: %1$s: URL to a page at WordPress.orgs */
$format = __(
'TNo language files are currently installed. Learn how to install various languages in WordPress by <a href="%1$s">reading more here</a>.',
'No language files are currently installed. Learn how to install various languages in WordPress by <a href="%1$s">reading more here</a>.',
'multisite-language-switcher'
);
$message = sprintf(
Expand Down Expand Up @@ -262,18 +260,18 @@ public function language_section(): int {
*/
public function main_section(): int {
$map = array(
'display' => __( 'Display', 'multisite-language-switcher' ),
'admin_display' => __( 'Admin Display', 'multisite-language-switcher' ),
'sort_by_description' => __( 'Sort languages', 'multisite-language-switcher' ),
'output_current_blog' => __( 'Current language link', 'multisite-language-switcher' ),
'only_with_translation' => __( 'Translation links', 'multisite-language-switcher' ),
'description' => __( 'Description', 'multisite-language-switcher' ),
'before_output' => __( 'Text/HTML before the list', 'multisite-language-switcher' ),
'after_output' => __( 'Text/HTML after the list', 'multisite-language-switcher' ),
'before_item' => __( 'Text/HTML before each item', 'multisite-language-switcher' ),
'after_item' => __( 'Text/HTML after each item', 'multisite-language-switcher' ),
'content_filter' => __( 'Available translations hint', 'multisite-language-switcher' ),
'content_priority' => __( 'Hint priority', 'multisite-language-switcher' ),
'display' => esc_html__( 'Display', 'multisite-language-switcher' ),
'admin_display' => esc_html__( 'Admin Display', 'multisite-language-switcher' ),
'sort_by_description' => esc_html__( 'Sort languages', 'multisite-language-switcher' ),
'output_current_blog' => esc_html__( 'Current language link', 'multisite-language-switcher' ),
'only_with_translation' => esc_html__( 'Translation links', 'multisite-language-switcher' ),
'description' => esc_html__( 'Description', 'multisite-language-switcher' ),
'before_output' => esc_html__( 'Text/HTML before the list', 'multisite-language-switcher' ),
'after_output' => esc_html__( 'Text/HTML after the list', 'multisite-language-switcher' ),
'before_item' => esc_html__( 'Text/HTML before each item', 'multisite-language-switcher' ),
'after_item' => esc_html__( 'Text/HTML after each item', 'multisite-language-switcher' ),
'content_filter' => esc_html__( 'Available translations hint', 'multisite-language-switcher' ),
'content_priority' => esc_html__( 'Hint priority', 'multisite-language-switcher' ),
);

return $this->add_settings_fields( $map, 'main_section' );
Expand All @@ -288,11 +286,11 @@ public function main_section(): int {
*/
public function advanced_section(): int {
$map = array(
'activate_autocomplete' => __( 'Autocomplete', 'multisite-language-switcher' ),
'image_url' => __( 'Custom URL for flag-images', 'multisite-language-switcher' ),
'reference_user' => __( 'Reference user', 'multisite-language-switcher' ),
'exclude_current_blog' => __( 'Exclude blog', 'multisite-language-switcher' ),
'activate_content_import' => __( 'Content import', 'multisite-language-switcher' ),
'activate_autocomplete' => esc_html__( 'Autocomplete', 'multisite-language-switcher' ),
'image_url' => esc_html__( 'Custom URL for flag-images', 'multisite-language-switcher' ),
'reference_user' => esc_html__( 'Reference user', 'multisite-language-switcher' ),
'exclude_current_blog' => esc_html__( 'Exclude blog', 'multisite-language-switcher' ),
'activate_content_import' => esc_html__( 'Content import', 'multisite-language-switcher' ),
);

return $this->add_settings_fields( $map, 'advanced_section' );
Expand Down
18 changes: 9 additions & 9 deletions includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,24 @@ public function get_icon(): string {

switch ( $this->icon_type ) {
case self::TYPE_FLAG:
$icon = sprintf(
$class = ( new IconSvg() )->get( $this->language );
$icon = sprintf(
'<span class="flag-icon %s">%s</span>',
( new IconSvg() )->get( $this->language ),
$this->language
esc_attr( $class ),
esc_html( $this->language )
);
break;
case self::TYPE_LABEL:
$text = ( new IconLabel() )->get( $this->language );
$icon = sprintf(
'<span class="language-badge %s">%s</span>',
$this->language,
( new IconLabel() )->get( $this->language )
esc_attr( $this->language ),
esc_html( $text )
);
break;
default:
$icon = sprintf(
'<span class="dashicons %s"></span>',
empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit'
);
$class = empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit';
$icon = sprintf( '<span class="dashicons %s"></span>', esc_attr( $class ) );
}

return $icon;
Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/TestMslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,17 @@ function test_language_section(): void {
function test_main_section(): void {
$obj = $this->get_sut();

Functions\when( 'add_settings_field' )->returnArg();
Functions\expect( 'add_settings_field' )->times( 12 )->andReturnFirstArg();
Functions\expect( 'esc_html__' )->times( 12 )->andReturnFirstArg();

$this->assertEquals( 12, $obj->main_section() );
}

function test_advanced_section(): void {
$obj = $this->get_sut();

Functions\when( 'add_settings_field' )->returnArg();
Functions\expect( 'add_settings_field' )->times( 5 )->andReturnFirstArg();
Functions\expect( 'esc_html__' )->times( 5 )->andReturnFirstArg();

$this->assertEquals( 5, $obj->advanced_section() );
}
Expand Down
Loading