Skip to:
Content
Pages
Categories
Search
Top
Bottom

Shorter Freshness Titles

  • @thesnowjunkies

    Participant

    Okay, where do I go to mess around with the freshness format? Specifically, I want to do away with anything involving a comma:

    Examples:

    “3 days, 19 hours” becomes “3 days”
    “4 weeks, 9 days” becomes “4 weeks”

Viewing 7 replies - 1 through 7 (of 7 total)
  • @johnjamesjacoby

    Keymaster

    Search for: ‘function bbp_get_time_since(‘

    @thesnowjunkies

    Participant

    Yes. That worked. Thanks @JJJ

    @olivier-lettinga

    Participant

    @thesnowjunkies Can you share what you made of this?

    @olivier-lettinga

    Participant

    Actually @JohnJamesJacoby it’s the same as done on this forum. Can you share how you did it?

    It would be great to have the option to pass a parameter like ‘shortlink’ => true to bbp_get_topic_freshness_link();

     

    @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.

    @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.

    @blg002

    Participant

    @thesnowjunkies @johnjamesjacoby @undyingearth @olivier-lettinga So here’s what I did, it looks to work but I haven’t fully put it through its paces. I’m also kind of a n00b with this PHP WordPress thing so hopefully this isn’t a terrible idea. I basically used an add filter on bbp_get_time_since and did a regex string replacement on the output removing anything from the first comma up to ‘ago’.

    function short_freshness_time( $output, $older_date, $newer_date ) {
      $output = preg_replace( '/, .*[^ago]/', ' ', $output );
      return $output;
    }
    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar