Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. function wp_localize_jquery_ui_datepicker() {
  2.     global $wp_locale;
  3.  
  4.     if ( wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
  5.         return;
  6.     }
  7.  
  8.     // Convert the PHP date format into jQuery UI's format.
  9.     $datepicker_date_format = str_replace(
  10.         array(
  11.             'd', 'j', 'l', 'z', // Day.
  12.             'F', 'M', 'n', 'm', // Month.
  13.             'Y', 'y'            // Year.
  14.         ),
  15.         array(
  16.             'dd', 'd', 'DD', 'o',
  17.             'MM', 'M', 'm', 'mm',
  18.             'yy', 'y'
  19.         ),
  20.         get_option( 'date_format' )
  21.     );
  22.  
  23.     $datepicker_defaults = wp_json_encode( array(
  24.         'closeText'       => __( 'Close' ),
  25.         'currentText'     => __( 'Today' ),
  26.         'monthNames'      => array_values( $wp_locale->month ),
  27.         'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
  28.         'nextText'        => __( 'Next' ),
  29.         'prevText'        => __( 'Previous' ),
  30.         'dayNames'        => array_values( $wp_locale->weekday ),
  31.         'dayNamesShort'   => array_values( $wp_locale->weekday_abbrev ),
  32.         'dayNamesMin'     => array_values( $wp_locale->weekday_initial ),
  33.         'dateFormat'      => $datepicker_date_format,
  34.         'firstDay'        => absint( get_option( 'start_of_week' ) ),
  35.         'isRTL'           => $wp_locale->is_rtl(),
  36.     ) );
  37.  
  38.     wp_enqueue_script( 'jquery-ui-datepicker', '/jquery-ui-datepicker-custom.js', array(), '1.0' );
  39.     wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" );
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement