[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress XProfile Classes.
   4   *
   5   * @package BuddyPress
   6   * @subpackage XProfileClasses
   7   * @since 3.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Telephone number xprofile field type.
  15   *
  16   * @since 3.0.0
  17   */
  18  class BP_XProfile_Field_Type_Telephone extends BP_XProfile_Field_Type {
  19  
  20      /**
  21       * Constructor for the telephone number field type.
  22       *
  23       * @since 3.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( 'Phone Number', 'xprofile field type', 'buddypress' );
  30  
  31          $this->set_format( '/^.*$/', 'replace' );
  32  
  33          /**
  34           * Fires inside __construct() method for BP_XProfile_Field_Type_Telephone class.
  35           *
  36           * @since 3.0.0
  37           *
  38           * @param BP_XProfile_Field_Type_Telephone $this Current instance of the field type.
  39           */
  40          do_action( 'bp_xprofile_field_type_telephone', $this );
  41      }
  42  
  43      /**
  44       * Output the edit field HTML for this field type.
  45       *
  46       * Must be used inside the {@link bp_profile_fields()} template loop.
  47       *
  48       * @since 3.0.0
  49       *
  50       * @param array $raw_properties Optional key/value array of
  51       *                              {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes}
  52       *                              that you want to add.
  53       */
  54  	public function edit_field_html( array $raw_properties = array() ) {
  55          /*
  56           * User_id is a special optional parameter that certain other fields
  57           * types pass to {@link bp_the_profile_field_options()}.
  58           */
  59          if ( isset( $raw_properties['user_id'] ) ) {
  60              unset( $raw_properties['user_id'] );
  61          }
  62  
  63          $r = bp_parse_args(
  64              $raw_properties,
  65              array(
  66                  'type'  => 'tel',
  67                  'value' => bp_get_the_profile_field_edit_value(),
  68              )
  69          );
  70          ?>
  71  
  72          <legend id="<?php bp_the_profile_field_input_name(); ?>-1">
  73              <?php bp_the_profile_field_name(); ?>
  74              <?php bp_the_profile_field_required_label(); ?>
  75          </legend>
  76  
  77          <?php
  78  
  79          /** This action is documented in bp-xprofile/bp-xprofile-classes */
  80          do_action( bp_get_the_profile_field_errors_action() ); ?>
  81  
  82          <input <?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">
  83  
  84          <?php if ( bp_get_the_profile_field_description() ) : ?>
  85              <p class="description" id="<?php bp_the_profile_field_input_name(); ?>-3"><?php bp_the_profile_field_description(); ?></p>
  86          <?php endif; ?>
  87  
  88          <?php
  89      }
  90  
  91      /**
  92       * Output HTML for this field type on the wp-admin Profile Fields screen.
  93       *
  94       * Must be used inside the {@link bp_profile_fields()} template loop.
  95       *
  96       * @since 3.0.0
  97       *
  98       * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
  99       */
 100  	public function admin_field_html( array $raw_properties = array() ) {
 101          $r = bp_parse_args(
 102              $raw_properties,
 103              array(
 104                  'type' => 'tel',
 105              )
 106          );
 107          ?>
 108  
 109          <label for="<?php bp_the_profile_field_input_name(); ?>" class="screen-reader-text"><?php
 110              /* translators: accessibility text */
 111              esc_html_e( 'Phone Number', 'buddypress' );
 112          ?></label>
 113          <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
 114  
 115          <?php
 116      }
 117  
 118      /**
 119       * This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields
 120       * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
 121       *
 122       * @since 3.0.0
 123       *
 124       * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
 125       * @param string            $control_type  Optional. HTML input type used to render the
 126       *                                         current field's child options.
 127       */
 128  	public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
 129  
 130      /**
 131       * Format URL values for display.
 132       *
 133       * @since 3.0.0
 134       *
 135       * @param string     $field_value The URL value, as saved in the database.
 136       * @param string|int $field_id    Optional. ID of the field.
 137       *
 138       * @return string URL converted to a link.
 139       */
 140  	public static function display_filter( $field_value, $field_id = '' ) {
 141          $url   = wp_strip_all_tags( $field_value );
 142          $parts = parse_url( $url );
 143  
 144          // Add the tel:// protocol to the field value.
 145          if ( isset( $parts['scheme'] ) ) {
 146              if ( strtolower( $parts['scheme'] ) !== 'tel' ) {
 147                  $scheme = preg_quote( $parts['scheme'], '#' );
 148                  $url    = preg_replace( '#^' . $scheme . '#i', 'tel', $url );
 149              }
 150  
 151              $url_text = preg_replace( '#^tel://#i', '', $url );
 152  
 153          } else {
 154              $url_text = $url;
 155              $url      = 'tel://' . $url;
 156          }
 157  
 158          return sprintf(
 159              '<a href="%1$s" rel="nofollow">%2$s</a>',
 160              esc_url( $url, array( 'tel' ) ),
 161              esc_html( $url_text )
 162          );
 163      }
 164  }


Generated: Sun Apr 28 01:01:05 2024 Cross-referenced by PHPXref 0.7.1