本文整理汇总了PHP中BP_XProfile_Field::get_children方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_XProfile_Field::get_children方法的具体用法?PHP BP_XProfile_Field::get_children怎么用?PHP BP_XProfile_Field::get_children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BP_XProfile_Field
的用法示例。
在下文中一共展示了BP_XProfile_Field::get_children方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: admin_new_field_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])) {
$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
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:67,代码来源:Bxcft_Field_Type_DecimalNumber.php
示例2: admin_new_field_html
/**
* 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' => '');
//.........这里部分代码省略.........
示例3: xprofile_set_field_data
/**
* 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();
}
示例4: cfbgr_update_options_description
/**
* 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);
}
}
示例5: bxcft_special_fields_data_for_search_form
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;
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:66,代码来源:bp-xprofile-custom-fields-type.php
示例6: bps_field_options
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];
}
示例7: admin_new_field_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);
$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
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:88,代码来源:Bxcft_Field_Type_CheckboxAcceptance.php
示例8: admin_new_field_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
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:94,代码来源:Bxcft_Field_Type_SelectCustomTaxonomy.php
示例9: gmw_fl_xprofile_fields
/**
* 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>';
//.........这里部分代码省略.........
示例10: array
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"';
}
//.........这里部分代码省略.........
示例11: build_field_dd
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[]
}
}
示例12: admin_new_field_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])) {
$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
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:64,代码来源:Bxcft_Field_Type_Birthdate.php
示例13: xprofile_set_field_data
/**
* 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();
}
示例14: bp_get_the_profile_field_options
/**
* 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];
}
//.........这里部分代码省略.........
示例15: admin_new_field_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
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:99,代码来源:Bxcft_Field_Type_NumberMinMax.php