Skip to content

Commit

Permalink
Enqueue the datepicker UI when using a date field in the front-end
Browse files Browse the repository at this point in the history
  • Loading branch information
jom committed Mar 21, 2018
1 parent 4bbd2ba commit d8421b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 1 addition & 5 deletions includes/admin/class-wp-job-manager-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ public function conditional_includes() {
* Enqueues CSS and JS assets.
*/
public function admin_enqueue_scripts() {
global $wp_scripts;

$screen = get_current_screen();

if ( in_array( $screen->id, apply_filters( 'job_manager_admin_screen_ids', array( 'edit-job_listing', 'plugins', 'job_listing', 'job_listing_page_job-manager-settings', 'job_listing_page_job-manager-addons' ) ) ) ) {
$jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';

wp_enqueue_style( 'jquery-ui-style', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', array(), $jquery_version );
wp_enqueue_style( 'jquery-ui' );
wp_enqueue_style( 'job_manager_admin_css', JOB_MANAGER_PLUGIN_URL . '/assets/css/admin.css', array(), JOB_MANAGER_VERSION );
wp_register_script( 'jquery-tiptip', JOB_MANAGER_PLUGIN_URL. '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
wp_enqueue_script( 'job_manager_datepicker_js', JOB_MANAGER_PLUGIN_URL. '/assets/js/datepicker.min.js', array( 'jquery', 'jquery-ui-datepicker' ), JOB_MANAGER_VERSION, true );
Expand Down
3 changes: 2 additions & 1 deletion templates/form-fields/date-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
* @author Automattic
* @package WP Job Manager
* @category Template
* @version 1.30.0
* @version 1.30.2
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

wp_enqueue_script( 'wp-job-manager-datepicker' );
wp_enqueue_style( 'jquery-ui' );

?>
<input type="text" class="input-date job-manager-datepicker" name="<?php echo esc_attr( isset( $field['name'] ) ? $field['name'] : $key ); ?>"<?php if ( isset( $field['autocomplete'] ) && false === $field['autocomplete'] ) { echo ' autocomplete="off"'; } ?> id="<?php echo esc_attr( $key ); ?>" placeholder="<?php echo empty( $field['placeholder'] ) ? '' : esc_attr( $field['placeholder'] ); ?>" value="<?php echo isset( $field['value'] ) ? esc_attr( $field['value'] ) : ''; ?>" <?php if ( ! empty( $field['required'] ) ) echo 'required'; ?> />
Expand Down
12 changes: 12 additions & 0 deletions wp-job-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function __construct() {
add_action( 'after_setup_theme', array( $this, 'load_plugin_textdomain' ) );
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
add_action( 'init', array( $this, 'register_shared_assets' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'admin_init', array( $this, 'updater' ) );
add_action( 'wp_logout', array( $this, 'cleanup_job_posting_cookies' ) );
Expand Down Expand Up @@ -221,6 +222,16 @@ public function cleanup_job_posting_cookies() {
}
}

/**
* Registers assets used in both the frontend and WP admin.
*/
public function register_shared_assets() {
global $wp_scripts;

$jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
wp_register_style( 'jquery-ui', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', array(), $jquery_version );
}

/**
* Registers and enqueues scripts and CSS.
*/
Expand Down Expand Up @@ -338,6 +349,7 @@ public function frontend_scripts() {
wp_register_script( 'wp-job-manager-job-application', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-application.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
wp_register_script( 'wp-job-manager-job-submission', JOB_MANAGER_PLUGIN_URL . '/assets/js/job-submission.min.js', array( 'jquery' ), JOB_MANAGER_VERSION, true );
wp_localize_script( 'wp-job-manager-ajax-filters', 'job_manager_ajax_filters', $ajax_data );

wp_localize_script( 'wp-job-manager-job-dashboard', 'job_manager_job_dashboard', array(
'i18n_confirm_delete' => __( 'Are you sure you want to delete this listing?', 'wp-job-manager' ),
) );
Expand Down

0 comments on commit d8421b3

Please sign in to comment.