wordpress is adding a second backslash when I use addslashes

In your code json_encode() function causes to add second backslash on the following line. $data = json_encode($item_data); Add the following code in place of above code so it will replace double backslashes with single backslash in data returned by json_encode function. $data = str_replace(“\\\'”,”\\'”,json_encode($item_data )); Visit following links for more information on json_encode function. json_encode … Read more

What’s the proper way to sanitize checkbox value sent to the database

I would use the filter_var() function. It has some predefined filters that you can use depending on what kind of data you are expecting such as string, number, etc. So to sanitize for a number: $sanitizedNum = filter_var($yourVar, FILTER_SANITIZE_NUMBER_INT); For a string you would just change “_NUM_INT” to “_STRING”. Wrap those in a custom function … Read more

Escaping date string in url with wordpress

strtotime will return false if you give it weird information. echo strtotime(“<script>’); // bool(false) However, if you do what you are doing and nest two statement you may not get what you expect. echo strtotime(‘+1 day’,strtotime(‘<script>’)); // int(86400) And date returns the beginning of the universe, the day of creation– January 1, 1970– if given … Read more

Getting error to display radio button value in General Settings page

Apart from the isset issue, pointed by Rarst, there’s an error in the sanitization function. esc_attr seems not to work with radio buttons, using esc_sql does the job. You’re also missing the checked state for the buttons: add_filter( ‘admin_init’, ‘myservice_register_function’ ); function myservice_register_function() { register_setting( ‘general’, ‘my_service’, ‘esc_sql’ ); add_settings_field( ‘my_service’, ‘<label for=”service_need”>’.__(‘Do You need … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)