undyingearth (@undyingearth)

Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • @undyingearth

    Participant

    Ugh… the formatting went a bit crazy and deleted some of my response.

    Ignore the above. Basically, I wanted to say that I could achieve the effect I wanted by deleting some code from the core plugin, but I had problems when trying to do the same thing in my child theme functions.php.

    Here is the code I added to my functions.php

    http://pastebin.com/PNty9aPq

    It almost works – but it returns a freshness value that is wrong by several years (!)

    Any ideas?

    J.S.

    @undyingearth

    Participant

    I’ve almost got this working, but my PHP-fu skills are not quite strong enough. @johnjamesjacoby and @thesnowjunkies pointed me in the right direction, but I feel like I must be making a basic mistake in the implementation.

    I found the function bbp_get_time_since in /plugins/bbpress/includes/common/functions.php

    I managed to achieve the desired effect by deleting the following:

    `
    // Step two: the second chunk
    if ( $i + 2 $since ) {
    $output = $unknown_text;

    // We only want to output two chunks of time here, eg:
    // x years, xx months
    // x days, xx hours
    // so there’s only two bits of calculation below:
    } else {

    // Step one: the first chunk
    for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) {
    $seconds = $chunks[$i][0];

    // Finding the biggest chunk (if the chunk fits, break)
    $count = floor( $since / $seconds );
    if ( 0 != $count ) {
    break;
    }
    }

    // If $i iterates all the way to $j, then the event happened 0 seconds ago
    if ( !isset( $chunks[$i] ) ) {
    $output = $right_now_text;

    } else {

    // Set output var
    $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];

    // Step two: the second chunk
    if ( $i + 2 < $j ) {
    $seconds2 = $chunks[$i + 1][0];
    $name2 = $chunks[$i + 1][1];
    $count2 = floor( ( $since – ( $seconds * $count ) ) / $seconds2 );

    // Add to output var
    if ( 0 != $count2 ) {
    $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'bbpress' ) . ' 1 '. $name2 : _x( ',', 'Separator in time since', 'bbpress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
    }
    }

    // No output, so happened right now
    if ( ! (int) trim( $output ) ) {
    $output = $right_now_text;
    }
    }
    }

    // Append 'ago' to the end of time-since if not 'right now'
    if ( $output != $right_now_text ) {
    $output = sprintf( $ago_text, $output );
    }

    return apply_filters( 'bbp_get_time_short', $output, $older_date, $newer_date );
    }

    `

    This almost works. It cuts off the extra chunk. The problem is, it also returns a freshness value that is several years off. Instead of saying "10 minutes ago", it gives me "12 years ago"!

    Any ideas what I'm doing wrong? I can achieve what I want by editing the core plugin, but I'd really like to update-proof this.

    Thanks!

    J.S.

Viewing 2 replies - 1 through 2 (of 2 total)