', ']]>', $field_value ); } return stripslashes( $field_value ); } function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { if ( 'datebox' == $field_type ) return $field_value; if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) return $field_value; $values = explode( ',', $field_value ); if ( !empty( $values ) ) { foreach ( (array) $values as $value ) { $value = trim( $value ); // If the value is a URL, skip it and just make it clickable. if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) { $new_values[] = make_clickable( $value ); // Is not clickable } else { // More than 5 spaces if ( count( explode( ' ', $value ) ) > 5 ) { $new_values[] = $value; // Less than 5 spaces } else { $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); $new_values[] = '' . $value . ''; } } } $values = implode( ', ', $new_values ); } return $values; } /** * Ensures that BP data appears in comments array * * This filter loops through the comments return by a normal WordPress request * and swaps out user data with BP xprofile data, where available * * @param array $comments * @param int $post_id * @return array $comments */ function xprofile_filter_comments( $comments, $post_id ) { // Locate comment authors with WP accounts foreach( (array) $comments as $comment ) { if ( $comment->user_id ) { $user_ids[] = $comment->user_id; } } // If none are found, just return the comments array if ( empty( $user_ids ) ) { return $comments; } // Pull up the xprofile fullname of each commenter if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) { foreach( (array) $fullnames as $user_id => $user_fullname ) { $users[ $user_id ] = trim( stripslashes( $user_fullname ) ); } } // Loop through and match xprofile fullname with commenters foreach( (array) $comments as $i => $comment ) { if ( ! empty( $comment->user_id ) ) { if ( ! empty( $users[ $comment->user_id ] ) ) { $comments[ $i ]->comment_author = $users[ $comment->user_id ]; } } } return $comments; } add_filter( 'comments_array', 'xprofile_filter_comments', 10, 2 ); /** * Filter BP_User_Query::populate_extras to override each queries users fullname * * @since BuddyPress (1.7) * * @global BuddyPress $bp * @global WPDB $wpdb * @param BP_User_Query $user_query * @param string $user_ids_sql */ function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) { global $bp, $wpdb; if ( ! bp_is_active( 'xprofile' ) ) { return; } $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids ); // Loop through names and override each user's fullname foreach ( $user_id_names as $user_id => $user_fullname ) { if ( isset( $user_query->results[ $user_id ] ) ) { $user_query->results[ $user_id ]->fullname = $user_fullname; } } } add_filter( 'bp_user_query_populate_extras', 'bp_xprofile_filter_user_query_populate_extras', 2, 2 ); /** * Filter meta queries to modify for the xprofile data schema. * * @since BuddyPress (2.0.0) * * @access private Do not use. * * @param string $q SQL query. * @return string */ function bp_xprofile_filter_meta_query( $q ) { global $wpdb; // Get the first word of the command preg_match( '/^(\S+)/', $q, $first_word_matches ); if ( empty( $first_word_matches[0] ) ) { return $q; } // Get the field type preg_match( '/xprofile_(group|field|data)_id/', $q, $matches ); if ( empty( $matches[0] ) || empty( $matches[1] ) ) { return $q; } switch ( $first_word_matches[0] ) { /** * SELECT: * - replace 'xprofile_{fieldtype}_id' with 'object_id' * - ensure that 'object_id' is aliased to 'xprofile_{fieldtype}_id', * because update_meta_cache() needs the column name to parse * the query results * - append the 'object type' WHERE clause */ case 'SELECT' : $q = str_replace( array( $matches[0], 'SELECT object_id', 'WHERE ', ), array( 'object_id', 'SELECT object_id AS ' . $matches[0], $wpdb->prepare( 'WHERE object_type = %s AND ', $matches[1] ), ), $q ); break; /** * UPDATE and DELETE: * - replace 'xprofile_{fieldtype}_id' with 'object_id' * - append the 'object type' WHERE clause */ case 'UPDATE' : case 'DELETE' : $q = str_replace( array( $matches[0], 'WHERE ', ), array( 'object_id', $wpdb->prepare( 'WHERE object_type = %s AND ', $matches[1] ), ), $q ); break; /** * UPDATE and DELETE: * - replace 'xprofile_{fieldtype}_id' with 'object_id' * - ensure that the object_type field gets filled in */ case 'INSERT' : $q = str_replace( array( '`' . $matches[0] . '`', 'VALUES (', ), array( '`object_type`,`object_id`', $wpdb->prepare( "VALUES (%s,", $matches[1] ), ), $q ); break; } return $q; }