0

I have a warning via WordPress Themecheck plugin WARNING : Found a translation function that is missing a text-domain. Function esc_html__, with the arguments

As you can see, there is no arguments listed above and I'm really lost on this.

Here's the code function:

<?php 

    wp_nonce_field( basename( __FILE__ ), 'matilda_featured_image_nonce' );

    $selected = esc_html__( get_post_meta( $object->ID, 'matilda_featured_image', true ) );

?>

My text domain is "matilda"

Thanks for any suggestion.

2 Answers 2

1

Seems like the right thing to do there is to call esc_html instead of esc_html__. I have a feeling you don't need any escaping there at all.

0
1

If you want to add the textdomain to your esc_html__() function, do it like this:

$selected = esc_html__( get_post_meta( $object->ID, 'matilda_featured_image', true ), 'matilda' );

So far so good, but this is a complicated matter, as you pass a variable to your translation function.

Be sure to have a limited set of possible data for this field, and have those strings somewhere in your theme. For example, if you have a <select> in a metabox, you could do it like that:

<select name="matilda_featured_image">
    <option value="<?php _e( 'valueone', 'matilda' ); ?>"><?php _e( 'valueone', 'matilda' ); ?></option>
    <option value="<?php _e( 'valuetwo', 'matilda' ); ?>"><?php _e( 'valuetwo', 'matilda' ); ?></option>
</select>

This way you ensure that all the possible values are registered in your translation.

As @MarkKaplun pointed out, you may not need translation in your case whatsoever :)

1
  • I'm sure your method works too but I prefer @MarkKaplun solution. Thanks anyway.
    – Knott
    Commented Feb 25, 2016 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.