I'm using Bitbucket and have Scrutinizer configured to analyze code when uploaded. It complains about a variable not being declared and it causes a hit on code grading.
The variable txtVars seems to be never declared. If this is a global, consider adding a /** global: txtVars */ comment.
This makes sense to me as I am using the variable in my jQuery without it being declared in any way except for in my WordPress functions.php file:
txtVars
is introduced with the following PHP:
wp_enqueue_script( 'my-script',
MY_URL . 'assets/js/public.js',
array('jquery', 'heartbeat'),
MY_VERSION,
true
);
$vars = array(
'confirm_submit' => __( 'Submit', 'textdomain' ),
'confirm_cancel' => __( 'Cancel', 'textdomain' )
);
wp_localize_script( 'my-script', 'txtVars', $vars );
This allows me to use txtVars
in the jQuery script:
confirm(txtVars.confirm_submit);
I've tried declaring txtVars
a few different ways within the jQuery but it doesn't help, it generates an error, or txtVars
ends up empty.
Is there a way to declare this variable in jQuery to satisfy code checkers that expect variables to be declared?