Opened 12 years ago
Closed 10 years ago
#4365 closed defect (bug) (fixed)
bp_format_time() fails for datebox retrieved by bp_get_member_profile_data()
Reported by: | wbajzek | Owned by: | imath |
---|---|---|---|
Milestone: | 2.1 | Priority: | normal |
Severity: | normal | Version: | 1.5.6 |
Component: | Extended Profile | Keywords: | has-patch commit |
Cc: | sam3dus@… |
Description
- Create a datebox profile field
- Set it for some user
- In the members loop, attempt to retrieve that field with bp_get_member_profile_data()
Result: blank
It looks like BuddyPress stores the output of the datebox as a string like "2012-07-19 00:00:00". bp_get_member_profile_data() retrieves that from the database and then passes it to xprofile_format_profile_field(), which passes it to bp_format_time(), which returns false because the value fails the is_numeric() check.
Either bp_format_time() needs to be fixed to handle the datebox output, or the datebox needs to be fixed so it stores time in the format that bp_format_time() expects.
Attachments (3)
Change History (13)
#3
@
12 years ago
Even if it didn't fail the is_numeric check, there would be this problem for xprofile_get_field_data() re type = datebox
bp_format_time() defaults to $localize_time = true
function bp_format_time( $time, $just_date = false, $localize_time = true )
Which you don't want on a profile datebox value unless it's Age.
(is there an Age converter function ? )
But in function xprofile_format_profile_field, $localize_time is not set to false.
if ( 'datebox' == $field_type ) { $field_value = bp_format_time( $field_value, true );
So even if you defeat the is_numeric fail by doing this
$time = strtotime( $time );
and passing it into xprofile_format_profile_field() you get a result that is 'off' by the local offset.
Can't figure out why this time issue doesn't appear on profile pages.
I suspect it's something in $members_template
#5
@
12 years ago
Instead of
xprofile_format_profile_field()
Use
xprofile_filter_format_field_value()
which handles time correctly.
Live and learn.
#6
@
10 years ago
- Keywords has-patch added
I think we have 2 ways to fix the problem :
- As the $field_value param of the function
xprofile_format_profile_field()
is a string : we can as wbajzek is suggesting "strtotime" the value before usingbp_format_time()
in case of a datebox field. (see 4365.strtotime.patch)
- or i've read in the docblock of this function that the "todo" suggests to move it as a filter. But there are already 2 filters in place that are doing the job (see 4365.filters.patch) :
- xprofile_filter_format_field_value
- and xprofile_filter_format_field_value_by_type
So i'd suggest to use them for the cases that are concerned :
- when using
bp_member_profile_data( 'field=Datebox' );
in the members loop - and when using
xprofile_get_random_profile_data()
to get a random field
This ticket was mentioned in IRC in #buddypress-dev by imathfromparis. View the logs.
10 years ago
#8
@
10 years ago
following up our discussion in dev-chat, 4365.03.patch is now directly using xprofile_filter_format_field_value_by_type()
to fix the issue.
see also #4374