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 
        }
    /**
     * 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 
    }
/**
 * A simple function to set profile data for a specific field for a specific user.
 *
 * @package BuddyPress Core
 * @param int|string $field The ID of the field, or the $name of the field.
 * @param int|$user_id The ID of the user
 * @param mixed The value for the field you want to set for the user.
 * @global BuddyPress $bp The one true BuddyPress instance
 * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name.
 * @return bool True on success, false on failure.
 */
function xprofile_set_field_data($field, $user_id, $value, $is_required = false)
{
    if (is_numeric($field)) {
        $field_id = $field;
    } else {
        $field_id = xprofile_get_field_id_from_name($field);
    }
    if (empty($field_id)) {
        return false;
    }
    // Special-case support for integer 0 for the number field type
    if ($is_required && !is_integer($value) && $value !== '0' && (empty($value) || !is_array($value) && !strlen(trim($value)))) {
        return false;
    }
    $field = new BP_XProfile_Field($field_id);
    $field_type = BP_XProfile_Field::get_type($field_id);
    $field_type_obj = bp_xprofile_create_field_type($field_type);
    /**
     * Certain types of fields (checkboxes, multiselects) may come through empty.
     * Save as empty array so this isn't overwritten by the default on next edit.
     *
     * Special-case support for integer 0 for the number field type
     */
    if (empty($value) && !is_integer($value) && $value !== '0' && $field_type_obj->accepts_null_value) {
        $value = array();
    }
    // If the value is empty, then delete any field data that exists, unless the field is of a type where null values are semantically meaningful
    if (empty($value) && !is_integer($value) && $value !== '0' && !$field_type_obj->accepts_null_value) {
        xprofile_delete_field_data($field_id, $user_id);
        return true;
    }
    // For certain fields, only certain parameters are acceptable, so add them to the whitelist.
    if ($field_type_obj->supports_options) {
        $field_type_obj->set_whitelist_values(wp_list_pluck($field->get_children(), 'name'));
    }
    // Check the value is in an accepted format for this form field.
    if (!$field_type_obj->is_valid($value)) {
        return false;
    }
    $field = new BP_XProfile_ProfileData();
    $field->field_id = $field_id;
    $field->user_id = $user_id;
    $field->value = maybe_serialize($value);
    return $field->save();
}
/**
 * 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 bxcft_special_fields_data_for_search_form($f)
 {
     $request = stripslashes_deep($_REQUEST);
     switch ($f->type) {
         case 'select_custom_post_type':
         case 'multiselect_custom_post_type':
             $f->values = isset($request[$f->code]) ? (array) $request[$f->code] : array();
             $field = new BP_XProfile_Field($f->id);
             $array_options = array();
             if ($field) {
                 $childs = $field->get_children();
                 if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) {
                     $post_type_selected = $childs[0]->name;
                     $posts = new WP_Query(array('posts_per_page' => -1, 'post_type' => $post_type_selected, 'orderby' => 'title', 'order' => 'ASC'));
                     if ($posts) {
                         foreach ($posts->posts as $p) {
                             $array_options[$p->ID] = $p->post_title;
                         }
                     }
                 }
             }
             $f->options = $array_options;
             if ($f->type === 'select_custom_post_type') {
                 $f->display = 'selectbox';
             } else {
                 $f->display = 'multiselectbox';
             }
             break;
         case 'select_custom_taxonomy':
         case 'multiselect_custom_taxonomy':
             $f->values = isset($request[$f->code]) ? (array) $request[$f->code] : array();
             $field = new BP_XProfile_Field($f->id);
             $array_options = array();
             if ($field) {
                 $childs = $field->get_children();
                 if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) {
                     $taxonomy_selected = $childs[0]->name;
                     $terms = get_terms($taxonomy_selected, array('hide_empty' => false));
                     if ($terms) {
                         foreach ($terms as $t) {
                             $array_options[$t->term_id] = $t->name;
                         }
                     }
                 }
             }
             $f->options = $array_options;
             if ($f->type === 'select_custom_taxonomy') {
                 $f->display = 'selectbox';
             } else {
                 $f->display = 'multiselectbox';
             }
             break;
         case 'checkbox_acceptance':
             $f->values = isset($request[$f->code]) ? (array) $request[$f->code] : array();
             $f->options = array(0 => __('no', 'bxcft'), 1 => __('yes', 'bxcft'));
             $f->display = 'radio';
             break;
         case 'image':
         case 'file':
             $f->values = isset($request[$f->code]) ? (array) $request[$f->code] : array();
             $f->options = array(1 => __('Not empty', 'bxcft'));
             $f->display = 'checkbox';
             break;
     }
     return $f;
 }
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 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 
        }
        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 
        }
/**
 * 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 '&nbsp;-&nbsp;';
                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 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;
	}
 public function build_field_dd($current_field, $selected_field_id)
 {
     $groups = BP_XProfile_Group::get(array('fetch_fields' => true));
     $html = '';
     foreach ($groups as $group) {
         //if there are no fields in this group, no need to proceed further
         if (empty($group->fields)) {
             continue;
         }
         $html .= "<option value='0'> " . _x('Select Field', 'Fild selection title in admin', 'conditional-profile-fields-for-bp') . "</option>";
         $html .= "<optgroup label ='{ {$group->name} }'>";
         foreach ($group->fields as $field) {
             //can not have condition for itself
             if ($field->id == $current_field->id) {
                 continue;
             }
             $field = new BP_XProfile_Field($field->id, false, false);
             // $field->type_obj->supports_options;
             //$field->type_obj->supports_multiple_defaults;
             $html .= "<option value='{$field->id}'" . selected($field->id, $selected_field_id, false) . " >{$field->name}</option>";
             if ($field->type_obj->supports_options) {
                 $this->fields_info['field_' . $field->id]['type'] = 'multi';
                 $children = $field->get_children();
                 $this->fields_info['field_' . $field->id]['options'] = $children;
                 //get all children and we will render the view to select one of these children
             } else {
                 $this->fields_info['field_' . $field->id]['type'] = 'single';
             }
             //now, let us build an optgroup
         }
         $html .= "</optgroup>";
         echo $html;
         //$this->fields_info[]
     }
 }
        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' => '');
                }
            }
            ?>
            <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('Show age (hide birthdate):', 'bxcft');
            ?>
</h3>
                <div class="inside">
                    <p>
                        <?php 
            _e('Check this if you want to show age instead of birthdate:', 'bxcft');
            ?>
                        <input type="hidden" name="<?php 
            echo esc_attr("{$type}_option[0]");
            ?>
" id="<?php 
            echo esc_attr("{$type}_option0");
            ?>
" value="show_birthdate" />
                        <input type="checkbox" name="<?php 
            echo esc_attr("{$type}_option[1]");
            ?>
" id="<?php 
            echo esc_attr("{$type}_option1");
            ?>
" value="show_age"
                               <?php 
            if ($options[0]->name == 'show_age') {
                ?>
checked="checked"<?php 
            }
            ?>
/>
                    </p>
                </div>
            </div>
        <?php 
        }
Example #13
0
/**
 * xprofile_set_field_data()
 *
 * A simple function to set profile data for a specific field for a specific user.
 *
 * @package BuddyPress Core
 * @param $field The ID of the field, or the $name of the field.
 * @param $user_id The ID of the user
 * @param $value The value for the field you want to set for the user.
 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
 * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name.
 * @return true on success, false on failure.
 */
