I am validating plugin to make it compatible with WPCS
. a function which contains gettext
placeholder returning error when i run phpcs
command. Source code and screenshot of error is attached for reference. Maybe i am missing something or doing it in wrong way?
/**
* Add Error.
*
* @package Mypackage
* @since 0.1.0
*
* @param string $code Error Code.
* @param string $message Error Message.
* @return object WP_Error Returns Error Object.
*/
function mypackage_add_error( $code, $message ) {
/* translators: %s: Error Message */
return new WP_Error( $code, sprintf( esc_html__( '%s', 'mypackage' ), $message ) );
}
return new WP_Error( $code, $message);
– mmm Feb 24 '18 at 21:38mypackage_add_error
? – Anwer AR Feb 24 '18 at 21:42mypackage_add_error
seems somewhat redundant, would it not be easier to just create theWP_Error
object in place rather than callingmypackage_add_error
?mypackage_add_error
is not the place for translation, and%s
is not something to be translated – Tom J Nowell♦ Feb 24 '18 at 21:44WP_Error
every-time which i am still doing inmypackage_add_error
. not sure if its good or bad practice but eventually it was supposed to find a nicer way. so instead of callingWP_Error
directly i wrap it in a function to easily modify in future. so my point of interest is maybe: can we use dynamic strings from variables with translation functions? just like i do with$message
in above function – Anwer AR Feb 24 '18 at 21:55