本文整理汇总了PHP中BP_XProfile_ProfileData::get_value_byid方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_XProfile_ProfileData::get_value_byid方法的具体用法?PHP BP_XProfile_ProfileData::get_value_byid怎么用?PHP BP_XProfile_ProfileData::get_value_byid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BP_XProfile_ProfileData
的用法示例。
在下文中一共展示了BP_XProfile_ProfileData::get_value_byid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_field_options_html
/**
* Output the edit field options HTML for this field type.
*
* BuddyPress considers a field's "options" to be, for example, the items in a selectbox.
* These are stored separately in the database, and their templating is handled separately.
*
* This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because
* it's also used in the wp-admin screens when creating new fields, and for backwards compatibility.
*
* Must be used inside the {@link bp_profile_fields()} template loop.
*
* @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
*
*/
public function edit_field_options_html(array $args = array())
{
$original_option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']));
if (!empty($_POST['field_' . $this->field_obj->id])) {
$option_values = (array) $_POST['field_' . $this->field_obj->id];
$option_values = array_map('sanitize_text_field', $option_values);
} else {
$option_values = (array) $original_option_values;
}
//member types list as array
$options = self::get_roles();
$selected = '';
//$option_values = (array) $original_option_values;
if (empty($option_values) || in_array('none', $option_values)) {
$selected = ' selected="selected"';
}
$html = '<option value="" ' . $selected . ' >----' . '</option>';
echo $html;
foreach ($options as $role => $label) {
$selected = '';
// Run the allowed option name through the before_save filter, so we'll be sure to get a match
$allowed_options = xprofile_sanitize_data_value_before_save($role, false, false);
// First, check to see whether the user-entered value matches
if (in_array($allowed_options, (array) $option_values)) {
$selected = ' selected="selected"';
}
echo apply_filters('bp_get_the_profile_field_options_roles', '<option' . $selected . ' value="' . esc_attr(stripslashes($role)) . '">' . $label . '</option>', $role, $this->field_obj->id, $selected);
}
}
示例2: profile_screen_admin
/**
* profile_screen_admin()
*
* Filters option for 'Teacher', only admins are allowed to access it.
*/
function profile_screen_admin($options)
{
for ($i = 0; $i < count($options); $i++) {
if (!is_super_admin() && $options[$i]->name == __('Teacher', 'bpsp') && BP_XProfile_ProfileData::get_value_byid($options[$i]->parent_id) != __('Teacher', 'bpsp')) {
unset($options[$i]);
}
}
return array_merge($options);
}
示例3: edit_field_options_html
/**
* Output the edit field options HTML for this field type.
*
* BuddyPress considers a field's "options" to be, for example, the items in a selectbox.
* These are stored separately in the database, and their templating is handled separately.
*
* This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because
* it's also used in the wp-admin screens when creating new fields, and for backwards compatibility.
*
* Must be used inside the {@link bp_profile_fields()} template loop.
*
* @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
*
*/
public function edit_field_options_html(array $args = array())
{
$original_option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']));
if (!empty($_POST['field_' . $this->field_obj->id])) {
$option_values = (array) $_POST['field_' . $this->field_obj->id];
$option_values = array_map('sanitize_text_field', $option_values);
} else {
$option_values = (array) $original_option_values;
}
//member types list as array
$options = self::get_member_types();
//$option_values = (array) $original_option_values;
if ($this->display_as_radio()) {
$this->_edit_options_html_radio($option_values, $options);
} else {
$this->_edit_options_html($option_values, $options);
}
}
示例4: edit_field_options_html
/**
* Output the edit field options HTML for this field type.
*
* BuddyPress considers a field's "options" to be, for example, the items in a selectbox.
* These are stored separately in the database, and their templating is handled separately.
*
* This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because
* it's also used in the wp-admin screens when creating new fields, and for backwards compatibility.
*
* Must be used inside the {@link bp_profile_fields()} template loop.
*
* @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
* @since 2.0.0
*/
public function edit_field_options_html(array $args = array())
{
$option_value = BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']);
$options = $this->field_obj->get_children();
$html = sprintf('<div id="%s">', esc_attr('field_' . $this->field_obj->id));
for ($k = 0, $count = count($options); $k < $count; ++$k) {
// Check for updated posted values, but errors preventing them from
// being saved first time
if (isset($_POST['field_' . $this->field_obj->id]) && $option_value != $_POST['field_' . $this->field_obj->id]) {
if (!empty($_POST['field_' . $this->field_obj->id])) {
$option_value = sanitize_text_field($_POST['field_' . $this->field_obj->id]);
}
}
// Run the allowed option name through the before_save filter, so
// we'll be sure to get a match
$allowed_options = xprofile_sanitize_data_value_before_save($options[$k]->name, false, false);
$selected = '';
if ($option_value === $allowed_options || empty($option_value) && !empty($options[$k]->is_default_option)) {
$selected = ' checked="checked"';
}
$new_html = sprintf('<label><input %1$s type="radio" name="%2$s" id="%3$s" value="%4$s">%5$s</label>', $selected, esc_attr("field_{$this->field_obj->id}"), esc_attr("option_{$options[$k]->id}"), esc_attr(stripslashes($options[$k]->name)), esc_html(stripslashes($options[$k]->name)));
/**
* Filters the HTML output for an individual field options radio button.
*
* @since 1.1.0
*
* @param string $new_html Label and radio input field.
* @param object $value Current option being rendered for.
* @param int $id ID of the field object being rendered.
* @param string $selected Current selected value.
* @param string $k Current index in the foreach loop.
*/
$html .= apply_filters('bp_get_the_profile_field_options_radio', $new_html, $options[$k], $this->field_obj->id, $selected, $k);
}
echo $html . '</div>';
}
示例5: 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];
}
//.........这里部分代码省略.........
示例6: xprofile_filter_comments
function xprofile_filter_comments($comments, $post_id)
{
foreach ((array) $comments as $comment) {
if ($comment->user_id) {
$user_ids[] = $comment->user_id;
}
}
if (empty($user_ids)) {
return $comments;
}
if ($fullnames = BP_XProfile_ProfileData::get_value_byid(1, $user_ids)) {
foreach ((array) $fullnames as $user) {
$users[$user->user_id] = trim($user->value);
}
}
foreach ((array) $comments as $i => $comment) {
if (!empty($comment->user_id)) {
if (!empty($users[$comment->user_id])) {
$comments[$i]->comment_author = $users[$comment->user_id];
}
}
}
return $comments;
}
示例7: xprofile_get_field_data
/**
* xprofile_get_field_data()
*
* Fetches profile data for a specific field for the 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
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
* @uses BP_XProfile_ProfileData::get_value_byfieldname() Fetches the value based on the params passed.
* @return The profile field data.
*/
function xprofile_get_field_data( $field, $user_id = null ) {
global $bp;
if ( !$user_id )
$user_id = $bp->displayed_user->id;
if ( !$user_id )
return false;
if ( is_numeric( $field ) )
$field_id = $field;
else
$field_id = xprofile_get_field_id_from_name( $field );
if ( !$field_id )
return false;
return apply_filters( 'xprofile_get_field_data', BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) );
}
示例8: edit_field_options_html
/**
* Output the edit field options HTML for this field type.
*
* BuddyPress considers a field's "options" to be, for example, the items in a selectbox.
* These are stored separately in the database, and their templating is handled seperately.
*
* This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because
* it's also used in the wp-admin screens when creating new fields, and for backwards compatibility.
*
* Must be used inside the {@link bp_profile_fields()} template loop.
*
* @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
* @since BuddyPress (2.0.0)
*/
public function edit_field_options_html(array $args = array())
{
$original_option_values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']));
$options = $this->field_obj->get_children();
$html = '<option value="">' . esc_html__('----', 'buddypress') . '</option>';
if (empty($original_option_values) && !empty($_POST['field_' . $this->field_obj->id])) {
$original_option_values = sanitize_text_field($_POST['field_' . $this->field_obj->id]);
}
$option_values = (array) $original_option_values;
for ($k = 0, $count = count($options); $k < $count; ++$k) {
$selected = '';
// Check for updated posted values, but errors preventing them from being saved first time
foreach ($option_values as $i => $option_value) {
if (isset($_POST['field_' . $this->field_obj->id]) && $_POST['field_' . $this->field_obj->id] != $option_value) {
if (!empty($_POST['field_' . $this->field_obj->id])) {
$option_values[$i] = sanitize_text_field($_POST['field_' . $this->field_obj->id]);
}
}
}
// Run the allowed option name through the before_save filter, so we'll be sure to get a match
$allowed_options = xprofile_sanitize_data_value_before_save($options[$k]->name, false, false);
// First, check to see whether the user-entered value matches
if (in_array($allowed_options, $option_values)) {
$selected = ' selected="selected"';
}
// Then, if the user has not provided a value, check for defaults
if (!is_array($original_option_values) && empty($option_values) && $options[$k]->is_default_option) {
$selected = ' selected="selected"';
}
$html .= apply_filters('bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr(stripslashes($options[$k]->name)) . '">' . esc_html(stripslashes($options[$k]->name)) . '</option>', $options[$k], $this->field_obj->id, $selected, $k);
}
echo $html;
}
示例9: bp_core_get_user_displaynames
/**
* Fetch the display name for a group of users.
*
* Uses the 'Name' field in xprofile if available. Falls back on WP
* display_name, and then user_nicename.
*
* @since 2.0.0
*
* @param array $user_ids Array of user IDs to get display names for.
* @return array
*/
function bp_core_get_user_displaynames($user_ids)
{
// Sanitize.
$user_ids = wp_parse_id_list($user_ids);
// Remove dupes and empties.
$user_ids = array_unique(array_filter($user_ids));
if (empty($user_ids)) {
return array();
}
$uncached_ids = array();
foreach ($user_ids as $user_id) {
if (false === wp_cache_get('bp_user_fullname_' . $user_id, 'bp')) {
$uncached_ids[] = $user_id;
}
}
// Prime caches.
if (!empty($uncached_ids)) {
if (bp_is_active('xprofile')) {
$fullname_data = BP_XProfile_ProfileData::get_value_byid(1, $uncached_ids);
// Key by user_id.
$fullnames = array();
foreach ($fullname_data as $fd) {
if (!empty($fd->value)) {
$fullnames[intval($fd->user_id)] = $fd->value;
}
}
// If xprofiledata is not found for any users, we'll look
// them up separately.
$no_xprofile_ids = array_diff($uncached_ids, array_keys($fullnames));
} else {
$fullnames = array();
$no_xprofile_ids = $user_ids;
}
if (!empty($no_xprofile_ids)) {
// Use WP_User_Query because we don't need BP information.
$query = new WP_User_Query(array('include' => $no_xprofile_ids, 'fields' => array('ID', 'user_nicename', 'display_name'), 'count_total' => false, 'blog_id' => 0));
foreach ($query->results as $qr) {
$fullnames[$qr->ID] = !empty($qr->display_name) ? $qr->display_name : $qr->user_nicename;
// If xprofile is active, set this value as the
// xprofile display name as well.
if (bp_is_active('xprofile')) {
xprofile_set_field_data(1, $qr->ID, $fullnames[$qr->ID]);
}
}
}
foreach ($fullnames as $fuser_id => $fname) {
wp_cache_set('bp_user_fullname_' . $fuser_id, $fname, 'bp');
}
}
$retval = array();
foreach ($user_ids as $user_id) {
$retval[$user_id] = wp_cache_get('bp_user_fullname_' . $user_id, 'bp');
}
return $retval;
}
示例10: xprofile_get_field_data
/**
* Fetches profile data for a specific field for the user.
*
* When the field value is serialized, this function unserializes and filters each item in the array
* that results.
*
* @package BuddyPress Core
* @param mixed $field The ID of the field, or the $name of the field.
* @param int $user_id The ID of the user
* @global object $bp Global BuddyPress settings object
* @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.
* @return mixed The profile field data.
*/
function xprofile_get_field_data($field, $user_id = 0)
{
global $bp;
if (empty($user_id)) {
$user_id = $bp->displayed_user->id;
}
if (empty($user_id)) {
return false;
}
if (is_numeric($field)) {
$field_id = $field;
} else {
$field_id = xprofile_get_field_id_from_name($field);
}
if (empty($field_id)) {
return false;
}
$values = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($field_id, $user_id));
if (is_array($values)) {
$data = array();
foreach ((array) $values as $value) {
$data[] = apply_filters('xprofile_get_field_data', $value, $field_id, $user_id);
}
} else {
$data = apply_filters('xprofile_get_field_data', $values, $field_id, $user_id);
}
return $data;
}
示例11: edit_field_options_html
public function edit_field_options_html(array $args = array())
{
$options = $this->field_obj->get_children();
$checkbox_acceptance = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']));
if (!empty($_POST['field_' . $this->field_obj->id])) {
$new_checkbox_acceptance = $_POST['field_' . $this->field_obj->id];
$checkbox_acceptance = $checkbox_acceptance != $new_checkbox_acceptance ? $new_checkbox_acceptance : $checkbox_acceptance;
}
$html = '<input type="checkbox" name="check_acc_' . bp_get_the_profile_field_input_name() . '" id="check_acc_' . bp_get_the_profile_field_input_name() . '"';
if ($checkbox_acceptance == 1) {
$html .= ' checked="checked"';
}
if (isset($args['required']) && $args['required']) {
$html .= ' required="required" aria-required="true"';
}
$html .= ' value="1" /> ';
$html .= '<input type="hidden" name="' . bp_get_the_profile_field_input_name() . '" id="' . bp_get_the_profile_field_input_name() . '"';
if ($checkbox_acceptance == 1) {
$html .= ' value="1" /> ';
} else {
$html .= ' value="0" /> ';
}
if ($options) {
foreach ($options as $option) {
$html .= rawurldecode($option->name);
}
}
// Javascript.
$html .= '
<script>
jQuery(document).ready(function() {
jQuery("#check_acc_' . bp_get_the_profile_field_input_name() . '").click(function() {
if (jQuery(this).is(":checked")) {
jQuery("#' . bp_get_the_profile_field_input_name() . '").val("1");
} else {
jQuery("#' . bp_get_the_profile_field_input_name() . '").val("0");
}
});
});
</script>
';
echo apply_filters('bp_get_the_profile_field_checkbox_acceptance', $html, $args['type'], $this->field_obj->id, $checkbox_acceptance);
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:43,代码来源:Bxcft_Field_Type_CheckboxAcceptance.php
示例12: edit_field_options_html
public function edit_field_options_html(array $args = array())
{
$options = $this->field_obj->get_children();
$posts_selected = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']));
$html = '';
if ($options) {
$post_type_selected = $options[0]->name;
if (!empty($_POST['field_' . $this->field_obj->id])) {
$new_posts_selected = $_POST['field_' . $this->field_obj->id];
$posts_selected = $posts_selected != $new_posts_selected ? $new_posts_selected : $posts_selected;
}
// Get posts of custom post type selected.
$posts = new WP_Query(array('posts_per_page' => -1, 'post_type' => $post_type_selected, 'orderby' => 'title', 'order' => 'ASC'));
if ($posts) {
foreach ($posts->posts as $post) {
$html .= sprintf('<option value="%s"%s>%s</option>', $post->ID, !empty($posts_selected) && in_array($post->ID, $posts_selected) ? 'selected="selected"' : '', $post->post_title);
}
}
}
echo apply_filters('bp_get_the_profile_field_multiselect_custom_post_type', $html, $args['type'], $post_type_selected, $this->field_obj->id);
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:21,代码来源:Bxcft_Field_Type_MultiSelectCustomPostType.php
示例13: bp_get_the_profile_field_options
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"';
}
//.........这里部分代码省略.........
示例14: edit_field_options_html
public function edit_field_options_html(array $args = array())
{
$options = $this->field_obj->get_children();
$date = BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']);
$day = 0;
$month = 0;
$year = 0;
$html = '';
// Set day, month, year defaults
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, and errors preventing them from being saved first time.
if (!empty($_POST['field_' . $this->field_obj->id . '_day'])) {
$new_day = (int) $_POST['field_' . $this->field_obj->id . '_day'];
$day = $day != $new_day ? $new_day : $day;
}
if (!empty($_POST['field_' . $this->field_obj->id . '_month'])) {
$new_month = $_POST['field_' . $this->field_obj->id . '_month'];
$month = $month != $new_month ? $new_month : $month;
}
if (!empty($_POST['field_' . $this->field_obj->id . '_year'])) {
$new_year = date('j', (int) $_POST['field_' . $this->field_obj->id . '_year']);
$year = $year != $new_year ? $new_year : $year;
}
// $type will be passed by calling function when needed
switch ($args['type']) {
case 'day':
$html = sprintf('<option value="" %1$s>%2$s</option>', selected($day, 0, false), __('----', 'buddypress'));
for ($i = 1; $i < 32; ++$i) {
$html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected($day, $i, false), (int) $i);
}
break;
case 'month':
$eng_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$months = array(0 => __('January', 'buddypress'), 1 => __('February', 'buddypress'), 2 => __('March', 'buddypress'), 3 => __('April', 'buddypress'), 4 => __('May', 'buddypress'), 5 => __('June', 'buddypress'), 6 => __('July', 'buddypress'), 7 => __('August', 'buddypress'), 8 => __('September', 'buddypress'), 9 => __('October', 'buddypress'), 10 => __('November', 'buddypress'), 11 => __('December', 'buddypress'));
$html = sprintf('<option value="" %1$s>%2$s</option>', selected($month, 0, false), __('----', 'buddypress'));
for ($i = 0; $i < 12; ++$i) {
$html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($eng_months[$i]), selected($month, $eng_months[$i], false), $months[$i]);
}
break;
case 'year':
$html = sprintf('<option value="" %1$s>%2$s</option>', selected($year, 0, false), __('----', 'buddypress'));
for ($i = date('Y') - 1; $i > 1901; $i--) {
$html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected($year, $i, false), (int) $i);
}
break;
}
echo apply_filters('bp_get_the_profile_field_birthdate', $html, $args['type'], $day, $month, $year, $this->field_obj->id, $date);
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:61,代码来源:Bxcft_Field_Type_Birthdate.php
示例15: edit_field_options_html
/**
* Output the edit field options HTML for this field type.
*
* BuddyPress considers a field's "options" to be, for example, the items in a selectbox.
* These are stored separately in the database, and their templating is handled separately.
*
* This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because
* it's also used in the wp-admin screens when creating new fields, and for backwards compatibility.
*
* Must be used inside the {@link bp_profile_fields()} template loop.
*
* @since 2.0.0
*
* @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
*/
public function edit_field_options_html(array $args = array())
{
$date = BP_XProfile_ProfileData::get_value_byid($this->field_obj->id, $args['user_id']);
$day = 0;
$month = 0;
$year = 0;
$html = '';
$eng_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
// Set day, month, year defaults.
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, and errors preventing them from
// being saved first time.
if (!empty($_POST['field_' . $this->field_obj->id . '_day'])) {
$new_day = (int) $_POST['field_' . $this->field_obj->id . '_day'];
$day = $day != $new_day ? $new_day : $day;
}
if (!empty($_POST['field_' . $this->field_obj->id . '_month'])) {
if (in_array($_POST['field_' . $this->field_obj->id . '_month'], $eng_months)) {
$new_month = $_POST['field_' . $this->field_obj->id . '_month'];
} else {
$new_month = $month;
}
$month = $month !== $new_month ? $new_month : $month;
}
if (!empty($_POST['field_' . $this->field_obj->id . '_year'])) {
$new_year = (int) $_POST['field_' . $this->field_obj->id . '_year'];
$year = $year != $new_year ? $new_year : $year;
}
// $type will be passed by calling function when needed.
switch ($args['type']) {
case 'day':
$html = sprintf('<option value="" %1$s>%2$s</option>', selected($day, 0, false), __('----', 'buddypress'));
for ($i = 1; $i < 32; ++$i) {
$html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected($day, $i, false), (int) $i);
}
break;
case 'month':
$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 = sprintf('<option value="" %1$s>%2$s</option>', selected($month, 0, false), __('----', 'buddypress'));
for ($i = 0; $i < 12; ++$i) {
$html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($eng_months[$i]), selected($month, $eng_months[$i], false), $months[$i]);
}
break;
case 'year':
$html = sprintf('<option value="" %1$s>%2$s</option>', selected($year, 0, false), __('----', 'buddypress'));
for ($i = 2037; $i > 1901; $i--) {
$html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected($year, $i, false), (int) $i);
}
break;
}
/**
* Filters the output for the profile field datebox.
*
* @since 1.1.0
*
* @param string $html HTML output for the field.
* @param string $value Which date type is being rendered for.
* @param string $day Date formatted for the current day.
* @param string $month Date formatted for the current month.
* @param string $year Date formatted for the current year.
* @param int $id ID of the field object being rendered.
* @param string $date Current date.
*/
echo apply_filters('bp_get_the_profile_field_datebox', $html, $args['type'], $day, $month, $year, $this->field_obj->id, $date);
}