function xprofile_set_field_data( $field, $user_id, $value, $is_required = false ) {
	if ( is_numeric( $field ) )
		$field_id = $field;
	else
		$field_id = xprofile_get_field_id_from_name( $field );

	if ( !$field_id )
		return false;

	if ( $is_required && ( empty( $value ) || !strlen( trim( $value ) ) ) )
		return false;

	/* If the value is empty, then delete any field data that exists */
	if ( empty( $value ) ) {
		xprofile_delete_field_data( $field_id, $user_id );
		return true;
	}

	$field = new BP_XProfile_Field( $field_id );

	/* Check the value is an acceptable value */
	if ( 'checkbox' == $field->type || 'radio' == $field->type || 'selectbox' == $field->type || 'multiselectbox' == $field->type ) {
		$options = $field->get_children();

		foreach( $options as $option )
			$possible_values[] = $option->name;

		if ( is_array( $value ) ) {
			foreach( $value as $i => $single ) {
				if ( !in_array( $single, (array)$possible_values ) )
					unset( $value[$i] );
			}

			if ( empty( $value ) )
				return false;

			/* Reset the keys by merging with an empty array */
			$value = array_merge( array(), $value );
		} else {
			if ( !in_array( $value, (array)$possible_values ) )
				return false;
		}
	}

	$field = new BP_XProfile_ProfileData();
	$field->field_id = $field_id;
	$field->user_id = $user_id;
	$field->value = maybe_serialize( $value );

	return $field->save();
}
/**
 * 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);
            $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 
        }
/**
 * A simple function to set profile data for a specific field for a specific user.
 *
 * @package BuddyPress Core
 * @param $field The ID of the field, or the $name of the field.
 * @param $user_id The ID of the user
 * @param $value The value for the field you want to set for the user.
 * @global object $bp Global BuddyPress settings object
 * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name.
 * @return true on success, false on failure.
 */
