/** * @ticket BP6545 */ public function test_newly_created_field_should_have_field_id_property_set() { $field = new BP_XProfile_Field(); $field->group_id = 1; $field->name = 'Foo'; $new_field_id = $field->save(); $this->assertSame($new_field_id, $field->id); }
function delete() { global $wpdb, $bp; if (empty($this->can_delete)) { return false; } // Delete field group if (!$wpdb->query($wpdb->prepare("DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id))) { return false; } else { // Remove the group's fields. if (BP_XProfile_Field::delete_for_group($this->id)) { // Remove profile data for the groups fields for ($i = 0, $count = count($this->fields); $i < $count; ++$i) { BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id); } } return true; } }
function delete() { global $wpdb, $bp; if (!$this->can_delete) { return false; } $sql = $wpdb->prepare("DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id); if (!$wpdb->query($sql)) { return false; } else { // Now the group is deleted, remove the group's fields. if (BP_XProfile_Field::delete_for_group($this->id)) { // Now delete all the profile data for the groups fields for ($i = 0; $i < count($this->fields); $i++) { BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id); } } return true; } }
/** * xprofile_edit() * * Renders the edit form for the profile fields within a group as well as * handling the save action. * * [NOTE] This is old code that was written when editing was not done in the theme. * It is big and clunky and will be broken up in future versions. * * @package BuddyPress XProfile * @param $group_id The ID of the group of fields to edit * @param $action The HTML form action * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() * @global $wpdb WordPress DB access object. * @global $userdata WordPress global object containing current logged in user userdata */ function xprofile_edit($group_id, $action) { global $wpdb, $userdata, $bp; // Create a new group object based on the group ID. $group = new BP_XProfile_Group($group_id); ?> <div class="wrap"> <h2><?php echo attribute_escape($group->name); ?> <?php _e("Information", 'buddypress'); ?> </h2> <?php // If this group has fields then continue if ($group->fields) { $errors = null; $list_html = '<ul class="forTab" id="' . strtolower($group_name) . '">'; // Loop through each field in the group for ($j = 0; $j < count($group->fields); $j++) { // Create a new field object for this field based on the field ID. $field = new BP_XProfile_Field($group->fields[$j]->id); // Add the ID for this field to the field_ids array $field_ids[] = $group->fields[$j]->id; // If the user has submitted the form - validate and save the new value for this field if (isset($_GET['mode']) && 'save' == $_GET['mode']) { /* Check the nonce */ if (!check_admin_referer('bp_xprofile_edit')) { return false; } // If the current field is a datebox, we need to append '_day' to the end of the field name // otherwise the field name will not exist $post_field_string = 'datebox' == $group->fields[$j]->type ? '_day' : null; // Explode the posted field IDs into an array so we know which fields have been submitted $posted_fields = explode(',', $_POST['field_ids']); // Fetch the current field from the _POST array based on field ID. $current_field = $_POST['field_' . $posted_fields[$j] . $post_field_string]; // If the field is required and has been left blank then we need to add a callback error. if ($field->is_required && !isset($current_field) || $field->is_required && empty($current_field)) { // Add the error message to the errors array $field->message = sprintf(__('%s cannot be left blank.', 'buddypress'), $field->name); $errors[] = $field->message . "<br />"; // If the field is not required and the field has been left blank, delete any values for the // field from the database. } else { if (!$field->is_required && (empty($current_field) || is_null($current_field))) { // Create a new profile data object for the logged in user based on field ID. $profile_data = new BP_Xprofile_ProfileData($group->fields[$j]->id, $bp->loggedin_user->id); if ($profile_data) { // Delete any data $profile_data->delete(); // Also remove any selected profile field data from the $field object. $field->data->value = null; } // If we get to this point then the field validates ok and we have new data. } else { // Create an empty profile data object and populate it with new data $profile_data = new BP_Xprofile_ProfileData(); $profile_data->field_id = $group->fields[$j]->id; $profile_data->user_id = $userdata->ID; $profile_data->last_updated = time(); // If the $post_field_string we set up earlier is not null, then this is a datebox // we need to concatenate each of the three select boxes for day, month and year into // one value. if ($post_field_string != null) { // Concatenate the values. $date_value = $_POST['field_' . $group->fields[$j]->id . '_day'] . $_POST['field_' . $group->fields[$j]->id . '_month'] . $_POST['field_' . $group->fields[$j]->id . '_year']; // Turn the concatenated value into a timestamp $profile_data->value = strtotime($date_value); } else { // Checkbox and multi select box fields will submit an array as their value // so we need to serialize them before saving to the DB. if (is_array($current_field)) { $current_field = serialize($current_field); } $profile_data->value = $current_field; } // Finally save the value to the database. if (!$profile_data->save()) { $field->message = __('There was a problem saving changes to this field, please try again.', 'buddypress'); } else { $field->data->value = $profile_data->value; } } } } // Each field object comes with HTML that can be rendered to edit that field. // We just need to render that to the page by adding it to the $list_html variable // that will be rendered when the field loop has finished. $list_html .= '<li>' . $field->get_edit_html() . '</li>'; } // Now that the loop has finished put the final touches on the HTML including the submit button. $list_html .= '</ul>'; $list_html .= '<p class="submit"> <input type="submit" name="save" id="save" value="' . __('Save Changes »', 'buddypress') . '" /> </p>'; $list_html .= wp_nonce_field('bp_xprofile_edit'); // If the user submitted the form to save new values, and there were errors, make sure we display them. if ($errors && isset($_POST['save'])) { $type = 'error'; $message = __('There were problems saving your information. Please fix the following:<br />', 'buddypress'); for ($i = 0; $i < count($errors); $i++) { $message .= $errors[$i]; } // If there were no errors then we can display a nice "Changes saved." message. } else { if (!$errors && isset($_POST['save'])) { $type = 'success'; $message = __('Changes saved.', 'buddypress'); // Record in activity stream xprofile_record_activity(array('item_id' => $group->id, 'component_name' => 'profile', 'component_action' => 'updated_profile', 'is_private' => 0)); do_action('xprofile_updated_profile', $group->id); } } } else { ?> <div id="message" class="error fade"> <p><?php _e('That group does not exist.', 'buddypress'); ?> </p> </div> <?php } ?> <?php // Finally, we can now render everything to the screen. ?> <?php if ($message != '') { $type = 'error' == $type ? 'error' : 'updated'; ?> <div id="message" class="<?php echo $type; ?> fade"> <p><?php echo $message; ?> </p> </div> <?php } ?> <p><form action="<?php echo $action; ?> " method="post" id="profile-edit-form" class="generic-form"> <?php if ($field_ids) { $field_ids = implode(",", $field_ids); } ?> <input type="hidden" name="field_ids" id="field_ids" value="<?php echo attribute_escape($field_ids); ?> " /> <?php echo $list_html; ?> </form> </p> </div> <?php }
/** * Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens. * * You don't need to implement this method for all field types. It's used in core by the * selectbox, multi selectbox, checkbox, and radio button fields, to allow the admin to * enter the child option values (e.g. the choices in a select box). * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 2.0.0 * * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. * @param string $control_type Optional. HTML input type used to render the current * field's child options. */ public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Please enter options for this Field:', 'buddypress'); ?> </h3> <div class="inside" aria-live="polite" aria-atomic="true" aria-relevant="all"> <p> <label for="sort_order_<?php echo esc_attr($type); ?> "><?php esc_html_e('Sort Order:', 'buddypress'); ?> </label> <select name="sort_order_<?php echo esc_attr($type); ?> " id="sort_order_<?php echo esc_attr($type); ?> " > <option value="custom" <?php selected('custom', $current_field->order_by); ?> ><?php esc_html_e('Custom', 'buddypress'); ?> </option> <option value="asc" <?php selected('asc', $current_field->order_by); ?> ><?php esc_html_e('Ascending', 'buddypress'); ?> </option> <option value="desc" <?php selected('desc', $current_field->order_by); ?> ><?php esc_html_e('Descending', 'buddypress'); ?> </option> </select> </p> <?php // Does option have children? $options = $current_field->get_children(true); // If no children options exists for this field, check in $_POST // for a submitted form (e.g. on the "new field" screen). if (empty($options)) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } // Grab the values from $_POST to use as the form's options. $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } // If there are still no children options set, this must be the "new field" screen, so add one new/empty option. if (empty($options)) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } // Render the markup for the children options. if (!empty($options)) { $default_name = ''; for ($i = 0, $count = count($options); $i < $count; ++$i) { $j = $i + 1; // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && $current_type_obj->supports_multiple_defaults) { $default_name = '[' . $j . ']'; } ?> <div id="<?php echo esc_attr("{$type}_div{$j}"); ?> " class="bp-option sortable"> <span class="bp-option-icon grabber"></span> <label for="<?php echo esc_attr("{$type}_option{$j}"); ?> " class="screen-reader-text"><?php /* translators: accessibility text */ esc_html_e('Add an option', 'buddypress'); ?> </label> <input type="text" name="<?php echo esc_attr("{$type}_option[{$j}]"); ?> " id="<?php echo esc_attr("{$type}_option{$j}"); ?> " value="<?php echo esc_attr(stripslashes($options[$i]->name)); ?> " /> <label for="<?php echo esc_attr("{$type}_option{$default_name}"); ?> "> <input type="<?php echo esc_attr($control_type); ?> " id="<?php echo esc_attr("{$type}_option{$default_name}"); ?> " name="<?php echo esc_attr("isDefault_{$type}_option{$default_name}"); ?> " <?php checked($options[$i]->is_default_option, true); ?> value="<?php echo esc_attr($j); ?> " /> <?php _e('Default Value', 'buddypress'); ?> </label> <?php if (1 !== $j) { ?> <div class ="delete-button"> <a href='javascript:hide("<?php echo esc_attr("{$type}_div{$j}"); ?> ")' class="delete"><?php esc_html_e('Delete', 'buddypress'); ?> </a> </div> <?php } ?> </div> <?php } ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option_number"); ?> " id="<?php echo esc_attr("{$type}_option_number"); ?> " value="<?php echo esc_attr($j + 1); ?> " /> <?php } ?> <div id="<?php echo esc_attr("{$type}_more"); ?> "></div> <p><a href="javascript:add_option('<?php echo esc_js($type); ?> ')"><?php esc_html_e('Add Another Option', 'buddypress'); ?> </a></p> <?php /** * Fires at the end of the new field additional settings area. * * @since 2.3.0 * * @param BP_XProfile_Field $current_field Current field being rendered. */ do_action('bp_xprofile_admin_new_field_additional_settings', $current_field); ?> </div> </div> <?php }
/** * GMW FL search form function - Display xprofile fields * @version 1.0 * @author Eyal Fitoussi */ function gmw_fl_xprofile_fields($gmw, $class) { if (!isset($gmw['search_form']['profile_fields']) && !isset($gmw['search_form']['profile_fields_date'])) { return; } $total_fields = isset($gmw['search_form']['profile_fields']) ? $gmw['search_form']['profile_fields'] : array(); if (isset($gmw['search_form']['profile_fields_date'])) { array_unshift($total_fields, $gmw['search_form']['profile_fields_date']); } echo '<div class="gmw-fl-form-xprofile-fields gmw-fl-form-xprofile-fields-' . $gmw['ID'] . ' ' . $class . '">'; $total_fields = apply_filters('gmw_fl_form_xprofile_field_before_displayed', $total_fields, $gmw); foreach ($total_fields as $field_id) { $fdata = new BP_XProfile_Field($field_id); $fname = 'field_' . $field_id; $label = $fdata->name; $fclass = 'field-' . $field_id; $fid = 'gmw-' . $gmw['ID'] . '-field-' . $field_id; $children = $fdata->get_children(); echo '<div class="editfield ' . $fdata->type . ' gmw-' . $gmw['ID'] . '-field-' . $field_id . '-wrapper">'; switch ($fdata->type) { case 'datebox': case 'birthdate': $value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : ''; $max = isset($_REQUEST[$fname . '_max']) ? esc_attr(stripslashes($_REQUEST[$fname . '_max'])) : ''; echo '<label for="' . $fid . '">' . __('Age Range (min - max)', 'GMW') . '</label>'; echo '<input size="3" type="text" name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '" value="' . $value . '" placeholder="' . __('Min', 'GMW') . '" />'; echo ' - '; echo '<input size="3" type="text" name="' . $fname . '_max" id="' . $fid . '_max" class="' . $fclass . '_max" value="' . $max . '" placeholder="' . __('Max', 'GMW') . '" />'; break; case 'textbox': $value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : ''; echo '<label for="' . $fid . '">' . $label . '</label>'; echo '<input type="text" name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '" value="' . $value . '" />'; break; case 'number': $value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : ''; echo '<label for="' . $fid . '">' . $label . '</label>'; echo '<input type="number" name="' . $fname . '" id="' . $fid . '" value="' . $value . '" />'; break; case 'textarea': $value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : ''; echo '<label for="' . $fid . '">' . $label . '</label>'; echo '<textarea rows="5" cols="40" name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '">' . $value . '</textarea>'; break; case 'selectbox': $value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : ''; echo '<label for="' . $fid . '">' . $label . '</label>'; echo '<select name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '">'; echo '<option value="">' . __(' -- All -- ', 'GMW') . '</option>'; foreach ($children as $child) { $option = trim($child->name); $selected = $option == $value ? "selected='selected'" : ""; echo '<option ' . $selected . ' value="' . $option . '" />' . $option . '</label>'; } echo '</select>'; break; case 'multiselectbox': $value = isset($_REQUEST[$fname]) ? $_REQUEST[$fname] : array(); echo '<label for="' . $fid . '">' . $label . '</label>'; echo '<select name="' . $fname . '[]" id="' . $fid . '" class="' . $fclass . '" multiple="multiple">'; foreach ($children as $child) { $option = trim($child->name); $selected = in_array($option, $value) ? "selected='selected'" : ""; echo '<option ' . $selected . ' value="' . $option . '" />' . $option . '</label>'; } echo "</select>"; break; case 'radio': $value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : ''; echo '<div class="radio">'; echo '<span class="label">' . $label . '</span>'; foreach ($children as $child) { $option = trim($child->name); $checked = $child->name == $value ? "checked='checked'" : ""; echo '<label><input ' . $checked . ' type="radio" name="' . $fname . '" value="' . $option . '" />' . $option . '</label>'; } echo '<a href="#" onclick="event.preventDefault();jQuery(this).closest(\'div\').find(\'input\').prop(\'checked\', false);">' . __('Clear', 'buddypress') . '</a><br/>'; echo '</div>'; break; case 'checkbox': $value = isset($_REQUEST[$fname]) ? $_REQUEST[$fname] : array(); echo '<div class="checkbox">'; echo '<span class="label">' . $label . '</span>'; foreach ($children as $child) { $option = trim($child->name); $checked = in_array($option, $value) ? "checked='checked'" : ""; echo '<label><input ' . $checked . ' type="checkbox" name="' . $fname . '[]" value="' . $option . '" />' . $option . '</label>'; } echo '</div>'; break; } // switch echo '</div>'; } echo '</div>'; }
function xprofile_update_field_position($field_id, $position, $field_group_id) { return BP_XProfile_Field::update_position($field_id, $position, $field_group_id); }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $text = ''; $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } $options[] = (object) array('id' => 0, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); $text .= sanitize_text_field(stripslashes($_POST[$type . '_option'][$i])); ++$i; } if (!$options) { $options[] = (object) array('id' => 0, 'is_default_option' => false, 'name' => ''); } } else { foreach ($options as $option) { $text .= rawurldecode($option->name); } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Use this field to write a text that should be displayed beside the checkbox:', 'bxcft'); ?> </h3> <div class="inside"> <p> <textarea name="<?php echo esc_attr("{$type}_text"); ?> " id="<?php echo esc_attr("{$type}_text"); ?> " rows="5" cols="60"><?php echo $text; ?> </textarea> </p> </div> <?php if ($options) { $i = 1; ?> <?php foreach ($options as $option) { ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option[{$i}]"); ?> " id ="<?php echo esc_attr("{$type}_option{$i}"); ?> " value="<?php echo $option->name; ?> " /> <?php $i++; } ?> <?php } ?> </div> <?php }
/** * @group member_types * @ticket BP5192 */ public function test_member_type_null_should_be_respected() { $g = $this->factory->xprofile_group->create(); $f1 = $this->factory->xprofile_field->create(array('field_group_id' => $g)); $f2 = $this->factory->xprofile_field->create(array('field_group_id' => $g)); bp_register_member_type('foo'); bp_register_member_type('bar'); $field1 = new BP_XProfile_Field($f1); $field1->set_member_types(array('foo')); $found_groups = BP_XProfile_Group::get(array('member_type' => array('null'), 'fetch_fields' => true)); // The groups aren't indexed, so we have to go looking for it. foreach ($found_groups as $fg) { if ($g == $fg->id) { $the_group = $fg; } } $this->assertNotContains($f1, wp_list_pluck($the_group->fields, 'id')); $this->assertContains($f2, wp_list_pluck($the_group->fields, 'id')); }
/** * Save the global field value. * * @since 1.0 * * @param object $field */ public function bp_xprofile_save_global_field_value($field) { if (!empty($_POST['saveField'])) { if (BP_XProfile_Field::admin_validate()) { $field_id = $field->id; if (empty($field_id)) { $field_id = BP_XProfile_Field::get_id_from_name($field->name); } $this->__update_xprofile_meta($field_id, 'field', 'global_value', $_POST['fieldvalue']); } } }
/** * Handles the deletion of a profile field (or field option) * * @since BuddyPress (1.0.0) * @global string $message The feedback message to show * @global $type The type of feedback message to show * @param int $field_id The field to delete * @param string $field_type The type of field being deleted * @param bool $delete_data Should the field data be deleted too? */ function xprofile_admin_delete_field($field_id, $field_type = 'field', $delete_data = false) { global $message, $type; // Switch type to 'option' if type is not 'field' // @todo trust this param $field_type = 'field' == $field_type ? __('field', 'buddypress') : __('option', 'buddypress'); $field = new BP_XProfile_Field($field_id); if (!$field->delete((bool) $delete_data)) { $message = sprintf(__('There was an error deleting the %s. Please try again.', 'buddypress'), $field_type); $type = 'error'; } else { $message = sprintf(__('The %s was deleted successfully!', 'buddypress'), $field_type); $type = 'success'; /** * Fires at the end of the field deletion process, if successful. * * @since BuddyPress (1.0.0) * * @param BP_XProfile_Field $field Current BP_XProfile_Field object. */ do_action('xprofile_fields_deleted_field', $field); } unset($_GET['mode']); xprofile_admin($message, $type); }
/** * Retrieve a `BP_XProfile_Field` instance. * * @static * * @param int $field_id ID of the field. * @return BP_XProfile_Field|false Field object if found, otherwise false. */ public static function get_instance($field_id) { global $wpdb; $field_id = (int) $field_id; if (!$field_id) { return false; } $field = wp_cache_get($field_id, 'bp_xprofile_fields'); if (false === $field) { $bp = buddypress(); $field = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id)); wp_cache_add($field->id, $field, 'bp_xprofile_fields'); if (!$field) { return false; } } $_field = new BP_XProfile_Field(); $_field->fill_data($field); return $_field; }
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); }
/** * Populates the BP_XProfile_Group object with profile field groups, fields, * and field data * * @package BuddyPress XProfile * * @global object $wpdb WordPress DB access object. * * @param array $args { * Array of optional arguments: * @type int $profile_group_id Limit results to a single profile group. * @type int $user_id Required if you want to load a specific user's data. * Default: displayed user's ID. * @type array|string $member_type Limit fields by those restricted to a given member type, or array of * member types. If `$user_id` is provided, the value of `$member_type` * will be overridden by the member types of the provided user. The * special value of 'any' will return only those fields that are * unrestricted by member type - i.e., those applicable to any type. * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false. * @type bool $hide_empty_fields True to hide fields where the user has not provided data. * Default: false. * @type bool $fetch_fields Whether to fetch each group's fields. Default: false. * @type bool $fetch_field_data Whether to fetch data for each field. Requires a $user_id. * Default: false. * @type array $exclude_groups Comma-separated list or array of group IDs to exclude. * @type array $exclude_fields Comma-separated list or array of field IDs to exclude. * @type bool $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields, * and data. Default: true. * } * @return array $groups */ public static function get($args = array()) { global $wpdb; // Parse arguments. $r = wp_parse_args($args, array('profile_group_id' => false, 'user_id' => bp_displayed_user_id(), 'member_type' => false, 'hide_empty_groups' => false, 'hide_empty_fields' => false, 'fetch_fields' => false, 'fetch_field_data' => false, 'fetch_visibility_level' => false, 'exclude_groups' => false, 'exclude_fields' => false, 'update_meta_cache' => true)); // Keep track of object IDs for cache-priming. $object_ids = array('group' => array(), 'field' => array(), 'data' => array()); // WHERE. if (!empty($r['profile_group_id'])) { $where_sql = $wpdb->prepare('WHERE g.id = %d', $r['profile_group_id']); } elseif ($r['exclude_groups']) { $exclude = join(',', wp_parse_id_list($r['exclude_groups'])); $where_sql = "WHERE g.id NOT IN ({$exclude})"; } else { $where_sql = ''; } $bp = buddypress(); // Include or exclude empty groups. if (!empty($r['hide_empty_groups'])) { $group_ids = $wpdb->get_col("SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC"); } else { $group_ids = $wpdb->get_col("SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC"); } // Get all group data. $groups = self::get_group_data($group_ids); // Bail if not also getting fields. if (empty($r['fetch_fields'])) { return $groups; } // Get the group ids from the groups we found. $group_ids = wp_list_pluck($groups, 'id'); // Store for meta cache priming. $object_ids['group'] = $group_ids; // Bail if no groups found. if (empty($group_ids)) { return $groups; } // Setup IN query from group IDs. $group_ids_in = implode(',', (array) $group_ids); // Support arrays and comma-separated strings. $exclude_fields_cs = wp_parse_id_list($r['exclude_fields']); // Visibility - Handled here so as not to be overridden by sloppy use of the // exclude_fields parameter. See bp_xprofile_get_hidden_fields_for_user(). $hidden_user_fields = bp_xprofile_get_hidden_fields_for_user($r['user_id']); $exclude_fields_cs = array_merge($exclude_fields_cs, $hidden_user_fields); $exclude_fields_cs = implode(',', $exclude_fields_cs); // Set up NOT IN query for excluded field IDs. if (!empty($exclude_fields_cs)) { $exclude_fields_sql = "AND id NOT IN ({$exclude_fields_cs})"; } else { $exclude_fields_sql = ''; } // Set up IN query for included field IDs. $include_field_ids = array(); // Member-type restrictions. if (bp_get_member_types()) { if ($r['user_id'] || false !== $r['member_type']) { $member_types = $r['member_type']; if ($r['user_id']) { $member_types = bp_get_member_type($r['user_id'], false); if (empty($member_types)) { $member_types = array('null'); } } $member_types_fields = BP_XProfile_Field::get_fields_for_member_type($member_types); $include_field_ids += array_keys($member_types_fields); } } $in_sql = ''; if (!empty($include_field_ids)) { $include_field_ids_cs = implode(',', array_map('intval', $include_field_ids)); $in_sql = " AND id IN ({$include_field_ids_cs}) "; } // Fetch the fields. $field_ids = $wpdb->get_col("SELECT id FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids_in} ) AND parent_id = 0 {$exclude_fields_sql} {$in_sql} ORDER BY field_order"); // Bail if no fields. if (empty($field_ids)) { return $groups; } $field_ids = array_map('intval', $field_ids); // Prime the field cache. $uncached_field_ids = bp_get_non_cached_ids($field_ids, 'bp_xprofile_fields'); if (!empty($uncached_field_ids)) { $_uncached_field_ids = implode(',', array_map('intval', $uncached_field_ids)); $uncached_fields = $wpdb->get_results("SELECT * FROM {$bp->profile->table_name_fields} WHERE id IN ({$_uncached_field_ids})"); foreach ($uncached_fields as $uncached_field) { $fid = intval($uncached_field->id); wp_cache_set($fid, $uncached_field, 'bp_xprofile_fields'); } } // Pull field objects from the cache. $fields = array(); foreach ($field_ids as $field_id) { $fields[] = xprofile_get_field($field_id); } // Store field IDs for meta cache priming. $object_ids['field'] = $field_ids; // Maybe fetch field data. if (!empty($r['fetch_field_data'])) { // Get field data for user ID. if (!empty($field_ids) && !empty($r['user_id'])) { $field_data = BP_XProfile_ProfileData::get_data_for_user($r['user_id'], $field_ids); } // Remove data-less fields, if necessary. if (!empty($r['hide_empty_fields']) && !empty($field_ids) && !empty($field_data)) { // Loop through the results and find the fields that have data. foreach ((array) $field_data as $data) { // Empty fields may contain a serialized empty array. $maybe_value = maybe_unserialize($data->value); // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. if ((!empty($maybe_value) || '0' == $maybe_value) && false !== ($key = array_search($data->field_id, $field_ids))) { // Fields that have data get removed from the list. unset($field_ids[$key]); } } // The remaining members of $field_ids are empty. Remove them. foreach ($fields as $field_key => $field) { if (in_array($field->id, $field_ids)) { unset($fields[$field_key]); } } // Reset indexes. $fields = array_values($fields); } // Field data was found. if (!empty($fields) && !empty($field_data) && !is_wp_error($field_data)) { // Loop through fields. foreach ((array) $fields as $field_key => $field) { // Loop through the data in each field. foreach ((array) $field_data as $data) { // Assign correct data value to the field. if ($field->id == $data->field_id) { $fields[$field_key]->data = new stdClass(); $fields[$field_key]->data->value = $data->value; $fields[$field_key]->data->id = $data->id; } // Store for meta cache priming. $object_ids['data'][] = $data->id; } } } } // Prime the meta cache, if necessary. if (!empty($r['update_meta_cache'])) { bp_xprofile_update_meta_cache($object_ids); } // Maybe fetch visibility levels. if (!empty($r['fetch_visibility_level'])) { $fields = self::fetch_visibility_level($r['user_id'], $fields); } // Merge the field array back in with the group array. foreach ((array) $groups as $group) { // Indexes may have been shifted after previous deletions, so we get a // fresh one each time through the loop. $index = array_search($group, $groups); foreach ((array) $fields as $field) { if ($group->id === $field->group_id) { $groups[$index]->fields[] = $field; } } // When we unset fields above, we may have created empty groups. // Remove them, if necessary. if (empty($group->fields) && !empty($r['hide_empty_groups'])) { unset($groups[$index]); } // Reset indexes. $groups = array_values($groups); } return $groups; }
function bps_field_options($id) { static $options = array(); if (isset($options[$id])) { return $options[$id]; } $field = new BP_XProfile_Field($id); if (empty($field->id)) { return array(); } $options[$id] = array(); $rows = $field->get_children(); if (is_array($rows)) { foreach ($rows as $row) { $options[$id][stripslashes(trim($row->name))] = stripslashes(trim($row->name)); } } return $options[$id]; }
public function bxcft_get_field_value($value = '', $type = '', $id = '') { $value_to_return = strip_tags($value); if ($value_to_return !== '') { // Birthdate. if ($type == 'birthdate') { $show_age = false; $field = new BP_XProfile_Field($id); if ($field) { $childs = $field->get_children(); if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0]) && $childs[0]->name == 'show_age') { $show_age = true; } } if ($show_age) { $value_to_return = floor((time() - strtotime($value_to_return)) / 31556926); } else { $value_to_return = date_i18n(get_option('date_format'), strtotime($value_to_return)); } } elseif ($type == 'email') { if (strpos($value_to_return, 'mailto') === false) { $value_to_return = sprintf('<a href="mailto:%s">%s</a>', $value_to_return, $value_to_return); } } elseif ($type == 'web') { if (strpos($value_to_return, 'href=') === false) { $value_to_return = sprintf('<a href="%s">%s</a>', $value_to_return, $value_to_return); } } elseif ($type == 'datepicker') { $value_to_return = date_i18n(get_option('date_format'), strtotime($value_to_return)); } elseif ($type == 'select_custom_post_type') { $field = new BP_XProfile_Field($id); if ($field) { $childs = $field->get_children(); if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) { $post_type_selected = $childs[0]->name; } $post = get_post($value_to_return); if ($post->post_type == $post_type_selected) { $value_to_return = $post->post_title; } else { // Custom post type is not the same. $value_to_return = '--'; } } else { $value_to_return = '--'; } } elseif ($type == 'multiselect_custom_post_type') { $field = new BP_XProfile_Field($id); if ($field) { $values = explode(",", $value_to_return); $childs = $field->get_children(); if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) { $post_type_selected = $childs[0]->name; $cad = ''; foreach ($values as $v) { $post = get_post($v); if ($post->post_type == $post_type_selected) { if ($cad == '') { $cad .= '<ul class="list_custom_post_type">'; } $cad .= '<li>' . $post->post_title . '</li>'; } } if ($cad != '') { $cad .= '</ul>'; } } $value_to_return = $cad; } else { $value_to_return = '--'; } } elseif ($type == 'checkbox_acceptance') { $value_to_return = (int) $value_to_return == 1 ? __('yes', 'bxcft') : __('no', 'bxcft'); } elseif ($type == 'image') { $uploads = wp_upload_dir(); if (strpos($value_to_return, $uploads['baseurl']) === false) { $value_to_return = $uploads['baseurl'] . $value_to_return; } $value_to_return = '<img src="' . $value_to_return . '" alt="" />'; } elseif ($type == 'file') { $uploads = wp_upload_dir(); if (strpos($value_to_return, $uploads['baseurl']) === false) { $value_to_return = $uploads['baseurl'] . $value_to_return; } $value_to_return = '<a href="' . $value_to_return . '">' . __('Download file', 'bxcft') . '</a>'; } elseif ($type == 'color') { if (strpos($value_to_return, '#') === false) { $value_to_return = '#' . $value_to_return; } } else { // Not stripping tags. $value_to_return = $value; } } return apply_filters('bxcft_show_field_value', $value_to_return, $type, $id, $value); }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); $min = ''; $max = ''; if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { $is_default_option = true; $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => '2'); } } else { foreach ($options as $o) { if (strpos($o->name, 'min_') !== false) { $min = str_replace('min_', '', $o->name); } if (strpos($o->name, 'max_') !== false) { $max = str_replace('max_', '', $o->name); } } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Write min and max values. You can leave any field blank if you want.', 'bxcft'); ?> </h3> <div class="inside"> <p> <label for="<?php echo esc_attr("{$type}_option1"); ?> "> <?php esc_html_e('Minimum:', 'bxcft'); ?> </label> <input type="text" name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option1"); ?> " value="<?php echo $min; ?> " /> <label for="<?php echo esc_attr("{$type}_option2"); ?> "> <?php esc_html_e('Maximum:', 'bxcft'); ?> </label> <input type="text" name="<?php echo esc_attr("{$type}_option[2]"); ?> " id="<?php echo esc_attr("{$type}_option2"); ?> " value="<?php echo $max; ?> " /> </p> </div> </div> <script> var error_msg_number_minmax = '<?php esc_html_e("Min value cannot be bigger than max value.", "bxcft"); ?> ', error_msg_number_minmax_empty = '<?php esc_html_e("You have to fill at least one field.", "bxcft"); ?> '; </script> <?php }
/** * Handles the adding or editing of profile field data for a user. * * @param int $group_id ID of the group. * @param int|null $field_id ID of the field being managed. */ function xprofile_admin_manage_field($group_id, $field_id = null) { global $wpdb, $message, $groups; $bp = buddypress(); if (is_null($field_id)) { $field = new BP_XProfile_Field(); } else { $field = xprofile_get_field($field_id); } $field->group_id = $group_id; if (isset($_POST['saveField'])) { if (BP_XProfile_Field::admin_validate()) { $field->is_required = $_POST['required']; $field->type = $_POST['fieldtype']; $field->name = $_POST['title']; if (!empty($_POST['description'])) { $field->description = $_POST['description']; } else { $field->description = ''; } if (!empty($_POST["sort_order_{$field->type}"])) { $field->order_by = $_POST["sort_order_{$field->type}"]; } $field->field_order = $wpdb->get_var($wpdb->prepare("SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id)); if (empty($field->field_order) || is_wp_error($field->field_order)) { $field->field_order = (int) $wpdb->get_var($wpdb->prepare("SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id)); $field->field_order++; } // For new profile fields, set the $field_id. For existing profile // fields, this will overwrite $field_id with the same value. $field_id = $field->save(); if (empty($field_id)) { $message = __('There was an error saving the field. Please try again.', 'buddypress'); $type = 'error'; } else { $message = __('The field was saved successfully.', 'buddypress'); $type = 'success'; // @todo remove these old options if (1 == $field_id) { bp_update_option('bp-xprofile-fullname-field-name', $field->name); } // Set member types. if (isset($_POST['has-member-types'])) { $member_types = array(); if (isset($_POST['member-types'])) { $member_types = stripslashes_deep($_POST['member-types']); } $field->set_member_types($member_types); } // Validate default visibility. if (!empty($_POST['default-visibility']) && in_array($_POST['default-visibility'], wp_list_pluck(bp_xprofile_get_visibility_levels(), 'id'))) { bp_xprofile_update_field_meta($field_id, 'default_visibility', $_POST['default-visibility']); } // Validate custom visibility. if (!empty($_POST['allow-custom-visibility']) && in_array($_POST['allow-custom-visibility'], array('allowed', 'disabled'))) { bp_xprofile_update_field_meta($field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility']); } // Validate signup. if (!empty($_POST['signup-position'])) { bp_xprofile_update_field_meta($field_id, 'signup_position', (int) $_POST['signup-position']); } else { bp_xprofile_delete_meta($field_id, 'field', 'signup_position'); } /** * Fires at the end of the process to save a field for a user, if successful. * * @since 1.0.0 * * @param BP_XProfile_Field $field Current BP_XProfile_Field object. */ do_action('xprofile_fields_saved_field', $field); $groups = bp_xprofile_get_groups(); } unset($_GET['mode']); xprofile_admin($message, $type); } else { $field->render_admin_form($message); } } else { $field->render_admin_form(); } }
/** * 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 function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } $taxonomies = get_taxonomies(array('public' => true, '_builtin' => false)); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <?php if (!$taxonomies) { ?> <h3><?php _e('There is no custom taxonomy. You need to create at least one to use this field.', 'bxcft'); ?> </h3> <?php } else { ?> <h3><?php esc_html_e('Select a custom taxonomy:', 'bxcft'); ?> </h3> <div class="inside"> <p> <?php _e('Select a custom taxonomy:', 'bxcft'); ?> <select name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option[1]"); ?> "> <option value=""><?php _e('Select...', 'bxcft'); ?> </option> <?php foreach ($taxonomies as $k => $v) { ?> <option value="<?php echo $k; ?> "<?php if ($options[0]->name == $k) { ?> selected="selected"<?php } ?> ><?php echo $v; ?> </option> <?php } ?> </select> </p> </div> <?php } ?> </div> <?php }
/** * Handles the deletion of a profile field (or field option) * * @since BuddyPress (1.0) * @global string $message The feedback message to show * @global $type The type of feedback message to show * @param int $field_id The field to delete * @param string $field_type The type of field being deleted * @param bool $delete_data Should the field data be deleted too? */ function xprofile_admin_delete_field($field_id, $field_type = 'field', $delete_data = false) { global $message, $type; // Switch type to 'option' if type is not 'field' // @todo trust this param $field_type = 'field' == $field_type ? __('field', 'buddypress') : __('option', 'buddypress'); $field = new BP_XProfile_Field($field_id); if (!$field->delete((bool) $delete_data)) { $message = sprintf(__('There was an error deleting the %s. Please try again', 'buddypress'), $field_type); $type = 'error'; } else { $message = sprintf(__('The %s was deleted successfully!', 'buddypress'), $field_type); $type = 'success'; do_action('xprofile_fields_deleted_field', $field); } unset($_GET['mode']); xprofile_admin($message, $type); }
function xprofile_admin_delete_field($field_id, $type = 'field') { global $message, $type; if ('field' == $type) { $type = __('field', 'buddypress'); } else { $type = __('option', 'buddypress'); } $field = new BP_XProfile_Field($field_id); if (!$field->delete()) { $message = sprintf(__('There was an error deleting the %s. Please try again', 'buddypress'), $type); $type = 'error'; } else { $message = sprintf(__('The %s was deleted successfully!', 'buddypress'), $type); $type = 'success'; do_action('xprofile_fields_deleted_field', $field); } unset($_GET['mode']); xprofile_admin($message, $type); }
function xprofile_validate_signup_fields($result) { global $bp_xprofile_callback, $avatar_error, $avatar_error_msg, $has_errors; global $canvas, $original; global $current_site, $active_signup; global $wp_upload_error; if ($_POST['stage'] != 'validate-user-signup') { return $result; } // form has been submitted, let's validate the form // using the built in Wordpress functions and our own. extract($result); $counter = 0; $has_errors = false; $prev_field_id = -1; // Validate all sign up fields $fields = BP_XProfile_Field::get_signup_fields(); if ($fields) { foreach ($fields as $field) { $value = $_POST['field_' . $field->id]; // Need to check if the previous field had // the same ID, as to not validate individual // day/month/year dropdowns individually. if ($prev_field_id != $field->id) { $field = new BP_XProfile_Field($field->id); if ('datebox' == $field->type) { if ($_POST['field_' . $field->id . '_day'] != "" && $_POST['field_' . $field->id . '_month'] != "" && $_POST['field_' . $field->id . '_year'] != "") { $value = strtotime($_POST['field_' . $field->id . '_day'] . " " . $_POST['field_' . $field->id . '_month'] . " " . $_POST['field_' . $field->id . '_year']); } } if (is_array($value)) { $value = serialize($value); } $bp_xprofile_callback[$counter] = array("field_id" => $field->id, "type" => $field->type, "value" => $value); if ($field->is_required && empty($value)) { $bp_xprofile_callback[$counter]["error_msg"] = sprintf(__('%s cannot be left blank', 'buddypress'), $field->name); $has_errors = true; } $counter++; } $prev_field_id = $field->id; } } // validate the avatar upload if there is one. $avatar_error = false; $checked_upload = false; $checked_size = false; $checked_type = false; $original = false; $canvas = false; // Set friendly error feedback. $uploadErrors = array(0 => __("There is no error, the file uploaded with success", 'buddypress'), 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE), 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE), 3 => __("The uploaded file was only partially uploaded", 'buddypress'), 6 => __("Missing a temporary folder", 'buddypress')); if (isset($_FILES['file'])) { if (4 !== $_FILES['file']['error']) { if (!($checked_upload = bp_core_check_avatar_upload($_FILES))) { $avatar_error = true; $avatar_error_msg = $uploadErrors[$_FILES['file']['error']]; } if ($checked_upload && !($checked_size = bp_core_check_avatar_size($_FILES))) { $avatar_error = true; $avatar_size = size_format(CORE_MAX_FILE_SIZE); $avatar_error_msg = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), $avatar_size); } if ($checked_upload && $checked_size && !($checked_type = bp_core_check_avatar_type($_FILES))) { $avatar_error = true; $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.', 'buddypress'); } // "Handle" upload into temporary location if ($checked_upload && $checked_size && $checked_type && !($original = bp_core_handle_avatar_upload($_FILES))) { $avatar_error = true; $avatar_error_msg = sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error); } if ($checked_upload && $checked_size && $checked_type && $original && !($canvas = bp_core_resize_avatar($original))) { $canvas = $original; } } } if (!$has_errors && !$avatar_error) { $public = (int) $_POST['blog_public']; // put the user profile meta in a session ready to store. for ($i = 0; $i < count($bp_xprofile_callback); $i++) { $meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value']; } $meta['xprofile_field_ids'] = $_POST['xprofile_ids']; $meta['avatar_image_resized'] = $canvas; $meta['avatar_image_original'] = $original; $_SESSION['xprofile_meta'] = $meta; } else { $errors->add('bp_xprofile_errors', ''); } return array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); }
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(); switch ( $field->type ) { case 'selectbox': case 'multiselectbox': if ( 'multiselectbox' != $field->type ) $html .= '<option value="">--------</option>'; for ( $k = 0; $k < count($options); $k++ ) { $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id ) ); $option_values = (array)$option_values; /* Check for updated posted values, but errors preventing them from being saved first time */ foreach( (array)$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]; } } if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option ) { $selected = ' selected="selected"'; } else { $selected = ''; } $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . stripslashes( esc_attr( $options[$k]->name ) ) . '">' . stripslashes( esc_attr( $options[$k]->name ) ) . '</option>', $options[$k] ); } break; case 'radio': $html = '<div id="field_' . $field->id . '">'; for ( $k = 0; $k < count($options); $k++ ) { $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id); /* 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]; } if ( $option_value == $options[$k]->name || $value == $options[$k]->name || ( empty( $option_value ) && $options[$k]->is_default_option ) ) { $selected = ' checked="checked"'; } else { $selected = ''; } $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="' . stripslashes( esc_attr( $options[$k]->name ) ) . '"> ' . stripslashes( esc_attr( $options[$k]->name ) ) . '</label>', $options[$k] ); } $html .= '</div>'; break; case 'checkbox': $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id); /* 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]; } $option_values = maybe_unserialize($option_values); for ( $k = 0; $k < count($options); $k++ ) { for ( $j = 0; $j < count($option_values); $j++ ) { if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) { $selected = ' checked="checked"'; break; } } $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="' . stripslashes( esc_attr( $options[$k]->name ) ) . '"> ' . stripslashes( esc_attr( $options[$k]->name ) ) . '</label>', $options[$k] ); $selected = ''; } break; case 'datebox': if ( !empty( $field->data->value ) ) { $day = date("j", $field->data->value); $month = date("F", $field->data->value); $year = date("Y", $field->data->value); $default_select = ' selected="selected"'; } /* 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=""' . esc_attr( $default_select ) . '>--</option>'; for ( $i = 1; $i < 32; $i++ ) { if ( $day == $i ) { $selected = ' selected = "selected"'; } else { $selected = ''; } $html .= '<option value="' . $i .'"' . $selected . '>' . $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=""' . esc_attr( $default_select ) . '>------</option>'; for ( $i = 0; $i < 12; $i++ ) { if ( $month == $eng_months[$i] ) { $selected = ' selected = "selected"'; } else { $selected = ''; } $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>'; } break; case 'year': $html .= '<option value=""' . esc_attr( $default_select ) . '>----</option>'; for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) { if ( $year == $i ) { $selected = ' selected = "selected"'; } else { $selected = ''; } $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>'; } break; } apply_filters( 'bp_get_the_profile_field_datebox', $html, $day, $month, $year, $default_select ); break; } return $html; }
/** * Each time a field is saved, BuddyPress deletes the options to recreate them * * So we need to wait till the options are recreated to save their descriptions. * * @param BP_XProfile_Field $field the member type field object * @global $wpdb WP DB API */ function cfbgr_update_options_description($field = null) { global $wpdb; // Get the the Member types xProfile field $saved_option = (int) bp_get_option('cfbgr_xfield_id', 0); if (empty($field->id) || empty($saved_option) || (int) $field->id !== $saved_option) { return; } if (empty($field->type_obj->descriptions)) { return; } $options = $field->get_children(true); if (!empty($options) && is_array($options)) { foreach ($options as $option) { if (!empty($field->type_obj->descriptions[$option->name])) { $wpdb->update(buddypress()->profile->table_name_fields, array('description' => stripslashes(wp_kses($field->type_obj->descriptions[$option->name], array()))), array('id' => $option->id), array('%s'), array('%d')); } } // Make sure to update only once ! unset($field->type_obj->descriptions); } }
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); $options = $current_field->get_children(true); if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { $is_default_option = true; $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => '2'); } } ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Select max number of decimals:', 'bxcft'); ?> </h3> <div class="inside"> <p> <select name="<?php echo esc_attr("{$type}_option[1]"); ?> " id="<?php echo esc_attr("{$type}_option1"); ?> "> <?php for ($j = 1; $j <= 6; $j++) { ?> <option value="<?php echo $j; ?> "<?php if ($j === (int) $options[0]->name) { ?> selected="selected"<?php } ?> ><?php echo $j; ?> </option> <?php } ?> </select> </p> </div> </div> <?php }
public static function prepare_buddypress_data($user_id, $config, $entry) { // required for user to display in the directory if (function_exists('bp_update_user_last_activity')) { bp_update_user_last_activity($user_id); } else { bp_update_user_meta($user_id, 'last_activity', true); } $buddypress_meta = rgars($config, 'meta/buddypress_meta'); if (empty($buddypress_meta)) { return; } self::log_debug(__METHOD__ . '(): starting.'); $form = RGFormsModel::get_form_meta($entry['form_id']); $buddypress_row = array(); $i = 0; foreach ($buddypress_meta as $meta_item) { if (empty($meta_item['meta_name']) || empty($meta_item['meta_value'])) { continue; } $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']); if (version_compare(BP_VERSION, '1.6', '<')) { $bp_field = new BP_XProfile_Field(); $bp_field->bp_xprofile_field($meta_item['meta_name']); } else { require_once WP_PLUGIN_DIR . '/buddypress/bp-xprofile/bp-xprofile-classes.php'; $bp_field = new BP_XProfile_Field($meta_item['meta_name']); } // if bp field is a checkbox AND gf field is a checkbox, get array of input values $input_type = RGFormsModel::get_input_type($gform_field); if (in_array($bp_field->type, array('checkbox', 'multiselectbox')) && in_array($input_type, array('checkbox', 'multiselect'))) { $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field); if (!is_array($meta_value)) { $meta_value = explode(',', $meta_value); } $meta_value = self::maybe_get_category_name($gform_field, $meta_value); $meta_value = array_filter($meta_value, 'GFUser::not_empty'); } else { if ($bp_field->type == 'datebox' && $gform_field['type'] == 'date') { if (version_compare(BP_VERSION, '2.1.1', '<')) { $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) . ' 00:00:00'; } } else { $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry); } } self::log_debug(__METHOD__ . "(): Meta item: {$meta_item['meta_name']}. Value: {$meta_value}"); $buddypress_row[$i]['value'] = $meta_value; $buddypress_row[$i]['last_update'] = date('Y-m-d H:i:s'); $buddypress_row[$i]['field'] = $bp_field; $i++; } GFUserData::insert_buddypress_data($buddypress_row); self::log_debug(__METHOD__ . '(): finished.'); }
/** * @group cache */ public function test_get_fields_for_member_type_should_skip_cache_after_a_fields_member_type_is_modified() { global $wpdb; $this->field->set_member_types(array('foo')); // Prime cache. BP_XProfile_Field::get_fields_for_member_type('foo'); $num_queries = $wpdb->num_queries; $this->field->set_member_types(array('none')); $found = BP_XProfile_Field::get_fields_for_member_type('foo'); $this->assertTrue($num_queries + 2 <= $wpdb->num_queries); $this->assertEqualSets(array(1), array_keys($found)); }
/** * Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens. * * You don't need to implement this method for all field types. It's used in core by the * selectbox, multi selectbox, checkbox, and radio button fields, to allow the admin to * enter the child option values (e.g. the choices in a select box). * * Must be used inside the {@link bp_profile_fields()} template loop. * * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. * @param string $control_type Optional. HTML input type used to render the current field's child options. * @since BuddyPress (2.0.0) */ public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '') { $type = array_search(get_class($this), bp_xprofile_get_field_types()); if (false === $type) { return; } $class = $current_field->type != $type ? 'display: none;' : ''; $current_type_obj = bp_xprofile_create_field_type($type); ?> <div id="<?php echo esc_attr($type); ?> " class="postbox bp-options-box" style="<?php echo esc_attr($class); ?> margin-top: 15px;"> <h3><?php esc_html_e('Please enter options for this Field:', 'buddypress'); ?> </h3> <div class="inside"> <p> <label for="sort_order_<?php echo esc_attr($type); ?> "><?php esc_html_e('Sort Order:', 'buddypress'); ?> </label> <select name="sort_order_<?php echo esc_attr($type); ?> " id="sort_order_<?php echo esc_attr($type); ?> " > <option value="custom" <?php selected('custom', $current_field->order_by); ?> ><?php esc_html_e('Custom', 'buddypress'); ?> </option> <option value="asc" <?php selected('asc', $current_field->order_by); ?> ><?php esc_html_e('Ascending', 'buddypress'); ?> </option> <option value="desc" <?php selected('desc', $current_field->order_by); ?> ><?php esc_html_e('Descending', 'buddypress'); ?> </option> </select> </p> <?php $options = $current_field->get_children(true); // If no children options exists for this field, check in $_POST for a submitted form (e.g. on the "new field" screen). if (!$options) { $options = array(); $i = 1; while (isset($_POST[$type . '_option'][$i])) { // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) { $is_default_option = true; } elseif (isset($_POST["isDefault_{$type}_option"][$i])) { $is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i]; } else { $is_default_option = false; } // Grab the values from $_POST to use as the form's options $options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]))); ++$i; } // If there are still no children options set, this must be the "new field" screen, so add one new/empty option. if (!$options) { $options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => ''); } } // Render the markup for the children options if (!empty($options)) { $default_name = ''; for ($i = 0, $count = count($options); $i < $count; ++$i) { $j = $i + 1; // Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE. if ($current_type_obj->supports_options && $current_type_obj->supports_multiple_defaults) { $default_name = '[' . $j . ']'; } ?> <p class="sortable"> <span> Ξ </span> <input type="text" name="<?php echo esc_attr("{$type}_option[{$j}]"); ?> " id="<?php echo esc_attr("{$type}_option{$j}"); ?> " value="<?php echo esc_attr(stripslashes($options[$i]->name)); ?> " /> <input type="<?php echo esc_attr($control_type); ?> " name="<?php echo esc_attr("isDefault_{$type}_option{$default_name}"); ?> " <?php checked($options[$i]->is_default_option, true); ?> value="<?php echo esc_attr($j); ?> " /> <span><?php _e('Default Value', 'buddypress'); ?> </span> <?php if (1 <= $i) { ?> <a href="<?php echo esc_url('users.php?page=bp-profile-setup&mode=delete_option&option_id=' . $options[$i]->id); ?> " class="ajax-option-delete" id="delete-<?php echo esc_attr($options[$i]->id); ?> ">[x]</a> <?php } ?> </p> <?php } ?> <input type="hidden" name="<?php echo esc_attr("{$type}_option_number"); ?> " id="<?php echo esc_attr("{$type}_option_number"); ?> " value="<?php echo esc_attr($j + 1); ?> " /> <?php } ?> <div id="<?php echo esc_attr("{$type}_more"); ?> "></div> <p><a href="javascript:add_option('<?php echo esc_js($type); ?> ')"><?php esc_html_e('Add Another Option', 'buddypress'); ?> </a></p> </div> </div> <?php }
/** * Delete a profile field group * * @since BuddyPress (1.1.0) * * @global object $wpdb * @return boolean */ public function delete() { global $wpdb; // Bail if field group cannot be deleted if (empty($this->can_delete)) { return false; } /** * Fires before the current group instance gets deleted. * * @since BuddyPress (2.0.0) * * @param BP_XProfile_Group Current instance of the group being deleted. Passed by reference. */ do_action_ref_array('xprofile_group_before_delete', array(&$this)); $bp = buddypress(); $sql = $wpdb->prepare("DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id); $deleted = $wpdb->query($sql); // Delete field group if (empty($deleted) || is_wp_error($deleted)) { return false; } // Remove the group's fields. if (BP_XProfile_Field::delete_for_group($this->id)) { // Remove profile data for the groups fields for ($i = 0, $count = count($this->fields); $i < $count; ++$i) { BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id); } } /** * Fires after the current group instance gets deleted. * * @since BuddyPress (2.0.0) * * @param BP_XProfile_Group Current instance of the group being deleted. Passed by reference. */ do_action_ref_array('xprofile_group_after_delete', array(&$this)); return true; }