Bxcft_Field_Type_Color

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

Defined (1)

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

/classes/Bxcft_Field_Type_Color.php  
  1. class Bxcft_Field_Type_Color extends BP_XProfile_Field_Type 
  2. public function __construct() { 
  3. parent::__construct(); 
  4.  
  5. $this->name = _x( 'Color (HTML5 field)', 'xprofile field type', 'bxcft' ); 
  6.  
  7. $this->set_format( '/^.+$/', 'replace' ); 
  8. do_action( 'bp_xprofile_field_type_color', $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' => 'color' ),  
  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' => 'color',  
  30. 'value' => bp_get_the_profile_field_edit_value(),  
  31. ),  
  32. $raw_properties 
  33. ) ); 
  34. ?> 
  35. <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label> 
  36. <?php do_action( bp_get_the_profile_field_errors_action() ); ?> 
  37. <input <?php echo $html; ?>> 
  38. <script> 
  39. if (!Modernizr.inputtypes.color) { 
  40. // No html5 field colorpicker => Calling jscolor. 
  41. jQuery('input#<?php bp_the_profile_field_input_name() ?>').addClass('color'); 
  42. </script> 
  43. <?php 
  44.  
  45. public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 
  46.  
  47. /** 
  48. * Modify the appearance of value. Apply autolink if enabled. 
  49. * @param string $value Original value of field 
  50. * @param int $field_id Id of field 
  51. * @return string Value formatted 
  52. */ 
  53. public static function display_filter($field_value, $field_id = '') { 
  54.  
  55. $new_field_value = $field_value; 
  56.  
  57. if (!empty($field_value)) { 
  58. if (!empty($field_id)) { 
  59. $field = BP_XProfile_Field::get_instance($field_id); 
  60. if ($field) { 
  61. $do_autolink = apply_filters('bxcft_do_autolink',  
  62. $field->get_do_autolink()); 
  63. if ($do_autolink) { 
  64. $query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  65. $search_url = add_query_arg( array( 
  66. $query_arg => urlencode( $field_value ) 
  67. ), bp_get_members_directory_permalink() ); 
  68. $new_field_value = '<a href="' . esc_url( $search_url ) . 
  69. '" rel="nofollow">' . $new_field_value . '</a>'; 
  70.  
  71. /** 
  72. * bxcft_color_display_filter 
  73. * Use this filter to modify the appearance of Color 
  74. * field value. 
  75. * @param $new_field_value Value of field 
  76. * @param $field_id Id of field. 
  77. * @return Filtered value of field. 
  78. */ 
  79. return apply_filters('bxcft_color_display_filter', $new_field_value, $field_id);