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?
- Simple way to alert error messages in Javascript
- How can I validate an email address using a regular expression?
- Good input validation loop using cin – C++
- How can I validate an email address using a regular expression?
- Reactjs – Form input validation
- How to validate an email address in JavaScript
- XAML Binding Groups
- “Stray start tag footer” in html validator?
- A potentially dangerous Request.Form value was detected from the client
- WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery
- Email validation using jQuery
- How to test valid UUID/GUID?
- what is a parse error and how do I fix it
- Server-side schema validation with JAX-WS
- ChangeDate – Date Picker Bootstrap
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- Validating IPv4 addresses with regexp
- what is a good method to sanitize the whole $_POST array in php?
- An invalid form control with name=” is not focusable
- Validate date in dd/mm/yyyy format using JQuery Validate
- How can I check if a string is a valid number?
- HTML5 Validation Error: body start tag seen but an element of the same type was already open
- How can I check if a single character appears in a string?
- What is jQuery Unobtrusive Validation?
- jQuery Form Validation before Ajax submit
- Contact Form 7 – Custom Validation
- How does the SQL injection from the “Bobby Tables” XKCD comic work?
- jQuery datepicker set selected date, on the fly
- Hapi/Joi Validation: How to process text to a specific format
- What is the best Java email address validation method?
- Check if inputs are empty using jQuery
- How to use date picker in Angular 2?
- ZIP Code (US Postal Code) validation
- A non well formed numeric value encountered
- jQuery UI ” $(“#datepicker”).datepicker is not a function”
- Displaying DateTime picker instead of Date picker in ASP .NET MVC 5.1/HTML 5 specific
- validate textfield contents in wordpress simple job board plugin
- Is sanitize_title enough to generate post slugs?
- Remove type attribute from script and style tags added by WordPress
- wordpress sanitize array?
- Data sanitization: Best Practices with code examples
- Should I sanitize an email address before passing it to the is_email() function?
- don’t publish custom post type post if a meta data field isn’t valid