Changeset 10163 for trunk/src/bp-xprofile/bp-xprofile-filters.php
- Timestamp:
- 10/01/2015 04:18:13 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-filters.php
r10140 r10163 55 55 add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 ); 56 56 57 // Save field groups 57 // Save field groups. 58 58 add_filter( 'xprofile_group_name_before_save', 'wp_filter_kses' ); 59 59 add_filter( 'xprofile_group_description_before_save', 'wp_filter_kses' ); 60 60 61 // Save fields 61 // Save fields. 62 62 add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses' ); 63 63 add_filter( 'xprofile_field_type_before_save', 'wp_filter_kses' ); … … 69 69 add_filter( 'xprofile_field_can_delete_before_save', 'absint' ); 70 70 71 // Save field options 71 // Save field options. 72 72 add_filter( 'xprofile_field_options_before_save', 'bp_xprofile_sanitize_field_options' ); 73 73 add_filter( 'xprofile_field_default_before_save', 'bp_xprofile_sanitize_field_default' ); 74 74 75 75 /** 76 * Sanitize each field option name for saving to the database 76 * Sanitize each field option name for saving to the database. 77 77 * 78 78 * @since 2.3.0 79 79 * 80 * @param mixed $field_options 80 * @param mixed $field_options Options to sanitize. 81 * 81 82 * @return mixed 82 83 */ … … 90 91 91 92 /** 92 * Sanitize each field option default for saving to the database 93 * Sanitize each field option default for saving to the database. 93 94 * 94 95 * @since 2.3.0 95 96 * 96 * @param mixed $field_default 97 * @param mixed $field_default Field defaults to sanitize. 98 * 97 99 * @return mixed 98 100 */ … … 106 108 107 109 /** 108 * xprofile_filter_kses ( $content )109 *110 110 * Run profile field values through kses with filterable allowed tags. 111 111 * 112 * @param string $content 113 * @param object $data_obj The BP_XProfile_ProfileData object 112 * @param string $content Content to filter. 113 * @param object $data_obj The BP_XProfile_ProfileData object. 114 * 114 115 * @return string $content 115 116 */ … … 135 136 * Safely runs profile field data through kses and force_balance_tags. 136 137 * 137 * @param string $field_value 138 * @param int $field_id 139 * @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true 140 * @param object $data_obj The BP_XProfile_ProfileData object 138 * @param string $field_value Field value being santized. 139 * @param int $field_id Field ID being sanitized. 140 * @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true. 141 * @param object $data_obj The BP_XProfile_ProfileData object. 142 * 141 143 * @return string 142 144 */ 143 145 function xprofile_sanitize_data_value_before_save( $field_value, $field_id = 0, $reserialize = true, $data_obj = null ) { 144 146 145 // Return if empty 147 // Return if empty. 146 148 if ( empty( $field_value ) ) { 147 149 return $field_value; 148 150 } 149 151 150 // Value might be serialized 152 // Value might be serialized. 151 153 $field_value = maybe_unserialize( $field_value ); 152 154 153 // Filter single value 155 // Filter single value. 154 156 if ( !is_array( $field_value ) ) { 155 157 $kses_field_value = xprofile_filter_kses( $field_value, $data_obj ); … … 167 169 $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj ); 168 170 169 // Filter each array item independently 171 // Filter each array item independently. 170 172 } else { 171 173 $filtered_values = array(); … … 195 197 * 196 198 * @param string $field_value XProfile field_value to be filtered. 197 * @param string $field_type XProfile field_type to be filtered. 199 * @param string $field_type XProfile field_type to be filtered. 200 * 198 201 * @return string $field_value Filtered XProfile field_value. False on failure. 199 202 */ 200 203 function xprofile_filter_format_field_value( $field_value, $field_type = '' ) { 201 204 202 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731 205 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. 203 206 if ( ! isset( $field_value ) || empty( $field_value ) && ( '0' !== $field_value ) ) { 204 207 return false; … … 213 216 214 217 /** 215 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside a bp_has_profile() loop. 218 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside 219 * a bp_has_profile() loop. 216 220 * 217 221 * @since 2.1.0 218 222 * 219 * @param mixed $field_value Field value. 220 * @param string $field_type Field type. 223 * @param mixed $field_value Field value. 224 * @param string $field_type Field type. 225 * 221 226 * @return mixed 222 227 */ … … 236 241 237 242 /** 238 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched by xprofile_get_field_data(). 243 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched 244 * by xprofile_get_field_data(). 239 245 * 240 246 * @since 2.1.0 241 247 * 242 248 * @param mixed $field_value Field value. 243 * @param int $field_id Field type. 249 * @param int $field_id Field type. 250 * 251 * @return string 244 252 */ 245 253 function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) { … … 253 261 * @since 2.1.0 254 262 * 255 * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate256 * filter.257 * @param BP_XProfile_Field $field Fieldobject.258 * @param BP_XProfile_Field_Type Field type object.263 * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate filter. 264 * @param BP_XProfile_Field $field Field object. 265 * @param BP_XProfile_Field_Type $field_type_obj Field type object. 266 * 259 267 * @return mixed 260 268 */ … … 271 279 * to members search results out of them. 272 280 * 273 * - Not run on datebox field types 274 * - Not run on values without commas with less than 5 words 275 * - URL's are made clickable 281 * - Not run on datebox field types. 282 * - Not run on values without commas with less than 5 words. 283 * - URL's are made clickable. 276 284 * - To disable: remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); 277 285 * 278 286 * @since 1.1.0 279 287 * 280 * @param string $field_value 281 * @param string $field_type 288 * @param string $field_value Profile field data value. 289 * @param string $field_type Profile field type. 290 * 282 291 * @return string 283 292 */ … … 302 311 $new_values[] = make_clickable( $value ); 303 312 304 // Is not clickable 313 // Is not clickable. 305 314 } else { 306 315 307 // More than 5 spaces 316 // More than 5 spaces. 308 317 if ( count( explode( ' ', $value ) ) > 5 ) { 309 318 $new_values[] = $value; 310 319 311 // Less than 5 spaces 320 // Less than 5 spaces. 312 321 } else { 313 322 $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); … … 324 333 325 334 /** 326 * Ensures that BP data appears in comments array 335 * Ensures that BP data appears in comments array. 327 336 * 328 337 * This filter loops through the comments return by a normal WordPress request 329 * and swaps out user data with BP xprofile data, where available 330 * 331 * @param array $comments 332 * @param int $post_id 338 * and swaps out user data with BP xprofile data, where available. 339 * 340 * @param array $comments Comments to filter in. 341 * @param int $post_id Post ID the comments are for. 342 * 333 343 * @return array $comments 334 344 */ 335 345 function xprofile_filter_comments( $comments, $post_id = 0 ) { 336 346 337 // Locate comment authors with WP accounts 347 // Locate comment authors with WP accounts. 338 348 foreach( (array) $comments as $comment ) { 339 349 if ( $comment->user_id ) { … … 342 352 } 343 353 344 // If none are found, just return the comments array 354 // If none are found, just return the comments array. 345 355 if ( empty( $user_ids ) ) { 346 356 return $comments; 347 357 } 348 358 349 // Pull up the xprofile fullname of each commenter 359 // Pull up the xprofile fullname of each commenter. 350 360 if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) { 351 361 foreach( (array) $fullnames as $user_id => $user_fullname ) { … … 354 364 } 355 365 356 // Loop through and match xprofile fullname with commenters 366 // Loop through and match xprofile fullname with commenters. 357 367 foreach( (array) $comments as $i => $comment ) { 358 368 if ( ! empty( $comment->user_id ) ) { … … 368 378 369 379 /** 370 * Filter BP_User_Query::populate_extras to override each queries users fullname 380 * Filter BP_User_Query::populate_extras to override each queries users fullname. 371 381 * 372 382 * @since 1.7.0 373 383 * 374 * @param BP_User_Query $user_query 375 * @param string $user_ids_sql384 * @param BP_User_Query $user_query User query to filter. 385 * @param string $user_ids_sql SQL statement to use. 376 386 */ 377 387 function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql = '' ) { … … 383 393 $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids ); 384 394 385 // Loop through names and override each user's fullname 395 // Loop through names and override each user's fullname. 386 396 foreach ( $user_id_names as $user_id => $user_fullname ) { 387 397 if ( isset( $user_query->results[ $user_id ] ) ) { … … 397 407 * @since 2.2.0 398 408 * 399 * @param BP_User_Query User query object.409 * @param BP_User_Query $q User query object. 400 410 */ 401 411 function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query $q ) { 402 412 403 // Bail if no `xprofile_query` clause 413 // Bail if no `xprofile_query` clause. 404 414 if ( empty( $q->query_vars['xprofile_query'] ) ) { 405 415 return; … … 424 434 * 425 435 * @param string $q SQL query. 436 * 426 437 * @return string 427 438 */ … … 439 450 $q = preg_replace( $quoted_regex, '__QUOTE__', $q ); 440 451 441 // Get the first word of the command 452 // Get the first word of the command. 442 453 preg_match( '/^(\S+)/', $q, $first_word_matches ); 443 454 … … 446 457 } 447 458 448 // Get the field type 459 // Get the field type. 449 460 preg_match( '/xprofile_(group|field|data)_id/', $q, $matches ); 450 461
Note: See TracChangeset
for help on using the changeset viewer.