Моя проблема заключалась в том, что в основном php-файле я добавил в конец файла функцию javascript. Кажется, WordPress перехватывает такую функцию в элементе head. Я экспортировал эту функцию в файл сценария Java.
До:
<?php
/**
* Plugin Name: yyy
* Description: yyy
* Author: yyy
* Author URI: yyy
* Version: yyy
*/
/* many functions here */
function insert_in_header() {
echo '<script type="text/javascript">',
"perform_redirection(", '"', get_option('root'), '"', ", ", '"', get_option('redirect_to'), '");',
'</script>';
}
add_action('wp_head', 'insert_in_header');
?>
<--! PROBLEMS HERE-->
<script type = "text/javascript">
function perform_redirections(root, redirectionLink) {
// code here
}
</script>
После того, как:
<?php
/**
* Plugin Name: yyy
* Description: yyy
* Author: yyy
* Author URI: yyy
* Version: yyy
*/
/* many functions here */
function insert_in_header() {
// in headscripts.js i put the perform_redirection function
echo '<script type="text/javascript" src="', plugins_url('js/headscripts.js', __FILE__ ), '"> </script>';
echo '<script type="text/javascript">',
"perform_redirection(", '"', get_option('root'), '"', ", ", '"', get_option('redirect_to'), '");',
'</script>';
}
add_action('wp_head', 'insert_in_header');
?>