category = _x( 'WordPress Fields', 'xprofile field type category', 'buddypress' ); $this->name = _x( 'Text field', 'xprofile field type', 'buddypress' ); $this->accepts_null_value = true; $this->do_settings_section = true; $this->wp_user_key = ''; $this->set_format( '/^.*$/', 'replace' ); /** * Fires inside __construct() method for BP_XProfile_Field_Type_WordPress_Textbox class. * * @since 8.0.0 * * @param BP_XProfile_Field_Type_WordPress_Textbox $this Instance of the field type object. */ do_action( 'bp_xprofile_field_type_wordpress_textbox', $this ); /* * As we are using an xProfile field meta to store the WordPress field meta key we need * to make sure $this->wp_user_key is set before once the field has been populated. */ add_action( 'bp_xprofile_field', array( $this, 'set_wp_user_key' ), 10 ); } /** * Sets the WordPress field wp_user_key property before saving the xProfile field. * * @since 8.0.0 * * @param BP_XProfile_Field $field Field object. */ public function set_wp_user_key( $field ) { if ( ! $this->wp_user_key && 'wp-textbox' === $field->type ) { $this->wp_user_key = self::get_field_settings( $field->id ); } } /** * Gets the WordPress field value during an xProfile fields loop. * * This function is used inside `BP_XProfile_ProfileData::get_data_for_user()` * to include the WordPress field value into the xProfile fields loop. * * @since 8.0.0 * * @param integer $user_id The user ID. * @param integer $field_id The xProfile field ID. * @return array An array containing the metadata `id`, `value` and `table_name`. */ public function get_field_value( $user_id, $field_id = 0 ) { if ( ! $this->wp_user_key ) { $this->wp_user_key = self::get_field_settings( $field_id ); } return parent::get_field_value( $user_id, $field_id ); } /** * Sanitize the user field before saving it to db. * * @since 8.0.0 * * @param string $value The user field value. * @return string The sanitized field value. */ public function sanitize_for_db( $value ) { if ( ! $value ) { return ''; } if ( 'user_url' === $this->wp_user_key ) { return esc_url_raw( $value ); } return sanitize_text_field( $value ); } /** * Sanitize the user field before displaying it as an attribute. * * @since 8.0.0 * * @param string $value The user field value. * @return string The sanitized field value. */ public function sanitize_for_output( $value, $user_id = 0 ) { if ( ! $user_id ) { $user_id = bp_displayed_user_id(); } return sanitize_user_field( $this->wp_user_key, $value, $user_id, 'attribute' ); } /** * Output the edit field HTML for this field type. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 8.0.0 * * @param array $raw_properties Optional key/value array of * {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} * that you want to add. */ public function edit_field_html( array $raw_properties = array() ) { /* * User_id is a special optional parameter that certain other fields * types pass to {@link bp_the_profile_field_options()}. */ if ( ! is_admin() && isset( $raw_properties['user_id'] ) ) { unset( $raw_properties['user_id'] ); } $user_id = bp_displayed_user_id(); if ( isset( $raw_properties['user_id'] ) && $raw_properties['user_id'] ) { $user_id = (int) $raw_properties['user_id']; unset( $raw_properties['user_id'] ); } if ( ! $this->wp_user_key ) { $this->wp_user_key = self::get_field_settings( bp_get_the_profile_field_id() ); } $field_value = ''; if ( 'user_url' === $this->wp_user_key ) { if ( bp_displayed_user_id() ) { $field_value = bp_get_displayed_user()->userdata->{$this->wp_user_key}; } elseif ( $user_id ) { $user = get_user_by( 'id', $user_id ); $field_value = $user->{$this->wp_user_key}; } } else { $field_value = bp_get_user_meta( $user_id, $this->wp_user_key, true ); } $r = bp_parse_args( $raw_properties, array( 'type' => 'text', 'value' => $this->sanitize_for_output( $field_value, $user_id ), ) ); ?> get_edit_field_html_elements( $r ); ?> aria-labelledby="-1" aria-describedby="-3">

'text', ) ); ?> get_edit_field_html_elements( $r ); ?>> type !== $type ) { $style .= ' display: none;'; }; $setting = self::get_field_settings( $current_field->id ); $wp_labels = array_merge( array( 'first_name' => _x( 'First Name', 'xpofile wp-textbox field type label', 'buddypress' ), 'last_name' => _x( 'Last Name', 'xpofile wp-textbox field type label', 'buddypress' ), 'user_url' => _x( 'Website', 'xpofile wp-textbox field type label', 'buddypress' ), ), wp_get_user_contact_methods() ); ?>

    supported_keys as $key ) { if ( 'description' === $key || ! isset( $wp_labels[ $key ] ) ) { continue; } printf( '
  • ', esc_attr( $key ), checked( $key, $setting, false ), esc_html( $wp_labels[ $key ] ) ); } ?>
%1$s', $sanitized_website ); } return sanitize_user_field( $wp_user_key, $field_value, bp_displayed_user_id(), 'display' ); } }