Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bbp_get_time_since'

Viewing 15 results - 1 through 15 (of 15 total)
  • Author
    Search Results
  • #147133

    Robin W
    Moderator

    ok, so

    //function to remove the comma
    function change_comma_time($output) {
    $output = preg_replace( ‘/[,]/’ , ‘ ‘ , $output );
    return $output;
    }
    add_filter( ‘bbp_get_time_since’, ‘change_comma_time’ );
    add_filter(‘bp_core_time_since’, ‘change_comma_time’);

    will take out the commas. You need to add this to your functions file and

    ‘function custom_get_forum_freshness_link() {
    $time_since = bbp_get_forum_last_active_time( $forum_id );
    $anchor = $time_since ;
    return $anchor ;
    }

    add_filter( ‘bbp_get_forum_freshness_link’, ‘custom_get_forum_freshness_link’ );’

    will take out the link

    You will need to add these to your functions file.

    Come back if you need further help

    #142480

    Robin W
    Moderator

    so the answer is

    function short_freshness_time( $output) {
    $output = preg_replace( '/, .*[^ago]/', ' ', $output );
    return $output;
    }
    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    add_filter('bp_core_time_since', 'short_freshness_time');

    Drop this into your functions file

    #142470

    Stephen Edgar
    Moderator
    #142464

    virusek89
    Participant

    bbp_get_time_since

    I found it in these files

    bbpress\includes\topics\template-tags.php
    bbpress\includes\replies\template-tags.php
    bbpress\includes\forums\template-tags.php
    bbpress\includes\common\widgets.php
    bbpress\includes\common\functions.php

    Now what I need to edit to remove the rest of the decimal?

    I want to ask because I am a beginner in php

    #142460

    You’ll want to filter the output of bbp_get_time_since; it’s the function responsible for humanizing timestamps. You’ll probably want to perform a string replacement starting at the comma, and append your own ‘ago’ at the end.

    #142324

    Majijiboo
    Participant

    @koendb

    Which bbpress file should I add the below filter to to get that feature? Thanks.

    function short_freshness_time( $output) {
    $output = preg_replace( '/, .*[^ago]/', ' ', $output );
    return $output;
    }
    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    add_filter('bp_core_time_since', 'short_freshness_time');
    #141648

    koendb
    Participant

    Ah, sorry @shmoo or @macpress: forgot to add the filters:

    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    add_filter('bp_core_time_since', 'short_freshness_time');
    #141624

    koendb
    Participant

    Thanks Shmoo!
    I added this filter, don’t remember where I found it:

    function short_freshness_time( $output) {
    $output = preg_replace( '/, .*[^ago]/', ' ', $output );
    return $output;
    }
    
    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    add_filter('bp_core_time_since', 'short_freshness_time');

    Shall we leave this thread to Mycelus now? Feel free to PM me or open your own.

    #135580

    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' );
    
    #134256

    gingerngo
    Participant

    Hi,

    I’m wondering how I can create a function that will allow me to output just 1 time chunk in the freshness column instead of 2.

    So instead of “3 months, 1 hour” it will just be “3 months” and “4 hours, 23 minutes” will just be “4 hours.”

    I found the bbp_get_time_since() function, but I’d like to create a separate function so I don’t edit the plugin files. Is this possible?

    #126282

    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.

    #119989

    Search for: ‘function bbp_get_time_since(‘

    #112253

    highexistence
    Participant

    Anyone else interested, place this in your functions.php file:

    function bbp_get_reply_last_active_time( $reply_id ) {

    $last_active = get_post_field( 'post_date', $reply_id );

    $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) . ' ago' : '';

    return $last_active;

    }

    and then call it in loop-single-reply.php

    #108109

    ebharding
    Participant

    This was my solution

    I edited line 178 in my /wp-content/plugins/bbpress/bbp-includes/bbp-common-functions.php

    function bbp_get_time_since( $time ) {

    return apply_filters( ‘bbp_get_time_since’, human_time_diff( $time – 25200, current_time( ‘timestamp’ ) ), $time );

    }

    In my case (Pacific Time) I needed to subtract 7 hours which translated to 25200 seconds.

    #95271

    @miruru – You could filter

    bbp_get_topic_last_active

    and output your own time, or you could hook into

    bbp_get_time_since

    and have it return the second parameter that’s passed to it.

Viewing 15 results - 1 through 15 (of 15 total)