Skip to:
Content

BuddyPress.org

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's profile wbajzek Owned by: imath's profile imath
Milestone: 2.1 Priority: normal
Severity: normal Version: 1.5.6
Component: Extended Profile Keywords: has-patch commit
Cc: sam3dus@…

Description

  1. Create a datebox profile field
  2. Set it for some user
  3. 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)

4365.strtotime.patch (632 bytes) - added by imath 10 years ago.
4365.filters.patch (3.9 KB) - added by imath 10 years ago.
4365.03.patch (1.3 KB) - added by imath 10 years ago.

Download all attachments as: .zip

Change History (13)

#1 @luccame
12 years ago

see also #4374

#2 @DJPaul
12 years ago

  • Milestone changed from Awaiting Review to Future Release

#3 @shanebp
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

$field_value = strtotime( $field_value );

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

Last edited 12 years ago by shanebp (previous) (diff)

#4 @shanebp
12 years ago

  • Cc sam3dus@… added

#5 @shanebp
12 years ago

Instead of

xprofile_format_profile_field()

Use

xprofile_filter_format_field_value()

which handles time correctly.

Live and learn.

#6 @imath
10 years ago

  • Keywords has-patch added

I think we have 2 ways to fix the problem :

  1. 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 using bp_format_time() in case of a datebox field. (see 4365.strtotime.patch)
  1. 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
Last edited 10 years ago by imath (previous) (diff)

@imath
10 years ago

This ticket was mentioned in IRC in #buddypress-dev by imathfromparis. View the logs.


10 years ago

#8 @imath
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.

Last edited 10 years ago by imath (previous) (diff)

@imath
10 years ago

#9 @boonebgorges
10 years ago

  • Keywords commit added
  • Milestone changed from Future Release to 2.1

Yeah, this looks good for now. Thanks!

#10 @imath
10 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 8689:

Make sure xprofile_format_profile_field() returns a well formatted value in case of a datebox field.

This function is now using the display_filter() filters as defined by the corresponding BP_XProfile_Field_Type classes.

Props wbajzek, shanebp.

Fixes #4365

Note: See TracTickets for help on using tickets.