Paragraph text xProfile

Remove rich editor from xProfile’s Paragraph Text (Textarea)

Many clients have asked me how to disable the rich editor from textareas in BuddyBoss’s edit Profile page. There is an easy way to achieve this.

This is how the Paragraph text with rich editor looks like

We have to hook on the bp_xprofile_is_richtext_enabled_for_field filter, which is responsible for enabling the rich editor of every xProfile field or not.

We will then get the field type from the field’s ID and check if the type is textarea (Paragraph text). If that is the case then we will return false to the filter, so the rich editor is not enabled.

/**
 * Filters whether richtext is enabled for the given field.
 *
 * @param bool $enabled True if richtext is enabled for the field, otherwise false.
 * @param int  $field_id ID of the field.
 *
 * @since BuddyPress 2.4.0
 *
 */
function gkco_remove_rich_editor_from_textarea( $enabled, $field_id = 0 ) {

    if ( $field_id == 0 ) {
        return $enabled;
    }

    $field = xprofile_get_field( $field_id );

    // If xProfile field type is Textarea remove Rich editor
    if ( $field->type == 'textarea' ) {

        return false;
    }

    return $enabled;

}

add_filter( 'bp_xprofile_is_richtext_enabled_for_field', 'gkco_remove_rich_editor_from_textarea', 10, 2 );

The above filter will result in something like this:

Our textarea without the rich editor

The good thing is that we achieved our goal to remove the rich editor from every xProfile textarea, but on the other hand, our textarea now looks like an input.

The cause of this is the default style that BuddyPress uses to reset all form elements:

BuddyPress’s form element styles

The fix for this is also easy; we just have to add a bigger value for the textarea’s height using a CSS rule. For example:

#buddypress .bp-profile-content .standard-form textarea {
	height: 240px;
}

The result will look much better now:

Final result of an xProfile textarea without rich editor.

Please let me know if that helps or if you stumbled upon any issues.

0 Comments

Leave a Reply