Changeset 8547
- Timestamp:
- 06/25/2014 01:36:44 PM (10 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-classes.php
r8535 r8547 1696 1696 */ 1697 1697 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 1698 1699 /** 1700 * Format Date values for display. 1701 * 1702 * @since BuddyPress (2.1.0) 1703 * 1704 * @param string $field_value The date value, as saved in the database. 1705 * Typically, this is a MySQL-formatted date string (Y-m-d H:i:s). 1706 * @return string Date formatted by bp_format_time(). 1707 */ 1708 public static function display_filter( $field_value ) { 1709 // If Unix timestamp 1710 if ( is_numeric( $field_value ) ) { 1711 $field_value = bp_format_time( $field_value, true, false ); 1712 1713 // If MySQL timestamp 1714 } else { 1715 $field_value = bp_format_time( strtotime( $field_value ), true, false ); 1716 } 1717 1718 return $field_value; 1719 } 1698 1720 } 1699 1721 … … 2852 2874 } 2853 2875 2876 /** 2877 * Allow field types to modify the appearance of their values. 2878 * 2879 * By default, this is a pass-through method that does nothing. Only 2880 * override in your own field type if you need to provide custom 2881 * filtering for output values. 2882 * 2883 * @since BuddyPress (2.1.0) 2884 * 2885 * @param mixed $field_value Field value. 2886 * @return mixed 2887 */ 2888 public static function display_filter( $field_value ) { 2889 return $field_value; 2890 } 2854 2891 2855 2892 /** -
trunk/src/bp-xprofile/bp-xprofile-filters.php
r8163 r8547 50 50 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 ); 51 51 add_filter( 'bp_get_the_site_member_profile_data', 'xprofile_filter_format_field_value', 1, 2 ); 52 add_filter( 'xprofile_get_field_data', 'xprofile_filter_format_field_value_by_field_id', 5, 2 ); 53 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value_by_type', 5, 2 ); 52 54 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); 53 55 … … 117 119 118 120 /** 119 * xprofile_filter_format_field_value() 120 * 121 * Runs stripslashes on XProfile fields. If is field_type is 'datebox' 122 * then the date will be formatted by bp_format_time(). 123 * 124 * @since BuddyPress (1.0) 121 * Runs stripslashes on XProfile fields. 122 * 123 * @since BuddyPress (1.0.0) 125 124 * 126 125 * @param string $field_value XProfile field_value to be filtered. 127 126 * @param string $field_type XProfile field_type to be filtered. 128 *129 * @uses bp_format_time()130 *131 127 * @return string $field_value Filtered XProfile field_value. False on failure. 132 128 */ … … 135 131 return false; 136 132 137 if ( 'datebox' == $field_type ) { 138 139 // If Unix timestamp 140 if ( is_numeric( $field_value ) ) { 141 $field_value = bp_format_time( $field_value, true, false ); 142 143 // If MySQL timestamp 144 } else { 145 $field_value = bp_format_time( strtotime( $field_value ), true, false ); 146 } 147 148 } else { 133 if ( 'datebox' != $field_type ) { 149 134 $field_value = str_replace(']]>', ']]>', $field_value ); 150 135 } 151 136 152 137 return stripslashes( $field_value ); 138 } 139 140 /** 141 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside a bp_has_profile() loop. 142 * 143 * @since BuddyPress (2.1.0) 144 * 145 * @param mixed $field_value Field value. 146 * @param string $field_type Field type. 147 * @return mixed 148 */ 149 function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '' ) { 150 foreach ( bp_xprofile_get_field_types() as $type => $class ) { 151 if ( $type !== $field_type ) { 152 continue; 153 } 154 155 if ( method_exists( $class, 'display_filter' ) ) { 156 $field_value = call_user_func( array( $class, 'display_filter' ), $field_value ); 157 } 158 } 159 160 return $field_value; 161 } 162 163 /** 164 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched by xprofile_get_field_data(). 165 * 166 * @since BuddyPress (2.1.0) 167 * 168 * @param mixed $field_value Field value. 169 * @param int $field_id Field type. 170 */ 171 function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) { 172 $field = new BP_XProfile_Field( $field_id ); 173 return xprofile_filter_format_field_value_by_type( $field_value, $field->type ); 153 174 } 154 175
Note: See TracChangeset
for help on using the changeset viewer.