__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields ); } function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) { $this->groups = BP_XProfile_Group::get( array( 'profile_group_id' => $profile_group_id, 'user_id' => $user_id, 'hide_empty_groups' => $hide_empty_groups, 'hide_empty_fields' => $hide_empty_fields, 'fetch_fields' => $fetch_fields, 'fetch_field_data' => $fetch_field_data, 'exclude_groups' => $exclude_groups, 'exclude_fields' => $exclude_fields ) ); $this->group_count = count($this->groups); $this->user_id = $user_id; } function has_groups() { if ( $this->group_count ) return true; return false; } function next_group() { $this->current_group++; $this->group = $this->groups[$this->current_group]; $this->group->fields = apply_filters( 'xprofile_group_fields', $this->group->fields, $this->group->id ); $this->field_count = count( $this->group->fields ); return $this->group; } function rewind_groups() { $this->current_group = -1; if ( $this->group_count > 0 ) { $this->group = $this->groups[0]; } } function profile_groups() { if ( $this->current_group + 1 < $this->group_count ) { return true; } elseif ( $this->current_group + 1 == $this->group_count ) { do_action('xprofile_template_loop_end'); // Do some cleaning up after the loop $this->rewind_groups(); } $this->in_the_loop = false; return false; } function the_profile_group() { global $group; $this->in_the_loop = true; $group = $this->next_group(); if ( 0 == $this->current_group ) // loop has just started do_action('xprofile_template_loop_start'); } /**** FIELDS ****/ function next_field() { $this->current_field++; $this->field = $this->group->fields[$this->current_field]; return $this->field; } function rewind_fields() { $this->current_field = -1; if ( $this->field_count > 0 ) { $this->field = $this->group->fields[0]; } } function has_fields() { $has_data = false; for ( $i = 0, $count = count( $this->group->fields ); $i < $count; ++$i ) { $field = &$this->group->fields[$i]; if ( !empty( $field->data ) && $field->data->value != null ) { $has_data = true; } } if ( $has_data ) return true; return false; } function profile_fields() { if ( $this->current_field + 1 < $this->field_count ) { return true; } elseif ( $this->current_field + 1 == $this->field_count ) { // Do some cleaning up after the loop $this->rewind_fields(); } return false; } function the_profile_field() { global $field; $field = $this->next_field(); $value = !empty( $field->data ) && !empty( $field->data->value ) ? maybe_unserialize( $field->data->value ) : false; if ( !empty( $value ) ) { $this->field_has_data = true; } else { $this->field_has_data = false; } } } function xprofile_get_profile() { locate_template( array( 'profile/profile-loop.php'), true ); } function bp_has_profile( $args = '' ) { global $bp, $profile_template; // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page, // or this is a registration page $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() ); $defaults = array( 'user_id' => $bp->displayed_user->id, 'profile_group_id' => false, 'hide_empty_groups' => true, 'hide_empty_fields' => $hide_empty_fields_default, 'fetch_fields' => true, 'fetch_field_data' => true, 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude 'exclude_fields' => false // Comma-separated list of profile field IDs to exclude ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields ); return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); } function bp_profile_groups() { global $profile_template; return $profile_template->profile_groups(); } function bp_the_profile_group() { global $profile_template; return $profile_template->the_profile_group(); } function bp_profile_group_has_fields() { global $profile_template; return $profile_template->has_fields(); } function bp_field_css_class( $class = false ) { echo bp_get_field_css_class( $class ); } function bp_get_field_css_class( $class = false ) { global $profile_template; $css_classes = array(); if ( $class ) $css_classes[] = sanitize_title( esc_attr( $class ) ); // Set a class with the field ID $css_classes[] = 'field_' . $profile_template->field->id; // Set a class with the field name (sanitized) $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); if ( $profile_template->current_field % 2 == 1 ) $css_classes[] = 'alt'; $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) ); return apply_filters( 'bp_get_field_css_class', ' class="' . implode( ' ', $css_classes ) . '"' ); } function bp_field_has_data() { global $profile_template; return $profile_template->field_has_data; } function bp_field_has_public_data() { global $profile_template; if ( $profile_template->field_has_data ) return true; return false; } function bp_the_profile_group_id() { echo bp_get_the_profile_group_id(); } function bp_get_the_profile_group_id() { global $group; return apply_filters( 'bp_get_the_profile_group_id', $group->id ); } function bp_the_profile_group_name() { echo bp_get_the_profile_group_name(); } function bp_get_the_profile_group_name() { global $group; return apply_filters( 'bp_get_the_profile_group_name', $group->name ); } function bp_the_profile_group_slug() { echo bp_get_the_profile_group_slug(); } function bp_get_the_profile_group_slug() { global $group; return apply_filters( 'bp_get_the_profile_group_slug', sanitize_title( $group->name ) ); } function bp_the_profile_group_description() { echo bp_get_the_profile_group_description(); } function bp_get_the_profile_group_description() { global $group; echo apply_filters( 'bp_get_the_profile_group_description', $group->description ); } function bp_the_profile_group_edit_form_action() { echo bp_get_the_profile_group_edit_form_action(); } function bp_get_the_profile_group_edit_form_action() { global $bp, $group; return apply_filters( 'bp_get_the_profile_group_edit_form_action', trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $group->id ) ); } function bp_the_profile_group_field_ids() { echo bp_get_the_profile_group_field_ids(); } function bp_get_the_profile_group_field_ids() { global $group; $field_ids = ''; foreach ( (array) $group->fields as $field ) $field_ids .= $field->id . ','; return substr( $field_ids, 0, -1 ); } function bp_profile_fields() { global $profile_template; return $profile_template->profile_fields(); } function bp_the_profile_field() { global $profile_template; return $profile_template->the_profile_field(); } function bp_the_profile_field_id() { echo bp_get_the_profile_field_id(); } function bp_get_the_profile_field_id() { global $field; return apply_filters( 'bp_get_the_profile_field_id', $field->id ); } function bp_the_profile_field_name() { echo bp_get_the_profile_field_name(); } function bp_get_the_profile_field_name() { global $field; return apply_filters( 'bp_get_the_profile_field_name', $field->name ); } function bp_the_profile_field_value() { echo bp_get_the_profile_field_value(); } function bp_get_the_profile_field_value() { global $field; $field->data->value = bp_unserialize_profile_field( $field->data->value ); return apply_filters( 'bp_get_the_profile_field_value', $field->data->value, $field->type, $field->id ); } function bp_the_profile_field_edit_value() { echo bp_get_the_profile_field_edit_value(); } function bp_get_the_profile_field_edit_value() { global $field; /** * Check to see if the posted value is different, if it is re-display this * value as long as it's not empty and a required field. */ if ( !isset( $field->data->value ) ) $field->data->value = ''; if ( isset( $_POST['field_' . $field->id] ) && $field->data->value != $_POST['field_' . $field->id] ) { if ( !empty( $_POST['field_' . $field->id] ) ) $field->data->value = $_POST['field_' . $field->id]; else $field->data->value = ''; } $field_value = isset( $field->data->value ) ? bp_unserialize_profile_field( $field->data->value ) : ''; return apply_filters( 'bp_get_the_profile_field_edit_value', $field_value, $field->type, $field->id ); } function bp_the_profile_field_type() { echo bp_get_the_profile_field_type(); } function bp_get_the_profile_field_type() { global $field; return apply_filters( 'bp_the_profile_field_type', $field->type ); } function bp_the_profile_field_description() { echo bp_get_the_profile_field_description(); } function bp_get_the_profile_field_description() { global $field; return apply_filters( 'bp_get_the_profile_field_description', $field->description ); } function bp_the_profile_field_input_name() { echo bp_get_the_profile_field_input_name(); } function bp_get_the_profile_field_input_name() { global $field; $array_box = false; if ( 'multiselectbox' == $field->type ) $array_box = '[]'; return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id . $array_box ); } /** * bp_the_profile_field_options() * * Displays field options HTML for field types of 'selectbox', 'multiselectbox', * 'radio', 'checkbox', and 'datebox'. * * @package BuddyPress Xprofile * @since 1.1 * * @uses bp_get_the_profile_field_options() * * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'. */ function bp_the_profile_field_options( $args = '' ) { echo bp_get_the_profile_field_options( $args ); } /** * bp_get_the_profile_field_options() * * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox', * 'radio', 'checkbox', and 'datebox'. * * @package BuddyPress Xprofile * @since 1.1 * * @uses BP_XProfile_Field::get_children() * @uses BP_XProfile_ProfileData::get_value_byid() * * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'. */ function bp_get_the_profile_field_options( $args = '' ) { global $field; $defaults = array( 'type' => false ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( !method_exists( $field, 'get_children' ) ) $field = new BP_XProfile_Field( $field->id ); $options = $field->get_children(); // Setup some defaults $html = ''; $selected = ''; switch ( $field->type ) { case 'selectbox': if ( !$field->is_required ) $html .= ''; $original_option_values = ''; $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) $original_option_values = $_POST['field_' . $field->id]; $option_values = (array) $original_option_values; for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { // Check for updated posted values, but errors preventing them from being saved first time foreach( $option_values as $i => $option_value ) { if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) { if ( !empty( $_POST['field_' . $field->id] ) ) $option_values[$i] = $_POST['field_' . $field->id]; } } $selected = ''; // Run the allowed option name through the before_save filter, so we'll be sure to get a match $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); // First, check to see whether the user-entered value matches if ( in_array( $allowed_options, (array) $option_values ) ) $selected = ' selected="selected"'; // Then, if the user has not provided a value, check for defaults if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) $selected = ' selected="selected"'; $html .= apply_filters( 'bp_get_the_profile_field_options_select', '', $options[$k], $field->id, $selected, $k ); } break; case 'multiselectbox': $original_option_values = ''; $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) $original_option_values = $_POST['field_' . $field->id]; $option_values = (array) $original_option_values; for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { // Check for updated posted values, but errors preventing them from being saved first time foreach( $option_values as $i => $option_value ) { if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id][$i] != $option_value ) { if ( !empty( $_POST['field_' . $field->id][$i] ) ) $option_values[] = $_POST['field_' . $field->id][$i]; } } $selected = ''; // Run the allowed option name through the before_save filter, so we'll be sure to get a match $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); // First, check to see whether the user-entered value matches if ( in_array( $allowed_options, (array) $option_values ) ) $selected = ' selected="selected"'; // Then, if the user has not provided a value, check for defaults if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) $selected = ' selected="selected"'; $html .= apply_filters( 'bp_get_the_profile_field_options_multiselect', '', $options[$k], $field->id, $selected, $k ); } break; case 'radio': $html .= '