Insert javascript string into HTML with PHP in WP
<p>I need to create some widget for WP and in widget's setting will be <code>textarea</code>, where user can insert some JS code. And then my widget must inject this code to WP's <code>footer.php</code> with this function:</p>

<pre><code>add_action( 'wp_footer', 'inject_js', 10 );
</code></pre>

<p>In my <code>inject_js</code> I have:</p>

<pre><code>function inject_js () { 

    echo esc_attr( get_option('js_code') );

}
</code></pre>

<p>Everything is working good and the code inserts into HTML, but I faced one problem. In my HTML I get something like this:</p>

<pre><code>&amp;lt;!-- BEGIN JS widget --&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
    var __cp = {
        id: &amp;quot;J4FGckYPdasda21OaTnqo6s7kMgeGXdTBAb6SgXMD-A&amp;quot;
    };
</code></pre>

<p>As I understand I got the code from user's <code>textarea</code> in <code>string</code> type and I must do something with the quotes and other symbols, but I really don't know how to solve this issue, because I am new to PHP.</p>

<p>What PHP function must I use or it's possible to do with some WP functions? </p>

<p>I tried:</p>

<pre><code>echo htmlspecialchars(esc_attr( get_option('js_code') ));
</code></pre>

<p>and</p>

<pre><code>echo addslashes(esc_attr( get_option('js_code') ));
</code></pre>

<p>But nothing helped.</p>