Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/12/2015 05:50:45 PM (11 years ago)
Author:
boonebgorges
Message:

Enable richtext editing for xProfile textarea fields.

Profile fields of the 'textarea' type are now edited using wp_editor().
Output escaping has been modified to whitelist all tags permitted by the
"teeny" version of the wp_editor() interface.

Richtext is enabled for all and only 'textarea' fields:

  • To enable richtext editing for a custom field type, set the supports_richtext property of your BP_XProfile_Field_Type class to true. In these cases, you'll need to provide your own editing markup as well; see the edit_field_html() and admin_field_html() methods of BP_XProfile_Field_Type_Textarea for inspiration.
  • To disable richtext editing for specific 'textarea' fields, filter bp_xprofile_is_richtext_enabled_for_field.

Props needle, boonebgorges.
Fixes #5625.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php

    r10179 r10254  
    2727                $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
    2828                $this->name     = _x( 'Multi-line Text Area', 'xprofile field type', 'buddypress' );
     29                $this->supports_richtext = true;
    2930
    3031                $this->set_format( '/^.*$/m', 'replace' );
    … …  
    6061                }
    6162
    62                 $r = bp_parse_args( $raw_properties, array(
    63                         'cols' => 40,
    64                         'rows' => 5,
    65                 ) ); ?>
     63                $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field(); ?>
    6664
    6765                <label for="<?php bp_the_profile_field_input_name(); ?>">
    … …  
    7371
    7472                /** This action is documented in bp-xprofile/bp-xprofile-classes */
    75                 do_action( bp_get_the_profile_field_errors_action() ); ?>
     73                do_action( bp_get_the_profile_field_errors_action() );
    7674
    77                 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
     75                if ( ! $richtext_enabled ) {
     76                        $r = wp_parse_args( $raw_properties, array(
     77                                'cols' => 40,
     78                                'rows' => 5,
     79                        ) );
    7880
    79                 <?php
     81                        ?>
     82
     83                        <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
     84
     85                        <?php
     86
     87                } else {
     88
     89                        /**
     90                         * Filters the arguments passed to `wp_editor()` in richtext xprofile fields.
     91                         *
     92                         * @since 2.4.0
     93                         *
     94                         * @param array $args {
     95                         *     Array of optional arguments. See `wp_editor()`.
     96                         *     @type bool $teeny         Whether to use the teeny version of TinyMCE. Default true.
     97                         *     @type bool $media_buttons Whether to show media buttons. Default false.
     98                         *     @type bool $quicktags     Whether to show the quicktags buttons. Default true.
     99                         * }
     100                         */
     101                        $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
     102                                'teeny'         => true,
     103                                'media_buttons' => false,
     104                                'quicktags'     => true,
     105                        ) );
     106
     107                        wp_editor(
     108                                bp_get_the_profile_field_edit_value(),
     109                                bp_get_the_profile_field_input_name(),
     110                                $editor_args
     111                        );
     112                }
    80113        }
    81114
    … …  
    90123         */
    91124        public function admin_field_html( array $raw_properties = array() ) {
    92                 $r = bp_parse_args( $raw_properties, array(
    93                         'cols' => 40,
    94                         'rows' => 5,
    95                 ) ); ?>
     125                $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field();
    96126
    97                 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
     127                if ( ! $richtext_enabled ) {
    98128
    99                 <?php
     129                        $r = bp_parse_args( $raw_properties, array(
     130                                'cols' => 40,
     131                                'rows' => 5,
     132                        ) ); ?>
     133
     134                        <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
     135
     136                        <?php
     137                } else {
     138
     139                        /** This filter is documented in bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php */
     140                        $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
     141                                'teeny'         => true,
     142                                'media_buttons' => false,
     143                                'quicktags'     => true,
     144                        ) );
     145
     146                        wp_editor(
     147                                '',
     148                                'xprofile_textarea_' . bp_get_the_profile_field_id(),
     149                                $editor_args
     150                        );
     151                }
    100152        }
    101153
Note: See TracChangeset for help on using the changeset viewer.