Skip to:
Content
Pages
Categories
Search
Top
Bottom

Filtering bp_format_time

  • @henrywright-1

    Member

    I’m trying to filter bp_format_time in bp-core-template.php

    apply_filters( 'bp_format_time', $date ); allows me to pass $date to my filter function but surely I need to pass the $time variable as well? Not entirely sure how this can be done?

Viewing 6 replies - 1 through 6 (of 6 total)
  • @shanebp

    Moderator

    In your filter, var_dump $date – what do you see ?

    @henrywright-1

    Member

    Hi @shanebp

    If you take a look at the bp_format_time function (I have copied to Pastie.org for easy access) you’ll see the $date variable that is being returned needs both the $date and $time variables (see line 22):

    http://pastie.org/8468225

    return apply_filters( 'bp_format_time', $date ) only seems to allow me to pass $date to my filter function. Is there a way to pass $time variable as well or am I looking at this wrong?

    @shanebp

    Moderator

    $date doesn’t include the time unless $just_date is false.
    $time is never sent as a separate variable.

    So you’ll have to figure out how to call bp_format_time() without setting $just_date to true.
    Or write your own function.

    grep bp_format_time()
    I think you’ll see that usually BP calls it with a true value for $just_date.

    @henrywright-1

    Member

    I’m actually looking at formatting the date in private messages and in that case WP doesn’t call the function with true. $just_date is set to false by default so that part is all good.

    as you say I think i’ll have to write my own custom bp_format_time function. Thanks for your help!

    @shanebp

    Moderator

    > looking at formatting the date in private messages … $just_date is false.

    Then the filter will work fine.
    The time will be part of the string passed in $date.
    [ In your filter, var_dump $date – what do you see ? ]
    You just have do some string and date operations on that string.

    @henrywright-1

    Member

    Ah got ya! Thanks @shanebp i’m on your wavelength now. $date being a string I can perform some operations on.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Filtering bp_format_time’ is closed to new replies.
Skip to toolbar