Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ef_week_first_day as script data to prevent echoing script tags #582

Merged
merged 2 commits into from Jan 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions common/php/class-module.php
Expand Up @@ -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 "<script type=\"text/javascript\">var ef_week_first_day=\"" . get_option( 'start_of_week' ) . "\";</script>";

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' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use wp_json_encode here? I've got a similar PR which I based off a suggestion from some VIP documentation

Other than that, tested it and it looks good to go!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! TIL that function's not just for objects 馃檪


// 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' );
Expand Down