/bp-xprofile/classes/class-bp-xprofile-field-type-number.php

  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. * Number xprofile field type. 
  15. * 
  16. * @since 2.0.0 
  17. */ 
  18. class BP_XProfile_Field_Type_Number extends BP_XProfile_Field_Type { 
  19.  
  20. /** 
  21. * Constructor for the number 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( 'Number', 'xprofile field type', 'buddypress' ); 
  30.  
  31. $this->set_format( '/^\d+|-\d+$/', 'replace' ); 
  32.  
  33. /** 
  34. * Fires inside __construct() method for BP_XProfile_Field_Type_Number class. 
  35. * 
  36. * @since 2.0.0 
  37. * 
  38. * @param BP_XProfile_Field_Type_Number $this Current instance of 
  39. * the field type number. 
  40. */ 
  41. do_action( 'bp_xprofile_field_type_number', $this ); 
  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 2.0.0 
  49. * 
  50. * @param array $raw_properties Optional key/value array of 
  51. * {@link http://dev.w3.org/html5/markup/input.number.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. if ( isset( $raw_properties['user_id'] ) ) { 
  59. unset( $raw_properties['user_id'] ); 
  60.  
  61. $r = bp_parse_args( $raw_properties, array( 
  62. 'type' => 'number',  
  63. 'value' => bp_get_the_profile_field_edit_value() 
  64. ) ); ?> 
  65.  
  66. <label for="<?php bp_the_profile_field_input_name(); ?>"> 
  67. <?php bp_the_profile_field_name(); ?> 
  68. <?php bp_the_profile_field_required_label(); ?> 
  69. </label> 
  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. <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 
  77.  
  78. <?php 
  79.  
  80. /** 
  81. * Output HTML for this field type on the wp-admin Profile Fields screen. 
  82. * 
  83. * Must be used inside the {@link bp_profile_fields()} template loop. 
  84. * 
  85. * @since 2.0.0 
  86. * 
  87. * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 
  88. */ 
  89. public function admin_field_html( array $raw_properties = array() ) { 
  90. $r = bp_parse_args( $raw_properties, array( 
  91. 'type' => 'number' 
  92. ) ); ?> 
  93.  
  94. <label for="<?php bp_the_profile_field_input_name(); ?>" class="screen-reader-text"><?php 
  95. /** translators: accessibility text */ 
  96. esc_html_e( 'Number field', 'buddypress' ); 
  97. ?></label> 
  98. <input <?php echo $this->get_edit_field_html_elements( $r ); ?>> 
  99. <?php 
  100.  
  101. /** 
  102. * This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields 
  103. * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out. 
  104. * 
  105. * @since 2.0.0 
  106. * 
  107. * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 
  108. * @param string $control_type Optional. HTML input type used to render the current 
  109. * field's child options. 
  110. */ 
  111. public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 
.