esc_js()
is intended for escaping data for use within an HTML attribute.
If you want to escape data for use within an inline script, wp_json_encode()
should be sufficient.
For example:
var disabledDays = <?php echo wp_json_encode( $iva_disable_days ); ?>;
This outputs:
var disabledDays = ["4\/7\/2018","11\/18\/2017"];
If you check the variable in your dev tools console, you will see that it is being parsed correctly:
However – if you absolutely do not want escaped slashes (not recommended), the second param to wp_json_encode()
is a bitmask of options:
var disabledDays = <?php echo wp_json_encode( $iva_disable_days, JSON_UNESCAPED_SLASHES ); ?>;
This outputs:
var disabledDays = ["4/7/2018","11/18/2017"];
For a list of available options, check the PHP json_encode()
docs.
Related Posts:
- Data Validation: Always escape late / escape HTML Code
- Multiple register settings, with same option name – issue
- Best Practice for Validating and Sanitizing Data
- Data sanitization for user registration and user login
- What data sanitzation function should be used to store entire source code of webpage?
- Why the WP Core team does not allow filter_* functions? [closed]
- confused about sanitize_email after is_email [duplicate]
- Output Sanitation
- Validating input using java.util.Scanner
- What is the actual minimum length of an email address as defined by the IETF?
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- Sanitize and data validation with apply_filters() function
- How to properly validate data from $_GET or $_REQUEST using WordPress functions?
- is_email() VS sanitize_email()
- Server side validation
- Shortcode putting html such as
- How do I sanitize a javascript text?
- Does wp_insert_post validate the input?
- WordPress oEmbed W3C Validation
- How to Remove novalidate attribute from comment form
- What is wp_check_invalid_utf8?
- Data Validation
- Inconsistent server code response using HTTP API
- wordpress site validation errors
- vs WordPress Security
- Data validation
- Who is responsible for data sanitization in WordPress development?
- Settings API – sanitize_callback is not called and it leads to an incorrect behavior
- ACF Custom validation message not showing up
- What is the proper way to validate and sanitize JSON response from REST API?
- Does balanceTags() provide any escaping / protection?
- w3c validation problem – Twitter share button pulling content
- wp_remote_post – handling responses
- Prevent invalid or empty values from being saved to the database and retain the form field values upon error
- Unable to sanitize in customizer and escape in theme without removing ability for user to use “< br >” to insert a line break
- protect user submitted posts
- Settings API – getting hidden input / submit button’s name
- Require user to input code from an array of allowed codes with Gravity Forms [closed]
- How WordPress sanitizes post content on save? Or it doesn’t?
- Safely store code(html/js..) into database
- WordPress live, custom text box validation, how to?
- How to do more than one verify_nonce in one function?
- W3C validation errors (trailing slashes)
- How to save Checkbox-Options in Plugin Options Page
- Data Validation & Sanitization for Big HTML Blocks
- Jquery Validation Engine with Conatct Form 7
- Form Sanitization and Validation
- Gravity Forms validate arrival and departure
- Why is my script’s regex having its backslash removed?
- Proper Way to Sanitize Meta Input
- Validation Always Tells There Is an Open DIV
- Settings api sanatize callback not being triggered
- How long does plugin review usually take?
- WP calendar summary attribute validation error
- How to use esc_attr__() function properly to translate a variable that contains string?
- oneOf two possible objects in WP REST API?
- how to sanitizing $_POST with the correct way?
- How can I validate an email address using a regular expression?
- what is a parse error and how do I fix it
- ChangeDate – Date Picker Bootstrap
- Validate date in dd/mm/yyyy format using JQuery Validate
- How can I check if a string is a valid number?
- Check if inputs are empty using jQuery
- jQuery UI ” $(“#datepicker”).datepicker is not a function”
- Is sanitize_title enough to generate post slugs?
- When to use esc_html and when to use sanitize_text_field?
- Settings API – sanitizing urls, email addresses and text
- Does WordPress sanitize arguments to WP_Query?
- How to properly sanitize strings without $wpdb->prepare?
- Is there an equivalent of the PHP function sanitize_key in Gutenberg?
- stray elements
- Restrict user registration to emails on a single domain
- Creating custom AJAX requests
- Sanitizing and validating email field
- How to sanitize post meta field value?
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Change filename during upload
- Preserve old values on error in setting API
- jquery.validation.js is not working in woocommerce checkout page form
- Contact Form 7: Make field required after checkbox is checked
- What is the safe way to print tracking code / pixel code before tag or tag
- Stop saving process when metabox is invalid [duplicate]
- html element to separate php variable strings – ACF datepicker
- What’s the proper way to sanitize checkbox value sent to the database
- How to escape multiple attribute at once in WordPress?
- Can A Post Meta Field Store multiple values that are not in an array?
- esc_attr on get_post_meta [closed]
- Using esc_url_raw with protocols properly
- Remember form field values with page navigation
- Data Validation in wordpress
- how to make wordpress plugin from PersianWebToolkit? [closed]
- datepicker value in mysql
- Remove border attribute from Pin It Button image to pass HTML5 validation [closed]
- Verify Submitted Form Values and Show Warning Messages with Setting API
- settings api and the data passed in the parameter
- wp_enqueue_script jquery and jquery ui not working
- Contact form – problem with displaying message about sent mail
- Plugin option for input box validation
- Conditional required fields for WordPress Contact Form 7
- Validate user meta and redirect