From eecbf3787b6b8000e74f4f1a690b90566044bb4a Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 22 Jan 2020 13:14:29 -0500 Subject: [PATCH 1/2] Add `ef_week_first_day` as script data to prevent echoing script tags This attaches the `var` definition to the script itself, so it will only output when the script tag is actually printed, rather than just enqueued. --- common/php/class-module.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/php/class-module.php b/common/php/class-module.php index 5bd251057..78ee414b9 100644 --- a/common/php/class-module.php +++ b/common/php/class-module.php @@ -205,14 +205,12 @@ function filter_posts_link( $slug, $post_type = 'post' ) { */ function enqueue_datepicker_resources() { - // Add the first day of the week as an available variable to wp_head - echo ""; - wp_enqueue_script( 'jquery-ui-datepicker' ); //Timepicker needs to come after jquery-ui-datepicker and jquery wp_enqueue_script( 'edit_flow-timepicker', EDIT_FLOW_URL . 'common/js/jquery-ui-timepicker-addon.js', array( 'jquery', 'jquery-ui-datepicker' ), EDIT_FLOW_VERSION, true ); wp_enqueue_script( 'edit_flow-date_picker', EDIT_FLOW_URL . 'common/js/ef_date.js', array( 'jquery', 'jquery-ui-datepicker', 'edit_flow-timepicker' ), EDIT_FLOW_VERSION, true ); + wp_add_inline_script( 'edit_flow-date_picker', sprintf( 'var ef_week_first_day = \'%s\';', esc_attr( get_option( 'start_of_week' ) ) ), 'before' ); // Now styles wp_enqueue_style( 'jquery-ui-datepicker', EDIT_FLOW_URL . 'common/css/jquery.ui.datepicker.css', array( 'wp-jquery-ui-dialog' ), EDIT_FLOW_VERSION, 'screen' ); From 3499d83cf723530087ee85bcbe941500cc8200de Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 23 Jan 2020 11:07:35 -0500 Subject: [PATCH 2/2] Use `wp_json_encode` to escape variable --- common/php/class-module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/php/class-module.php b/common/php/class-module.php index 78ee414b9..0d7231d66 100644 --- a/common/php/class-module.php +++ b/common/php/class-module.php @@ -210,7 +210,7 @@ function enqueue_datepicker_resources() { //Timepicker needs to come after jquery-ui-datepicker and jquery wp_enqueue_script( 'edit_flow-timepicker', EDIT_FLOW_URL . 'common/js/jquery-ui-timepicker-addon.js', array( 'jquery', 'jquery-ui-datepicker' ), EDIT_FLOW_VERSION, true ); wp_enqueue_script( 'edit_flow-date_picker', EDIT_FLOW_URL . 'common/js/ef_date.js', array( 'jquery', 'jquery-ui-datepicker', 'edit_flow-timepicker' ), EDIT_FLOW_VERSION, true ); - wp_add_inline_script( 'edit_flow-date_picker', sprintf( 'var ef_week_first_day = \'%s\';', esc_attr( get_option( 'start_of_week' ) ) ), 'before' ); + wp_add_inline_script( 'edit_flow-date_picker', sprintf( 'var ef_week_first_day = %s;', wp_json_encode( get_option( 'start_of_week' ) ) ), 'before' ); // Now styles wp_enqueue_style( 'jquery-ui-datepicker', EDIT_FLOW_URL . 'common/css/jquery.ui.datepicker.css', array( 'wp-jquery-ui-dialog' ), EDIT_FLOW_VERSION, 'screen' );