[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-xprofile/classes/ -> class-bp-xprofile-field-type-textarea.php (source)

   1  <?php
   2  /**
   3   * BuddyPress XProfile Classes.
   4   *
   5   * @package BuddyPress
   6   * @subpackage XProfileClasses
   7   * @since 2.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Textarea xprofile field type.
  15   *
  16   * @since 2.0.0
  17   */
  18  class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {
  19  
  20      /**
  21       * Constructor for the textarea field type.
  22       *
  23       * @since 2.0.0
  24       */
  25  	public function __construct() {
  26          parent::__construct();
  27  
  28          $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
  29          $this->name     = _x( 'Multi-line Text Area', 'xprofile field type', 'buddypress' );
  30          $this->supports_richtext = true;
  31  
  32          $this->set_format( '/^.*$/m', 'replace' );
  33  
  34          /**
  35           * Fires inside __construct() method for BP_XProfile_Field_Type_Textarea class.
  36           *
  37           * @since 2.0.0
  38           *
  39           * @param BP_XProfile_Field_Type_Textarea $this Current instance of
  40           *                                              the field type textarea.
  41           */
  42          do_action( 'bp_xprofile_field_type_textarea', $this );
  43      }
  44  
  45      /**
  46       * Output the edit field HTML for this field type.
  47       *
  48       * Must be used inside the {@link bp_profile_fields()} template loop.
  49       *
  50       * @since 2.0.0
  51       *
  52       * @param array $raw_properties Optional key/value array of
  53       *                              {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes}
  54       *                              that you want to add.
  55       */
  56  	public function edit_field_html( array $raw_properties = array() ) {
  57  
  58          // User_id is a special optional parameter that certain other fields
  59          // types pass to {@link bp_the_profile_field_options()}.
  60          if ( isset( $raw_properties['user_id'] ) ) {
  61              unset( $raw_properties['user_id'] );
  62          }
  63  
  64          $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field(); ?>
  65  
  66          <legend id="<?php bp_the_profile_field_input_name(); ?>-1">
  67              <?php bp_the_profile_field_name(); ?>
  68              <?php bp_the_profile_field_required_label(); ?>
  69          </legend>
  70  
  71          <?php
  72  
  73          /** This action is documented in bp-xprofile/bp-xprofile-classes */
  74          do_action( bp_get_the_profile_field_errors_action() );
  75  
  76          if ( ! $richtext_enabled ) {
  77              $r = wp_parse_args( $raw_properties, array(
  78                  'cols' => 40,
  79                  'rows' => 5,
  80              ) );
  81  
  82              ?>
  83  
  84              <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?> aria-labelledby="<?php bp_the_profile_field_input_name(); ?>-1" aria-describedby="<?php bp_the_profile_field_input_name(); ?>-3"><?php bp_the_profile_field_edit_value(); ?></textarea>
  85  
  86              <?php
  87  
  88          } else {
  89  
  90              /**
  91               * Filters the arguments passed to `wp_editor()` in richtext xprofile fields.
  92               *
  93               * @since 2.4.0
  94               *
  95               * @param array $args {
  96               *     Array of optional arguments. See `wp_editor()`.
  97               *     @type bool $teeny         Whether to use the teeny version of TinyMCE. Default true.
  98               *     @type bool $media_buttons Whether to show media buttons. Default false.
  99               *     @type bool $quicktags     Whether to show the quicktags buttons. Default true.
 100               *     @type int  $textarea_rows Number of rows to display in the editor. Defaults to 1 in the
 101               *                               'admin' context, and 10 in the 'edit' context.
 102               * }
 103               * @param string $context The display context. 'edit' when the markup is intended for the
 104               *                        profile edit screen, 'admin' when intended for the Profile Fields
 105               *                        Dashboard panel.
 106               */
 107              $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
 108                  'teeny'         => true,
 109                  'media_buttons' => false,
 110                  'quicktags'     => true,
 111                  'textarea_rows' => 10,
 112              ), 'edit' );
 113  
 114              wp_editor(
 115                  bp_get_the_profile_field_edit_value(),
 116                  bp_get_the_profile_field_input_name(),
 117                  $editor_args
 118              );
 119          }
 120  
 121          if ( bp_get_the_profile_field_description() ) : ?>
 122              <p class="description" id="<?php bp_the_profile_field_input_name(); ?>-3"><?php bp_the_profile_field_description(); ?></p>
 123          <?php endif;
 124      }
 125  
 126      /**
 127       * Output HTML for this field type on the wp-admin Profile Fields screen.
 128       *
 129       * Must be used inside the {@link bp_profile_fields()} template loop.
 130       *
 131       * @since 2.0.0
 132       *
 133       * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
 134       */
 135  	public function admin_field_html( array $raw_properties = array() ) {
 136          $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field();
 137  
 138          if ( ! $richtext_enabled ) {
 139  
 140              $r = bp_parse_args( $raw_properties, array(
 141                  'cols' => 40,
 142                  'rows' => 5,
 143              ) ); ?>
 144  
 145              <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
 146  
 147              <?php
 148          } else {
 149  
 150              /** This filter is documented in bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php */
 151              $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
 152                  'teeny'         => true,
 153                  'media_buttons' => false,
 154                  'quicktags'     => true,
 155                  'textarea_rows' => 1,
 156              ), 'admin' );
 157  
 158              wp_editor(
 159                  '',
 160                  'xprofile_textarea_' . bp_get_the_profile_field_id(),
 161                  $editor_args
 162              );
 163          }
 164      }
 165  
 166      /**
 167       * This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields
 168       * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
 169       *
 170       * @since 2.0.0
 171       *
 172       * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
 173       * @param string            $control_type  Optional. HTML input type used to render the current
 174       *                                         field's child options.
 175       */
 176  	public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
 177  }


Generated: Mon Oct 21 01:01:35 2019 Cross-referenced by PHPXref 0.7.1