/** * Output the edit field options HTML for this field type. * * BuddyPress considers a field's "options" to be, for example, the items in a selectbox. * These are stored separately in the database, and their templating is handled separately. * * This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because * it's also used in the wp-admin screens when creating new fields, and for backwards compatibility. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. * */ public function edit_field_options_html(array $args = array()) { $original_option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id'])); if (!empty($_POST['field_' . $this->field_obj->id])) { $option_values = (array) $_POST['field_' . $this->field_obj->id]; $option_values = array_map('sanitize_text_field', $option_values); } else { $option_values = (array) $original_option_values; } //member types list as array $options = self::get_roles(); $selected = ''; //$option_values = (array) $original_option_values; if (empty($option_values) || in_array('none', $option_values)) { $selected = ' selected="selected"'; } $html = '<option value="" ' . $selected . ' >----' . '</option>'; echo $html; foreach ($options as $role => $label) { $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($role, false, false); // First, check to see whether the user-entered value matches if (in_array($allowed_options, (array) $option_values)) { $selected = ' selected="selected"'; } echo apply_filters('bp_get_the_profile_field_options_roles', '<option' . $selected . ' value="' . esc_attr(stripslashes($role)) . '">' . $label . '</option>', $role, $this->field_obj->id, $selected); } }
/** * Output the edit field options HTML for this field type. * * BuddyPress considers a field's "options" to be, for example, the items in a selectbox. * These are stored separately in the database, and their templating is handled separately. * * This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because * it's also used in the wp-admin screens when creating new fields, and for backwards compatibility. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 2.0.0 * * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. */ public function edit_field_options_html(array $args = array()) { $original_option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id'])); $options = $this->field_obj->get_children(); $html = ''; if (empty($original_option_values) && !empty($_POST['field_' . $this->field_obj->id])) { $original_option_values = sanitize_text_field($_POST['field_' . $this->field_obj->id]); } $option_values = $original_option_values ? (array) $original_option_values : array(); for ($k = 0, $count = count($options); $k < $count; ++$k) { $selected = ''; // 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_' . $this->field_obj->id]) && $_POST['field_' . $this->field_obj->id][$i] != $option_value) { if (!empty($_POST['field_' . $this->field_obj->id][$i])) { $option_values[] = sanitize_text_field($_POST['field_' . $this->field_obj->id][$i]); } } } // 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, $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) && !empty($options[$k]->is_default_option)) { $selected = ' selected="selected"'; } /** * Filters the HTML output for options in a multiselect input. * * @since 1.5.0 * * @param string $value Option tag for current value being rendered. * @param object $value Current option being rendered for. * @param int $id ID of the field object being rendered. * @param string $selected Current selected value. * @param string $k Current index in the foreach loop. */ $html .= apply_filters('bp_get_the_profile_field_options_multiselect', '<option' . $selected . ' value="' . esc_attr(stripslashes($options[$k]->name)) . '">' . esc_html(stripslashes($options[$k]->name)) . '</option>', $options[$k], $this->field_obj->id, $selected, $k); } echo $html; }
/** * Output the edit field options HTML for this field type. * * BuddyPress considers a field's "options" to be, for example, the items in a selectbox. * These are stored separately in the database, and their templating is handled seperately. * * This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because * it's also used in the wp-admin screens when creating new fields, and for backwards compatibility. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. * @since BuddyPress (2.0.0) */ public function edit_field_options_html(array $args = array()) { $original_option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id'])); $options = $this->field_obj->get_children(); $html = '<option value="">' . esc_html__('----', 'buddypress') . '</option>'; if (empty($original_option_values) && !empty($_POST['field_' . $this->field_obj->id])) { $original_option_values = sanitize_text_field($_POST['field_' . $this->field_obj->id]); } $option_values = (array) $original_option_values; for ($k = 0, $count = count($options); $k < $count; ++$k) { $selected = ''; // 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_' . $this->field_obj->id]) && $_POST['field_' . $this->field_obj->id] != $option_value) { if (!empty($_POST['field_' . $this->field_obj->id])) { $option_values[$i] = sanitize_text_field($_POST['field_' . $this->field_obj->id]); } } } // 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, $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', '<option' . $selected . ' value="' . esc_attr(stripslashes($options[$k]->name)) . '">' . esc_html(stripslashes($options[$k]->name)) . '</option>', $options[$k], $this->field_obj->id, $selected, $k); } echo $html; }
/** * Output the edit field options HTML for this field type. * * BuddyPress considers a field's "options" to be, for example, the items in a selectbox. * These are stored separately in the database, and their templating is handled separately. * * This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because * it's also used in the wp-admin screens when creating new fields, and for backwards compatibility. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 2.0.0 * * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. */ public function edit_field_options_html(array $args = array()) { $options = $this->field_obj->get_children(); $option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id'])); $option_values = $option_values ? (array) $option_values : array(); $html = ''; // Check for updated posted values, but errors preventing them from // being saved first time. if (isset($_POST['field_' . $this->field_obj->id]) && $option_values != maybe_serialize($_POST['field_' . $this->field_obj->id])) { if (!empty($_POST['field_' . $this->field_obj->id])) { $option_values = array_map('sanitize_text_field', $_POST['field_' . $this->field_obj->id]); } } for ($k = 0, $count = count($options); $k < $count; ++$k) { $selected = ''; // First, check to see whether the user's saved values match the option. for ($j = 0, $count_values = count($option_values); $j < $count_values; ++$j) { // 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); if ($option_values[$j] === $allowed_options || in_array($allowed_options, $option_values)) { $selected = ' checked="checked"'; break; } } // If the user has not yet supplied a value for this field, check to // see whether there is a default value available. if (empty($option_values) && empty($selected) && !empty($options[$k]->is_default_option)) { $selected = ' checked="checked"'; } $new_html = sprintf('<label for="%3$s"><input %1$s type="checkbox" name="%2$s" id="%3$s" value="%4$s">%5$s</label>', $selected, esc_attr("field_{$this->field_obj->id}[]"), esc_attr("field_{$options[$k]->id}_{$k}"), esc_attr(stripslashes($options[$k]->name)), esc_html(stripslashes($options[$k]->name))); /** * Filters the HTML output for an individual field options checkbox. * * @since 1.1.0 * * @param string $new_html Label and checkbox input field. * @param object $value Current option being rendered for. * @param int $id ID of the field object being rendered. * @param string $selected Current selected value. * @param string $k Current index in the foreach loop. */ $html .= apply_filters('bp_get_the_profile_field_options_checkbox', $new_html, $options[$k], $this->field_obj->id, $selected, $k); } echo $html; }
/** * Output the edit field options HTML for this field type. * * BuddyPress considers a field's "options" to be, for example, the items in a selectbox. * These are stored separately in the database, and their templating is handled separately. * * This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because * it's also used in the wp-admin screens when creating new fields, and for backwards compatibility. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. * @since 2.0.0 */ public function edit_field_options_html(array $args = array()) { $option_value = BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']); $options = $this->field_obj->get_children(); $html = sprintf('<div id="%s">', esc_attr('field_' . $this->field_obj->id)); for ($k = 0, $count = count($options); $k < $count; ++$k) { // Check for updated posted values, but errors preventing them from // being saved first time if (isset($_POST['field_' . $this->field_obj->id]) && $option_value != $_POST['field_' . $this->field_obj->id]) { if (!empty($_POST['field_' . $this->field_obj->id])) { $option_value = sanitize_text_field($_POST['field_' . $this->field_obj->id]); } } // 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); $selected = ''; if ($option_value === $allowed_options || empty($option_value) && !empty($options[$k]->is_default_option)) { $selected = ' checked="checked"'; } $new_html = sprintf('<label><input %1$s type="radio" name="%2$s" id="%3$s" value="%4$s">%5$s</label>', $selected, esc_attr("field_{$this->field_obj->id}"), esc_attr("option_{$options[$k]->id}"), esc_attr(stripslashes($options[$k]->name)), esc_html(stripslashes($options[$k]->name))); /** * Filters the HTML output for an individual field options radio button. * * @since 1.1.0 * * @param string $new_html Label and radio input field. * @param object $value Current option being rendered for. * @param int $id ID of the field object being rendered. * @param string $selected Current selected value. * @param string $k Current index in the foreach loop. */ $html .= apply_filters('bp_get_the_profile_field_options_radio', $new_html, $options[$k], $this->field_obj->id, $selected, $k); } echo $html . '</div>'; }
/** * 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 .= '<option value="">' . __('----', 'buddypress') . '</option>'; } $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', '<option' . $selected . ' value="' . esc_attr(stripslashes($options[$k]->name)) . '">' . esc_attr(stripslashes($options[$k]->name)) . '</option>', $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', '<option' . $selected . ' value="' . esc_attr(stripslashes($options[$k]->name)) . '">' . esc_attr(stripslashes($options[$k]->name)) . '</option>', $options[$k], $field->id, $selected, $k); } break; case 'radio': $html .= '<div id="field_' . $field->id . '">'; $option_value = BP_XProfile_ProfileData::get_value_byid($field->id); for ($k = 0, $count = count($options); $k < $count; ++$k) { // Check for updated posted values, but errors preventing them from being saved first time if (isset($_POST['field_' . $field->id]) && $option_value != $_POST['field_' . $field->id]) { if (!empty($_POST['field_' . $field->id])) { $option_value = $_POST['field_' . $field->id]; } } // 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); $selected = ''; if ($option_value == $allowed_options || !empty($value) && $value == $allowed_options || empty($option_value) && $options[$k]->is_default_option) { $selected = ' checked="checked"'; } $html .= apply_filters('bp_get_the_profile_field_options_radio', '<label><input' . $selected . ' type="radio" name="field_' . $field->id . '" id="option_' . $options[$k]->id . '" value="' . esc_attr(stripslashes($options[$k]->name)) . '"> ' . esc_attr(stripslashes($options[$k]->name)) . '</label>', $options[$k], $field->id, $selected, $k); } $html .= '</div>'; break; case 'checkbox': $option_values = BP_XProfile_ProfileData::get_value_byid($field->id); $option_values = maybe_unserialize($option_values); // Check for updated posted values, but errors preventing them from being saved first time if (isset($_POST['field_' . $field->id]) && $option_values != maybe_serialize($_POST['field_' . $field->id])) { if (!empty($_POST['field_' . $field->id])) { $option_values = $_POST['field_' . $field->id]; } } for ($k = 0, $count = count($options); $k < $count; ++$k) { $selected = ''; // First, check to see whether the user's saved values // match the option for ($j = 0, $count_values = count($option_values); $j < $count_values; ++$j) { // 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); if ($option_values[$j] == $allowed_options || @in_array($allowed_options, $value)) { $selected = ' checked="checked"'; break; } } // If the user has not yet supplied a value for this field, // check to see whether there is a default value available if (!is_array($option_values) && empty($option_values) && !$selected && $options[$k]->is_default_option) { $selected = ' checked="checked"'; } $html .= apply_filters('bp_get_the_profile_field_options_checkbox', '<label><input' . $selected . ' type="checkbox" name="field_' . $field->id . '[]" id="field_' . $options[$k]->id . '_' . $k . '" value="' . esc_attr(stripslashes($options[$k]->name)) . '"> ' . esc_attr(stripslashes($options[$k]->name)) . '</label>', $options[$k], $field->id, $selected, $k); } break; case 'datebox': $date = BP_XProfile_ProfileData::get_value_byid($field->id); // Set day, month, year defaults $day = ''; $month = ''; $year = ''; if (!empty($date)) { // If Unix timestamp if (is_numeric($date)) { $day = date('j', $date); $month = date('F', $date); $year = date('Y', $date); // If MySQL timestamp } else { $day = mysql2date('j', $date); $month = mysql2date('F', $date, false); // Not localized, so that selected() works below $year = mysql2date('Y', $date); } } // Check for updated posted values, but errors preventing them from being saved first time if (!empty($_POST['field_' . $field->id . '_day'])) { if ($day != $_POST['field_' . $field->id . '_day']) { $day = $_POST['field_' . $field->id . '_day']; } } if (!empty($_POST['field_' . $field->id . '_month'])) { if ($month != $_POST['field_' . $field->id . '_month']) { $month = $_POST['field_' . $field->id . '_month']; } } if (!empty($_POST['field_' . $field->id . '_year'])) { if ($year != date("j", $_POST['field_' . $field->id . '_year'])) { $year = $_POST['field_' . $field->id . '_year']; } } switch ($type) { case 'day': $html .= '<option value=""' . selected($day, '', false) . '>--</option>'; for ($i = 1; $i < 32; ++$i) { $html .= '<option value="' . $i . '"' . selected($day, $i, false) . '>' . $i . '</option>'; } break; case 'month': $eng_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $months = array(__('January', 'buddypress'), __('February', 'buddypress'), __('March', 'buddypress'), __('April', 'buddypress'), __('May', 'buddypress'), __('June', 'buddypress'), __('July', 'buddypress'), __('August', 'buddypress'), __('September', 'buddypress'), __('October', 'buddypress'), __('November', 'buddypress'), __('December', 'buddypress')); $html .= '<option value=""' . selected($month, '', false) . '>------</option>'; for ($i = 0; $i < 12; ++$i) { $html .= '<option value="' . $eng_months[$i] . '"' . selected($month, $eng_months[$i], false) . '>' . $months[$i] . '</option>'; } break; case 'year': $html .= '<option value=""' . selected($year, '', false) . '>----</option>'; for ($i = 2037; $i > 1901; $i--) { $html .= '<option value="' . $i . '"' . selected($year, $i, false) . '>' . $i . '</option>'; } break; } $html = apply_filters('bp_get_the_profile_field_datebox', $html, $type, $day, $month, $year, $field->id, $date); break; } return $html; }
public static function prepare_buddypress_data($user_id, $config, $entry) { // required for user to display in the directory bp_update_user_meta($user_id, 'last_activity', true); $buddypress_meta = rgars($config, 'meta/buddypress_meta'); if (empty($buddypress_meta)) { return; } $form = RGFormsModel::get_form_meta($entry['form_id']); $buddypress_row = array(); $i = 0; foreach ($buddypress_meta as $meta_item) { $buddypress_row[$i]['field_id'] = $meta_item['meta_name']; $buddypress_row[$i]['user_id'] = $user_id; // get GF and BP fields $gform_field = RGFormsModel::get_field($form, $meta_item['meta_value']); $bp_field = new BP_XProfile_Field(); $bp_field->bp_xprofile_field($meta_item['meta_name']); // if bp field is a checkbox AND gf field is a checkbox, get array of input values if ($bp_field->type == 'checkbox' && $gform_field['type'] == 'checkbox') { $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field); $meta_value = array_filter($meta_value, 'GFUser::not_empty'); } else { if ($bp_field->type == 'multiselectbox' && $gform_field['type'] == 'checkbox') { $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field); $meta_value = array_filter($meta_value, 'GFUser::not_empty'); } else { if ($bp_field->type == 'datebox' && $gform_field['type'] == 'date') { $meta_value = strtotime(self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry)); } else { $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry); } } } $buddypress_row[$i]['value'] = xprofile_sanitize_data_value_before_save($meta_value, $meta_item['meta_name']); $buddypress_row[$i]['last_update'] = date('Y-m-d H:i:s'); $i++; } GFUserData::insert_buddypress_data($buddypress_row); }
protected function _edit_options_html_radio($option_values, $options) { foreach ($options as $member_type => $label) { $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($member_type, false, false); // First, check to see whether the user-entered value matches if (in_array($allowed_options, (array) $option_values)) { $selected = ' checked="checked"'; } $new_html = sprintf('<label for="%3$s"><input %1$s type="radio" name="%2$s" id="%3$s" value="%4$s">%5$s</label>', $selected, esc_attr("field_{$this->field_obj->id}"), esc_attr("option_{$member_type}"), esc_attr(stripslashes($member_type)), esc_html(stripslashes($label))); echo apply_filters('bp_get_the_profile_field_options_member_type', $new_html, $member_type, $this->field_obj->id, $selected); } }