[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress XProfile Classes. 4 * 5 * @package BuddyPress 6 * @subpackage XProfileClasses 7 * @since 8.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * WordPress Biography xProfile field type. 15 * 16 * @since 8.0.0 17 */ 18 class BP_XProfile_Field_Type_WordPress_Biography extends BP_XProfile_Field_Type_WordPress { 19 20 /** 21 * Constructor for the WordPress biography field type. 22 * 23 * @since 8.0.0 24 */ 25 public function __construct() { 26 parent::__construct(); 27 28 $this->category = _x( 'WordPress Fields', 'xprofile field type category', 'buddypress' ); 29 $this->name = _x( 'Biography', 'xprofile field type', 'buddypress' ); 30 $this->accepts_null_value = true; 31 $this->wp_user_key = 'description'; 32 33 $this->set_format( '/^.*$/m', 'replace' ); 34 35 /** 36 * Fires inside __construct() method for BP_XProfile_Field_Type_WordPress_Biography class. 37 * 38 * @since 8.0.0 39 * 40 * @param BP_XProfile_Field_Type_WordPress_Biography $this Instance of the field type object. 41 */ 42 do_action( 'bp_xprofile_field_type_wordpress_biography', $this ); 43 } 44 45 /** 46 * Sanitize the user field before saving it to db. 47 * 48 * @since 8.0.0 49 * 50 * @param string $value The user field value. 51 * @return string The sanitized field value. 52 */ 53 public function sanitize_for_db( $value ) { 54 if ( ! $value ) { 55 return ''; 56 } 57 58 return trim( $value ); 59 } 60 61 /** 62 * Sanitize the user field before displaying it as an attribute. 63 * 64 * @since 8.0.0 65 * 66 * @param string $value The user field value. 67 * @param integer $user_id The user ID. 68 * @return string The sanitized field value. 69 */ 70 public function sanitize_for_output( $value, $user_id = 0 ) { 71 if ( ! $user_id ) { 72 $user_id = bp_displayed_user_id(); 73 } 74 75 return sanitize_user_field( $this->wp_user_key, $value, $user_id, 'attribute' ); 76 } 77 78 /** 79 * Output the edit field HTML for this field type. 80 * 81 * Must be used inside the {@link bp_profile_fields()} template loop. 82 * 83 * @since 8.0.0 84 * 85 * @param array $raw_properties Optional key/value array of 86 * {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} 87 * that you want to add. 88 */ 89 public function edit_field_html( array $raw_properties = array() ) { 90 /* 91 * User_id is a special optional parameter that certain other fields 92 * types pass to {@link bp_the_profile_field_options()}. 93 */ 94 if ( ! is_admin() && isset( $raw_properties['user_id'] ) ) { 95 unset( $raw_properties['user_id'] ); 96 } 97 98 $user_id = bp_displayed_user_id(); 99 if ( isset( $raw_properties['user_id'] ) && $raw_properties['user_id'] ) { 100 $user_id = (int) $raw_properties['user_id']; 101 unset( $raw_properties['user_id'] ); 102 } 103 ?> 104 105 <label for="<?php bp_the_profile_field_input_name(); ?>"> 106 <?php bp_the_profile_field_name(); ?> 107 <?php bp_the_profile_field_required_label(); ?> 108 </label> 109 110 <?php 111 /** This action is documented in bp-xprofile/bp-xprofile-classes */ 112 do_action( bp_get_the_profile_field_errors_action() ); 113 114 $r = bp_parse_args( 115 $raw_properties, 116 array( 117 'cols' => 40, 118 'rows' => 5, 119 ) 120 ); 121 ?> 122 123 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php 124 echo $this->sanitize_for_output( bp_get_user_meta( $user_id, $this->wp_user_key, true ), $user_id ); 125 ?></textarea> 126 127 <?php 128 } 129 130 /** 131 * Output HTML for this field type on the wp-admin Profile Fields screen. 132 * 133 * Must be used inside the {@link bp_profile_fields()} template loop. 134 * 135 * @since 8.0.0 136 * 137 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 138 */ 139 public function admin_field_html( array $raw_properties = array() ) { 140 $r = bp_parse_args( 141 $raw_properties, 142 array( 143 'cols' => 40, 144 'rows' => 5, 145 ) 146 ); 147 ?> 148 149 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea> 150 151 <?php 152 } 153 154 /** 155 * This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields 156 * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out. 157 * 158 * @since 8.0.0 159 * 160 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 161 * @param string $control_type Optional. HTML input type used to render the 162 * current field's child options. 163 */ 164 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 165 166 /** 167 * Format WordPress Biography for display. 168 * 169 * @since 8.0.0 170 * 171 * @param string $field_value The field value, as saved in the database. 172 * @param string|int $field_id Optional. ID of the field. 173 * @return string The sanitized WordPress field. 174 */ 175 public static function display_filter( $field_value, $field_id = '' ) { 176 return sanitize_user_field( 'description', $field_value, bp_displayed_user_id(), 'display' ); 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |