plechev

rangedate

Aug 31st, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. add_filter( 'rcl_fields', 'add_field_type_rangedate' );
  2. function add_field_type_rangedate( $fields ) {
  3.  
  4.     $fields['rangedate'] = array(
  5.         'label'  => __( 'Диапазон дат' ),
  6.         'class'  => 'Rcl_Field_RangeDate'
  7.     );
  8.  
  9.     return $fields;
  10. }
  11.  
  12. class Rcl_Field_RangeDate extends Rcl_Field_Abstract {
  13.  
  14.     public $required;
  15.     public $placeholder_from;
  16.     public $placeholder_to;
  17.  
  18.     function __construct( $args ) {
  19.         parent::__construct( $args );
  20.     }
  21.  
  22.     function get_options() {
  23.  
  24.         return array(
  25.             array(
  26.                 'slug'           => 'icon',
  27.                 'default'        => 'fa-calendar',
  28.                 'placeholder'    => 'fa-calendar',
  29.                 'class'          => 'rcl-iconpicker',
  30.                 'type'           => 'text',
  31.                 'title'          => __( 'Icon class of  font-awesome', 'wp-recall' ),
  32.                 'notice'         => __( 'Source', 'wp-recall' ) . ' <a href="https://fontawesome.com/v4.7.0/icons/" target="_blank">http://fontawesome.io/</a>'
  33.             ),
  34.             array(
  35.                 'slug'       => 'placeholder_from',
  36.                 'default'    => $this->placeholder_from,
  37.                 'type'       => 'text',
  38.                 'title'      => __( 'Placeholder from', 'wp-recall' )
  39.             ),
  40.             array(
  41.                 'slug'       => 'placeholder_to',
  42.                 'default'    => $this->placeholder_to,
  43.                 'type'       => 'text',
  44.                 'title'      => __( 'Placeholder to', 'wp-recall' )
  45.             )
  46.         );
  47.     }
  48.  
  49.     function get_placeholder( $type = 'from' ) {
  50.  
  51.         if ( $type == 'from' && $this->placeholder_from ) {
  52.             return 'placeholder="' . $this->placeholder_from . '"';
  53.         } else if ( $type == 'to' && $this->placeholder_to ) {
  54.             return 'placeholder="' . $this->placeholder_to . '"';
  55.         }
  56.  
  57.         return;
  58.     }
  59.  
  60.     function get_input() {
  61.  
  62.         rcl_datepicker_scripts();
  63.  
  64.         $this->classes = 'rcl-datepicker';
  65.  
  66.         $content .= '<input type="text" ' . $this->get_class() . ' onclick="rcl_show_datepicker(this);" title="' . __( 'Use the format', 'wp-recall' ) . ': yyyy-mm-dd" pattern="(\d{4}-\d{2}-\d{2})" ' . $this->get_required() . ' ' . $this->get_placeholder( 'from' ) . ' name="' . $this->input_name . '[]" id="' . $this->input_id . '_from" value="' . $this->value[0] . '"/>';
  67.         $content .= ' - ';
  68.         $content .= '<input type="text" ' . $this->get_class() . ' onclick="rcl_show_datepicker(this);" title="' . __( 'Use the format', 'wp-recall' ) . ': yyyy-mm-dd" pattern="(\d{4}-\d{2}-\d{2})" ' . $this->get_required() . ' ' . $this->get_placeholder( 'to' ) . ' name="' . $this->input_name . '[]" id="' . $this->input_id . '_to" value="' . $this->value[1] . '"/>';
  69.  
  70.         return $content;
  71.     }
  72.  
  73. }
Add Comment
Please, Sign In to add comment