0

I'm building a simple plugin that allows adding custom scripts to header and footer. Everything seems to work fine, but there is a 'bug'. When I add Google Analytics script to header, it shows with backslashes before apostrophes. I tried:

if ( get_magic_quotes_gpc() ) {
$_POST      = array_map( 'stripslashes_deep', $_POST );
$_GET       = array_map( 'stripslashes_deep', $_GET );
$_COOKIE    = array_map( 'stripslashes_deep', $_COOKIE );
$_REQUEST   = array_map( 'stripslashes_deep', $_REQUEST ); }

but that didn't solve the problem. Any advice?

0

In the documentation page for get_magic_quotes_gpc you can read:

Returns 0 if magic_quotes_gpc is off, 1 otherwise. Or always returns FALSE as of PHP 5.4.0.

I guess this can cause the first problem (that your code not works).

Next stripslashes_deep

You can use code like this:

$_POST = stripslashes_deep( $_POST );

But just check the WordPress docs for the function because you can break functions of the core or other plugins that expect their values slashed.

So it is probably better to work only on your own input vars:

$my_value = stripslashes( $_POST['value'] );
  • Thank you very much. I've implemented the last thing you mentioned: $old_option_header = get_option('onixion_header_scripts'); $temporary_option_add_header = stripslashes($_POST['header_scripts']); $new_option_header = $temporary_option_add_header; $new_option_header .= $old_option_header; update_option('onixion_header_scripts',$new_option_header); – Срђан Станишић Oct 4 '18 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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