diff --git src/bp-xprofile/bp-xprofile-classes.php src/bp-xprofile/bp-xprofile-classes.php
index 5fb8e50..9768b71 100644
--- src/bp-xprofile/bp-xprofile-classes.php
+++ src/bp-xprofile/bp-xprofile-classes.php
@@ -2440,13 +2440,33 @@ class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {
* @since BuddyPress (2.0.0)
*/
public function __construct() {
+
parent::__construct();
$this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
$this->name = _x( 'Multi-line Text Area', 'xprofile field type', 'buddypress' );
+ $this->type = 'textarea';
$this->set_format( '/^.*$/m', 'replace' );
+
+ // Create custom filters that mirror 'the_content' for formatting output
+ add_filter( 'bp_xprofile_field_type_textarea_content', 'wptexturize' );
+ add_filter( 'bp_xprofile_field_type_textarea_content', 'convert_smilies' );
+ add_filter( 'bp_xprofile_field_type_textarea_content', 'convert_chars' );
+ add_filter( 'bp_xprofile_field_type_textarea_content', 'wpautop' );
+ add_filter( 'bp_xprofile_field_type_textarea_content', 'shortcode_unautop' );
+
+ // Override and augment allowed tags
+ add_filter( 'xprofile_allowed_tags', array( $this, 'allowed_tags' ), 30, 2 );
+
+ // Parse the edit value
+ add_filter( 'bp_get_the_profile_field_edit_value', array( $this, 'get_field_value' ), 30, 3 );
+
+ // Filter for those who use xprofile_get_field_data instead of get_field_value
+ add_filter( 'xprofile_get_field_data', array( $this, 'get_field_data' ), 15, 3 );
+
do_action( 'bp_xprofile_field_type_textarea', $this );
+
}
/**
@@ -2465,10 +2485,7 @@ class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {
unset( $raw_properties['user_id'] );
}
- $r = bp_parse_args( $raw_properties, array(
- 'cols' => 40,
- 'rows' => 5,
- ) ); ?>
+ $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field(); ?>
-
+ get_edit_field_html_elements( $r ); ?>>
+ if ( ! $richtext_enabled ) {
+ $r = wp_parse_args( $raw_properties, array(
+ 'cols' => 40,
+ 'rows' => 5,
+ ) );
-
+
+
+
+ true,
+ 'media_buttons' => false,
+ 'quicktags' => true,
+ ) );
+
+ // Create the editor
+ wp_editor(
+ bp_get_the_profile_field_edit_value(),
+ bp_get_the_profile_field_input_name(),
+ $editor_args
+ );
+ }
}
/**
@@ -2493,25 +2533,207 @@ class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {
* @since BuddyPress (2.0.0)
*/
public function admin_field_html( array $raw_properties = array() ) {
- $r = bp_parse_args( $raw_properties, array(
- 'cols' => 40,
- 'rows' => 5,
- ) ); ?>
-
+ $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field();
- 40,
+ 'rows' => 5,
+ ) );
+
+ ?>
+
+
+
+ true,
+ 'media_buttons' => false,
+ 'quicktags' => true,
+ ) );
+
+ // Create the editor
+ wp_editor(
+ '',
+ 'xprofile_textarea_' . bp_get_the_profile_field_id(),
+ $editor_args
+ );
+ }
}
/**
* This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields
- * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
*
* @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 = '' ) {}
+
+ /**
+ * Format Visual Editor content for display.
+ *
+ * @since BuddyPress (2.1.0)
+ *
+ * @param string $field_value The Visual Editor content, as saved in the database.
+ * @return string Formatted HTML.
+ */
+ public static function display_filter( $field_value ) {
+
+ $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field();
+
+ if ( $richtext_enabled ) {
+
+ /**
+ * This is a bit of a hack because formatted text looks strange with the
+ * 'xprofile_filter_link_profile_data' filter applied. If instead, we parse
+ * this field type in read mode after all BuddyPress filters have been applied
+ * we can avoid this. Moreover, this method is called outside the scope of $this,
+ * so we have to directly reference the name of this class in the filter
+ */
+ add_filter( 'bp_get_the_profile_field_value', array( 'BP_XProfile_Field_Type_Textarea', 'get_field_value' ), 30, 3 );
+
+ }
+
+ // return the data as received and format in get_field_value() below
+ return $field_value;
+
+ }
+
+ /**
+ * Show our field type in read mode
+ *
+ * @param string $value
+ * @param string $type
+ * @param integer $id
+ * @return string
+ */
+ public function get_field_value( $value = '', $type = '', $id = '' ) {
+
+ // is it our field type?
+ if ( $type == 'textarea' ) {
+
+ global $field;
+
+ // sanity check
+ if ( ! is_object( $field ) ) return $value;
+
+ // get enabled and default to enabled if not yet present
+ $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true );
+ if ( $richtext_enabled === false ) $richtext_enabled = 1;
+ $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false;
+
+ if ( $richtext_enabled ) {
+
+ // we want the raw data, unfiltered
+ $value = $field->data->value;
+
+ // apply content filter
+ $value = apply_filters( 'bp_xprofile_field_type_textarea_content', stripslashes( $value ) );
+
+ return apply_filters( 'bp_xprofile_field_type_textarea_value', $value );
+
+ }
+
+ }
+
+ // fallback
+ return $value;
+
+ }
+
+ /**
+ * Filter for those who use xprofile_get_field_data instead of get_field_value
+ *
+ * @param string $value
+ * @param integer $field_id
+ * @param integer $user_id
+ * @return string
+ */
+ public function get_field_data( $value = '', $field_id = '', $user_id = '' ) {
+
+ // check we get a field ID
+ if ( $field_id === '' ) return $value;
+
+ // get field object
+ $field = new BP_XProfile_Field( $field_id );
+
+ // is it ours?
+ if ( $field->type == $this->type ) {
+
+ // get enabled and default to enabled if not yet present
+ $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true );
+ if ( $richtext_enabled === false ) $richtext_enabled = 1;
+ $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false;
+
+ if ( $richtext_enabled ) {
+
+ // apply content filter
+ $value = apply_filters( 'bp_xprofile_field_type_textarea_content', stripslashes( $value ) );
+
+ // return filtered value
+ return apply_filters( 'bp_xprofile_field_type_textarea_value', $value );
+
+ }
+
+ }
+
+ // fallback
+ return $value;
+
+ }
+
+ /**
+ * Callback to allow tags that teeny TinyMCE enables
+ *
+ * @since BuddyPress (2.2.0)
+ *
+ * @param array $allowedtags The array of allowed tags
+ * @param object $data_obj The xProfile data object (BP 2.1+)
+ * @return array $allowedtags The modified array of allowed tags
+ */
+ public function allowed_tags( $allowedtags, $data_obj = null ) {
+
+ // test if BP has sent the data object
+ if ( ! is_null( $data_obj ) ) {
+
+ // get field from data object
+ $field = new BP_XProfile_Field( $data_obj->field_id );
+
+ // if this isn't our field, skip amending allowed tags
+ if ( $field->type != $this->type ) return $allowedtags;
+
+ // get enabled and default to enabled if not yet present
+ $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true );
+ if ( $richtext_enabled === false ) $richtext_enabled = 1;
+ $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false;
+
+ // bail if not rich text
+ if ( ! $richtext_enabled ) return $allowedtags;
+
+ }
+
+ // default tags we need to enable the teeny TinyMCE editor markup
+ $richtext_tags = array(
+ 'img' => array( 'id' => 1, 'class' => 1, 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ),
+ 'ul' => array( 'id' => 1, 'class' => 1 ),
+ 'ol' => array( 'id' => 1, 'class' => 1 ),
+ 'li' => array( 'id' => 1, 'class' => 1 ),
+ 'span' => array( 'style' => 1 ),
+ 'p' => array( 'style' => 1 ),
+ );
+
+ $allowedtags = array_merge( $allowedtags, $richtext_tags );
+
+ return apply_filters( 'bp_xprofile_field_type_textarea_allowedtags', $allowedtags, $data_obj );
+
+ }
+
}
/**
diff --git src/bp-xprofile/bp-xprofile-functions.php src/bp-xprofile/bp-xprofile-functions.php
index f6f2dee..cf98978 100644
--- src/bp-xprofile/bp-xprofile-functions.php
+++ src/bp-xprofile/bp-xprofile-functions.php
@@ -967,6 +967,22 @@ function bp_xprofile_fullname_field_name() {
}
/**
+ * Is rich text enabled for this profile field?
+ *
+ * @since BuddyPress (2.2.0)
+ *
+ * @param int $field_id Optional. Default: current field ID.
+ * @return bool
+ */
+function bp_xprofile_is_richtext_enabled_for_field( $field_id = null ) {
+ if ( ! $field_id ) {
+ $field_id = bp_get_the_profile_field_id();
+ }
+
+ return apply_filters( 'bp_xprofile_is_richtext_enabled_for_field', true, $field_id );
+}
+
+/**
* Get visibility levels out of the $bp global
*
* @return array
diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php
index 5c9e53f..a9b070c 100644
--- src/bp-xprofile/bp-xprofile-template.php
+++ src/bp-xprofile/bp-xprofile-template.php
@@ -359,7 +359,13 @@ function bp_the_profile_field_id() {
}
function bp_get_the_profile_field_id() {
global $field;
- return apply_filters( 'bp_get_the_profile_field_id', $field->id );
+
+ $field_id = 0;
+ if ( ! empty( $field->id ) ) {
+ $field_id = $field->id;
+ }
+
+ return apply_filters( 'bp_get_the_profile_field_id', $field_id );
}
function bp_the_profile_field_name() {