Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/01/2015 04:18:13 AM (9 years ago)
Author:
tw2113
Message:

First pass of documentation cleanup for the XProfile Component.

See #6406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-filters.php

    r10140 r10163  
    5555add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 );
    5656
    57 // Save field groups
     57// Save field groups.
    5858add_filter( 'xprofile_group_name_before_save',        'wp_filter_kses' );
    5959add_filter( 'xprofile_group_description_before_save', 'wp_filter_kses' );
    6060
    61 // Save fields
     61// Save fields.
    6262add_filter( 'xprofile_field_name_before_save',         'wp_filter_kses' );
    6363add_filter( 'xprofile_field_type_before_save',         'wp_filter_kses' );
     
    6969add_filter( 'xprofile_field_can_delete_before_save',   'absint' );
    7070
    71 // Save field options
     71// Save field options.
    7272add_filter( 'xprofile_field_options_before_save', 'bp_xprofile_sanitize_field_options' );
    7373add_filter( 'xprofile_field_default_before_save', 'bp_xprofile_sanitize_field_default' );
    7474
    7575/**
    76  * Sanitize each field option name for saving to the database
     76 * Sanitize each field option name for saving to the database.
    7777 *
    7878 * @since 2.3.0
    7979 *
    80  * @param  mixed $field_options
     80 * @param  mixed $field_options Options to sanitize.
     81 *
    8182 * @return mixed
    8283 */
     
    9091
    9192/**
    92  * Sanitize each field option default for saving to the database
     93 * Sanitize each field option default for saving to the database.
    9394 *
    9495 * @since 2.3.0
    9596 *
    96  * @param  mixed $field_default
     97 * @param  mixed $field_default Field defaults to sanitize.
     98 *
    9799 * @return mixed
    98100 */
     
    106108
    107109/**
    108  * xprofile_filter_kses ( $content )
    109  *
    110110 * Run profile field values through kses with filterable allowed tags.
    111111 *
    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 *
    114115 * @return string $content
    115116 */
     
    135136 * Safely runs profile field data through kses and force_balance_tags.
    136137 *
    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 *
    141143 * @return string
    142144 */
    143145function xprofile_sanitize_data_value_before_save( $field_value, $field_id = 0, $reserialize = true, $data_obj = null ) {
    144146
    145     // Return if empty
     147    // Return if empty.
    146148    if ( empty( $field_value ) ) {
    147149        return $field_value;
    148150    }
    149151
    150     // Value might be serialized
     152    // Value might be serialized.
    151153    $field_value = maybe_unserialize( $field_value );
    152154
    153     // Filter single value
     155    // Filter single value.
    154156    if ( !is_array( $field_value ) ) {
    155157        $kses_field_value     = xprofile_filter_kses( $field_value, $data_obj );
     
    167169        $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj );
    168170
    169     // Filter each array item independently
     171    // Filter each array item independently.
    170172    } else {
    171173        $filtered_values = array();
     
    195197 *
    196198 * @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 *
    198201 * @return string $field_value Filtered XProfile field_value. False on failure.
    199202 */
    200203function xprofile_filter_format_field_value( $field_value, $field_type = '' ) {
    201204
    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.
    203206    if ( ! isset( $field_value ) || empty( $field_value ) && ( '0' !== $field_value ) ) {
    204207        return false;
     
    213216
    214217/**
    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.
    216220 *
    217221 * @since 2.1.0
    218222 *
    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 *
    221226 * @return mixed
    222227 */
     
    236241
    237242/**
    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().
    239245 *
    240246 * @since 2.1.0
    241247 *
    242248 * @param mixed $field_value Field value.
    243  * @param int $field_id Field type.
     249 * @param int   $field_id    Field type.
     250 *
     251 * @return string
    244252 */
    245253function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) {
     
    253261 * @since 2.1.0
    254262 *
    255  * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate
    256  *        filter.
    257  * @param BP_XProfile_Field $field Field object.
    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 *
    259267 * @return mixed
    260268 */
     
    271279 * to members search results out of them.
    272280 *
    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.
    276284 * - To disable: remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    277285 *
    278286 * @since 1.1.0
    279287 *
    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 *
    282291 * @return string
    283292 */
     
    302311                $new_values[] = make_clickable( $value );
    303312
    304             // Is not clickable
     313            // Is not clickable.
    305314            } else {
    306315
    307                 // More than 5 spaces
     316                // More than 5 spaces.
    308317                if ( count( explode( ' ', $value ) ) > 5 ) {
    309318                    $new_values[] = $value;
    310319
    311                 // Less than 5 spaces
     320                // Less than 5 spaces.
    312321                } else {
    313322                    $search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
     
    324333
    325334/**
    326  * Ensures that BP data appears in comments array
     335 * Ensures that BP data appears in comments array.
    327336 *
    328337 * 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 *
    333343 * @return array $comments
    334344 */
    335345function xprofile_filter_comments( $comments, $post_id = 0 ) {
    336346
    337     // Locate comment authors with WP accounts
     347    // Locate comment authors with WP accounts.
    338348    foreach( (array) $comments as $comment ) {
    339349        if ( $comment->user_id ) {
     
    342352    }
    343353
    344     // If none are found, just return the comments array
     354    // If none are found, just return the comments array.
    345355    if ( empty( $user_ids ) ) {
    346356        return $comments;
    347357    }
    348358
    349     // Pull up the xprofile fullname of each commenter
     359    // Pull up the xprofile fullname of each commenter.
    350360    if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) {
    351361        foreach( (array) $fullnames as $user_id => $user_fullname ) {
     
    354364    }
    355365
    356     // Loop through and match xprofile fullname with commenters
     366    // Loop through and match xprofile fullname with commenters.
    357367    foreach( (array) $comments as $i => $comment ) {
    358368        if ( ! empty( $comment->user_id ) ) {
     
    368378
    369379/**
    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.
    371381 *
    372382 * @since 1.7.0
    373383 *
    374  * @param BP_User_Query $user_query
    375  * @param string $user_ids_sql
     384 * @param BP_User_Query $user_query   User query to filter.
     385 * @param string        $user_ids_sql SQL statement to use.
    376386 */
    377387function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql = '' ) {
     
    383393    $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids );
    384394
    385     // Loop through names and override each user's fullname
     395    // Loop through names and override each user's fullname.
    386396    foreach ( $user_id_names as $user_id => $user_fullname ) {
    387397        if ( isset( $user_query->results[ $user_id ] ) ) {
     
    397407 * @since 2.2.0
    398408 *
    399  * @param BP_User_Query User query object.
     409 * @param BP_User_Query $q User query object.
    400410 */
    401411function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query $q ) {
    402412
    403     // Bail if no `xprofile_query` clause
     413    // Bail if no `xprofile_query` clause.
    404414    if ( empty( $q->query_vars['xprofile_query'] ) ) {
    405415        return;
     
    424434 *
    425435 * @param string $q SQL query.
     436 *
    426437 * @return string
    427438 */
     
    439450    $q = preg_replace( $quoted_regex, '__QUOTE__', $q );
    440451
    441     // Get the first word of the command
     452    // Get the first word of the command.
    442453    preg_match( '/^(\S+)/', $q, $first_word_matches );
    443454
     
    446457    }
    447458
    448     // Get the field type
     459    // Get the field type.
    449460    preg_match( '/xprofile_(group|field|data)_id/', $q, $matches );
    450461
Note: See TracChangeset for help on using the changeset viewer.