BP_XProfile_Field_Type_URL

URL xprofile field type.

Defined (1)

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

/bp-xprofile/classes/class-bp-xprofile-field-type-url.php  
  1. class BP_XProfile_Field_Type_URL extends BP_XProfile_Field_Type { 
  2.  
  3. /** 
  4. * Constructor for the URL field type 
  5. * @since 2.1.0 
  6. */ 
  7. public function __construct() { 
  8. parent::__construct(); 
  9.  
  10. $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); 
  11. $this->name = _x( 'URL', 'xprofile field type', 'buddypress' ); 
  12.  
  13. $this->set_format( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1, 3}) {3})(?!127(?:\.\d{1, 3}) {3})(?!169\.254(?:\.\d{1, 3}) {2})(?!192\.168(?:\.\d{1, 3}) {2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1, 3}) {2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1, 2}|2[0-4]\d|25[0-5])) {2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2, })))(?::\d{2, 5})?(?:/[^\s]*)?$_iuS', 'replace' ); 
  14.  
  15. /** 
  16. * Fires inside __construct() method for BP_XProfile_Field_Type_URL class. 
  17. * @since 2.0.0 
  18. * @param BP_XProfile_Field_Type_URL $this Current instance of 
  19. * the field type URL. 
  20. */ 
  21. do_action( 'bp_xprofile_field_type_url', $this ); 
  22.  
  23. /** 
  24. * Output the edit field HTML for this field type. 
  25. * Must be used inside the {@link bp_profile_fields()} template loop. 
  26. * @since 2.1.0 
  27. * @param array $raw_properties Optional key/value array of 
  28. * {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} 
  29. * that you want to add. 
  30. */ 
  31. public function edit_field_html( array $raw_properties = array() ) { 
  32.  
  33. // `user_id` is a special optional parameter that certain other 
  34. // fields types pass to {@link bp_the_profile_field_options()}. 
  35. if ( isset( $raw_properties['user_id'] ) ) { 
  36. unset( $raw_properties['user_id'] ); 
  37.  
  38. $r = bp_parse_args( $raw_properties, array( 
  39. 'type' => 'text',  
  40. 'inputmode' => 'url',  
  41. 'value' => esc_url( bp_get_the_profile_field_edit_value() ),  
  42. ) ); ?> 
  43.  
  44. <label for="<?php bp_the_profile_field_input_name(); ?>"> 
  45. <?php bp_the_profile_field_name(); ?> 
  46. <?php bp_the_profile_field_required_label(); ?> 
  47. </label> 
  48.  
  49. <?php 
  50.  
  51. /** This action is documented in bp-xprofile/bp-xprofile-classes */ 
  52. do_action( bp_get_the_profile_field_errors_action() ); ?> 
  53.  
  54. <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 
  55.  
  56. <?php 
  57.  
  58. /** 
  59. * Output HTML for this field type on the wp-admin Profile Fields screen. 
  60. * Must be used inside the {@link bp_profile_fields()} template loop. 
  61. * @since 2.1.0 
  62. * @param array $raw_properties Optional key/value array of permitted 
  63. * attributes that you want to add. 
  64. */ 
  65. public function admin_field_html( array $raw_properties = array() ) { 
  66.  
  67. $r = bp_parse_args( $raw_properties, array( 
  68. 'type' => 'url' 
  69. ) ); ?> 
  70.  
  71. <label for="<?php bp_the_profile_field_input_name(); ?>" class="screen-reader-text"><?php 
  72. /** translators: accessibility text */ 
  73. esc_html_e( 'URL', 'buddypress' ); 
  74. ?></label> 
  75. <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 
  76.  
  77. <?php 
  78.  
  79. /** 
  80. * This method usually outputs HTML for this field type's children options 
  81. * on the wp-admin Profile Fields "Add Field" and "Edit Field" screens, but 
  82. * for this field type, we don't want it, so it's stubbed out. 
  83. * @since 2.1.0 
  84. * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 
  85. * @param string $control_type Optional. HTML input type used to render the current 
  86. * field's child options. 
  87. */ 
  88. public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 
  89.  
  90. /** 
  91. * Modify submitted URL values before validation. 
  92. * The URL validation regex requires a http(s) protocol, so that all 
  93. * values saved in the database are fully-formed URLs. However, we 
  94. * still want to allow users to enter URLs without a protocol, for a 
  95. * better user experience. So we catch submitted URL values, and if 
  96. * the protocol is missing, we prepend 'http://' before passing to 
  97. * is_valid(). 
  98. * @since 2.1.0 
  99. * @since 2.4.0 Added the `$field_id` parameter. 
  100. * @param string $submitted_value Raw value submitted by the user. 
  101. * @param string|int $field_id Optional. ID of the field. 
  102. * @return string 
  103. */ 
  104. public static function pre_validate_filter( $submitted_value = '', $field_id = '' ) { 
  105.  
  106. // Allow empty URL values. 
  107. if ( empty( $submitted_value ) ) { 
  108. return ''; 
  109.  
  110. // Run some checks on the submitted value. 
  111. if ( false === strpos( $submitted_value, ':' ) && 
  112. substr( $submitted_value, 0, 1 ) !== '/' && 
  113. substr( $submitted_value, 0, 1 ) !== '#' && 
  114. ! preg_match( '/^[a-z0-9-]+?\.php/i', $submitted_value ) 
  115. ) { 
  116. $submitted_value = 'http://' . $submitted_value; 
  117.  
  118. return $submitted_value; 
  119.  
  120. /** 
  121. * Format URL values for display. 
  122. * @since 2.1.0 
  123. * @since 2.4.0 Added the `$field_id` parameter. 
  124. * @param string $field_value The URL value, as saved in the database. 
  125. * @param string|int $field_id Optional. ID of the field. 
  126. * @return string URL converted to a link. 
  127. */ 
  128. public static function display_filter( $field_value, $field_id = '' ) { 
  129. $link = strip_tags( $field_value ); 
  130. $no_scheme = preg_replace( '#^https?://#', '', rtrim( $link, '/' ) ); 
  131. $url_text = str_replace( $link, $no_scheme, $field_value ); 
  132. return '<a href="' . esc_url( $field_value ) . '" rel="nofollow">' . esc_html( $url_text ) . '</a>';