Bxcft_Field_Type_Datepicker

The BuddyPress Xprofile Custom Fields Type Bxcft Field Type Datepicker class.

Defined (1)

The class is defined in the following location(s).

/classes/Bxcft_Field_Type_Datepicker.php  
  1. class Bxcft_Field_Type_Datepicker extends BP_XProfile_Field_Type 
  2. public function __construct() { 
  3. parent::__construct(); 
  4.  
  5. $this->name = _x( 'Datepicker (HTML5 field)', 'xprofile field type', 'bxcft' ); 
  6.  
  7. $this->set_format( '/^\d{4}-\d{1, 2}-\d{1, 2}$/', 'replace' ); // "Y-m-d 00:00:00" 
  8. do_action( 'bp_xprofile_field_type_datepicker', $this ); 
  9.  
  10. public function admin_field_html (array $raw_properties = array ()) 
  11. $html = $this->get_edit_field_html_elements( array_merge( 
  12. array( 'type' => 'date' ),  
  13. $raw_properties 
  14. ) ); 
  15. ?> 
  16. <input <?php echo $html; ?> /> 
  17. <?php 
  18.  
  19. public function edit_field_html (array $raw_properties = array ()) 
  20. if ( isset( $raw_properties['user_id'] ) ) { 
  21. unset( $raw_properties['user_id'] ); 
  22.  
  23. // HTML5 required attribute. 
  24. if ( bp_get_the_profile_field_is_required() ) { 
  25. $raw_properties['required'] = 'required'; 
  26.  
  27. $html = $this->get_edit_field_html_elements( array_merge( 
  28. array( 
  29. 'type' => 'date',  
  30. 'value' => bp_get_the_profile_field_edit_value(),  
  31. ),  
  32. $raw_properties 
  33. ) ); 
  34.  
  35. $label = sprintf( 
  36. '<label for="%s">%s%s</label>',  
  37. bp_get_the_profile_field_input_name(),  
  38. bp_get_the_profile_field_name(),  
  39. (bp_get_the_profile_field_is_required()) ? 
  40. ' ' . esc_html__( '(required)', 'buddypress' ) : '' 
  41. ); 
  42. // Label. 
  43. echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required()); 
  44. // Errors. 
  45. do_action( bp_get_the_profile_field_errors_action() ); 
  46. // Input. 
  47. ?> 
  48. <input <?php echo $html; ?> /> 
  49. <?php 
  50.  
  51. public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 
  52.  
  53. /** 
  54. * Modify the appearance of value. Apply autolink if enabled. 
  55. * @param string $value Original value of field 
  56. * @param int $field_id Id of field 
  57. * @return string Value formatted 
  58. */ 
  59. public static function display_filter($field_value, $field_id = '') { 
  60.  
  61. $new_field_value = $field_value; 
  62.  
  63. if (!empty($field_value)) { 
  64. $new_field_value = date_i18n(get_option('date_format'),  
  65. strtotime($field_value)); 
  66.  
  67. if (!empty($field_id)) { 
  68. $field = BP_XProfile_Field::get_instance($field_id); 
  69. if ($field) { 
  70. $do_autolink = apply_filters('bxcft_do_autolink',  
  71. $field->get_do_autolink()); 
  72. if ($do_autolink) { 
  73. $query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  74. $search_url = add_query_arg( array( $query_arg => urlencode( $field_value ) ),  
  75. bp_get_members_directory_permalink() ); 
  76. $new_field_value = '<a href="' . esc_url( $search_url ) . 
  77. '" rel="nofollow">' . $new_field_value . '</a>'; 
  78.  
  79. /** 
  80. * 'bxcft_datepicker_display_filter' 
  81. * Use this filter to modify the appearance of Color 
  82. * field value. 
  83. * @param $value Value 
  84. * @param $field_id Id of field 
  85. * @return Filtered value of field 
  86. */ 
  87. return apply_filters('bxcft_datepicker_display_filter', $new_field_value,  
  88. $field_id);