@@ -86,6 +86,7 @@ public function __construct() {
8686 add_action ( 'widgets_init ' , [ $ this , 'widgets_init ' ] );
8787 add_action ( 'wp_loaded ' , [ $ this , 'register_shared_assets ' ] );
8888 add_action ( 'wp_enqueue_scripts ' , [ $ this , 'frontend_scripts ' ] );
89+ add_action ( 'wp_footer ' , [ $ this , 'maybe_localize_jquery_ui_datepicker ' ], 1 );
8990 add_action ( 'admin_init ' , [ $ this , 'updater ' ] );
9091 add_action ( 'admin_init ' , [ $ this , 'add_privacy_policy_content ' ] );
9192 add_action ( 'wp_logout ' , [ $ this , 'cleanup_job_posting_cookies ' ] );
@@ -251,6 +252,9 @@ public function register_shared_assets() {
251252
252253 $ jquery_version = isset ( $ wp_scripts ->registered ['jquery-ui-core ' ]->ver ) ? $ wp_scripts ->registered ['jquery-ui-core ' ]->ver : '1.9.2 ' ;
253254 wp_register_style ( 'jquery-ui ' , '//code.jquery.com/ui/ ' . $ jquery_version . '/themes/smoothness/jquery-ui.min.css ' , [], $ jquery_version );
255+
256+ // Register datepicker JS. It will be enqueued if needed when a date field is used.
257+ wp_register_script ( 'wp-job-manager-datepicker ' , JOB_MANAGER_PLUGIN_URL . '/assets/js/datepicker.min.js ' , [ 'jquery ' , 'jquery-ui-datepicker ' ], JOB_MANAGER_VERSION , true );
254258 }
255259
256260 /**
@@ -261,6 +265,21 @@ public static function register_select2_assets() {
261265 wp_register_style ( 'select2 ' , JOB_MANAGER_PLUGIN_URL . '/assets/js/select2/select2.min.css ' , [], '4.0.10 ' );
262266 }
263267
268+ /**
269+ * WordPress localizes this script late in `wp_head`. We sometimes enqueue the datepicker later on.
270+ *
271+ * @access private
272+ * @since 1.34.1
273+ */
274+ public function maybe_localize_jquery_ui_datepicker () {
275+ // Check if this data has already been added. Prevents outputting localization data multiple times.
276+ if ( wp_scripts ()->get_data ( 'jquery-ui-datepicker ' , 'after ' ) ) {
277+ return ;
278+ }
279+
280+ wp_localize_jquery_ui_datepicker ();
281+ }
282+
264283 /**
265284 * Registers and enqueues scripts and CSS.
266285 *
0 commit comments