Changeset 8672
- Timestamp:
- 07/23/2014 01:42:48 PM (12 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 3 edited
-
bp-xprofile-classes.php (modified) (3 diffs)
-
bp-xprofile-filters.php (modified) (2 diffs)
-
bp-xprofile-functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-classes.php
r8671 r8672 2646 2646 2647 2647 $r = bp_parse_args( $raw_properties, array( 2648 'type' => 'url', 2649 'value' => esc_url( bp_get_the_profile_field_edit_value() ), 2648 'type' => 'text', 2649 'inputmode' => 'url', 2650 'value' => esc_url( bp_get_the_profile_field_edit_value() ), 2650 2651 ) ); ?> 2651 2652 … … 2692 2693 */ 2693 2694 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 2695 2696 /** 2697 * Modify submitted URL values before validation. 2698 * 2699 * The URL validation regex requires a http(s) protocol, so that all 2700 * values saved in the database are fully-formed URLs. However, we 2701 * still want to allow users to enter URLs without a protocol, for a 2702 * better user experience. So we catch submitted URL values, and if 2703 * the protocol is missing, we prepend 'http://' before passing to 2704 * is_valid(). 2705 * 2706 * @since BuddyPress (2.1.0) 2707 * 2708 * @param string $submitted_value Raw value submitted by the user. 2709 * @return string 2710 */ 2711 public static function pre_validate_filter( $submitted_value ) { 2712 if ( false === strpos( $submitted_value, ':' ) 2713 && substr( $submitted_value, 0, 1 ) !== '/' 2714 && substr( $submitted_value, 0, 1 ) !== '#' 2715 && ! preg_match( '/^[a-z0-9-]+?\.php/i', $submitted_value ) 2716 ) { 2717 $submitted_value = 'http://' . $submitted_value; 2718 } 2719 2720 return $submitted_value; 2721 } 2694 2722 2695 2723 /** … … 3065 3093 3066 3094 /** 3095 * Allow field types to modify submitted values before they are validated. 3096 * 3097 * In some cases, it may be appropriate for a field type to catch 3098 * submitted values and modify them before they are passed to the 3099 * is_valid() method. For example, URL validation requires the 3100 * 'http://' scheme (so that the value saved in the database is always 3101 * a fully-formed URL), but in order to allow users to enter a URL 3102 * without this scheme, BP_XProfile_Field_Type_URL prepends 'http://' 3103 * when it's not present. 3104 * 3105 * By default, this is a pass-through method that does nothing. Only 3106 * override in your own field type if you need this kind of pre- 3107 * validation filtering. 3108 * 3109 * @since BuddyPress (2.1.0) 3110 * 3111 * @param mixed $submitted_value Submitted value. 3112 * @return mixed 3113 */ 3114 public static function pre_validate_filter( $field_value ) { 3115 return $field_value; 3116 } 3117 3118 /** 3067 3119 * Allow field types to modify the appearance of their values. 3068 3120 * -
trunk/src/bp-xprofile/bp-xprofile-filters.php
r8665 r8672 52 52 add_filter( 'xprofile_get_field_data', 'xprofile_filter_format_field_value_by_field_id', 5, 2 ); 53 53 54 add_filter( 'bp_xprofile_set_field_data_pre_validate', 'xprofile_filter_pre_validate_value_by_field_type', 10, 3 ); 54 55 add_filter( 'xprofile_data_value_before_save', 'xprofile_sanitize_data_value_before_save', 1, 4 ); 55 56 add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 ); … … 176 177 $field = new BP_XProfile_Field( $field_id ); 177 178 return xprofile_filter_format_field_value_by_type( $field_value, $field->type ); 179 } 180 181 /** 182 * Apply pre_validate_filter() filters as defined by the BP_XProfile_Field_Type classes before validating. 183 * 184 * @since BuddyPress (2.1.0) 185 * 186 * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate 187 * filter. 188 * @param BP_XProfile_Field $field Field object. 189 * @param BP_XProfile_Field_Type Field type object. 190 * @return mixed 191 */ 192 function xprofile_filter_pre_validate_value_by_field_type( $value, $field, $field_type_obj ) { 193 if ( method_exists( $field_type_obj, 'pre_validate_filter' ) ) { 194 $value = call_user_func( array( $field_type_obj, 'pre_validate_filter' ), $value ); 195 } 196 197 return $value; 178 198 } 179 199 -
trunk/src/bp-xprofile/bp-xprofile-functions.php
r8670 r8672 294 294 return false; 295 295 296 // Special-case support for integer 0 for the number field type297 if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) {298 return false;299 }300 301 296 $field = new BP_XProfile_Field( $field_id ); 302 297 $field_type = BP_XProfile_Field::get_type( $field_id ); 303 298 $field_type_obj = bp_xprofile_create_field_type( $field_type ); 299 300 /** 301 * Filter the raw submitted profile field value. 302 * 303 * Use this filter to modify the values submitted by users before 304 * doing field-type-specific validation. 305 * 306 * @since BuddyPress (2.1.0) 307 * 308 * @param mixed $value Value passed to xprofile_set_field_data() 309 * @param BP_XProfile_Field $field Field object. 310 * @param BP_XProfile_Field_Type $field_type_obj Field type object. 311 */ 312 $value = apply_filters( 'bp_xprofile_set_field_data_pre_validate', $value, $field, $field_type_obj ); 313 314 // Special-case support for integer 0 for the number field type 315 if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) { 316 return false; 317 } 304 318 305 319 /**
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)