function xprofile_set_field_data($field, $user_id, $value, $is_required = false)
{
    if (is_numeric($field)) {
        $field_id = $field;
    } else {
        $field_id = xprofile_get_field_id_from_name($field);
    }
    if (empty($field_id)) {
        return false;
    }
    if ($is_required && (empty($value) || !is_array($value) && !strlen(trim($value)))) {
        return false;
    }
    $field = new BP_XProfile_Field($field_id);
    // If the value is empty, then delete any field data that exists, unless the field is of a
    // type where null values are semantically meaningful
    if (empty($value) && 'checkbox' != $field->type && 'multiselectbox' != $field->type) {
        xprofile_delete_field_data($field_id, $user_id);
        return true;
    }
    // Check the value is an acceptable value
    if ('checkbox' == $field->type || 'radio' == $field->type || 'selectbox' == $field->type || 'multiselectbox' == $field->type) {
        $options = $field->get_children();
        foreach ($options as $option) {
            $possible_values[] = $option->name;
        }
        if (is_array($value)) {
            foreach ($value as $i => $single) {
                if (!in_array($single, (array) $possible_values)) {
                    unset($value[$i]);
                }
            }
            // Reset the keys by merging with an empty array
            $value = array_merge(array(), $value);
        } else {
            if (!in_array($value, (array) $possible_values)) {
                return false;
            }
        }
    }
    $field = new BP_XProfile_ProfileData();
    $field->field_id = $field_id;
    $field->user_id = $user_id;
    $field->value = maybe_serialize($value);
    return $field->save();
}
 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);
 }
    /**
     * 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>&nbsp;&Xi;&nbsp;</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&amp;mode=delete_option&amp;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 
    }
 /**
  * Get the condition applied on a field
  * 
  * @param type $field_id
  * @return array('field_id', 'visibility', 'operator', 'value' )
  */
 public function get_field_condition($field_id)
 {
     $visibility = bp_xprofile_get_meta($field_id, 'field', 'xprofile_condition_display');
     $operator = bp_xprofile_get_meta($field_id, 'field', 'xprofile_condition_operator');
     $value2 = bp_xprofile_get_meta($field_id, 'field', 'xprofile_condition_other_field_value');
     //check if it was a muti type field, then we need to send the name as value instead of id
     $related_field_id = $this->get_related_field_id($field_id);
     $related_field = new BP_XProfile_Field($related_field_id);
     //is the related field having multi type?
     $children = $related_field->get_children();
     $value = array();
     if (!empty($children)) {
         //if yes, we need to replace the value(as the value is id of the child option) with the name of the child option
         foreach ($children as $child) {
             if (in_array($child->id, $value2)) {
                 array_push($value, $child->name);
                 //$value = stripslashes( $child->name );
                 //break;
             }
         }
     }
     return compact('field_id', 'visibility', 'operator', 'value');
 }