Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bbp_get_time_since'

Viewing 25 results - 1 through 25 (of 28 total)
  • Author
    Search Results
  • #235956
    Robin W
    Moderator
    add_filter( 'bbp_get_reply_post_date', 'rew_show_time_since' , 10 , 6) ;
    add_filter( 'bbp_get_topic_post_date', 'rew_show_time_since' , 10 , 6) ;
    
    function rew_show_time_since ($result, $reply_id, $humanize, $gmt, $date, $time ){
    	$gmt_s  = ! empty( $gmt ) ? 'G' : 'U';
    	$date   = get_post_time( $gmt_s, $gmt, $reply_id );
    	$result = bbp_get_time_since( $date );
    return $result ;	
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    #235238

    In reply to: Customizing lead topic

    Robin W
    Moderator

    so is this with this function installed?

    add_filter ('bbp_get_topic_post_date' , 'rew_change_to_freshness', 10 , 6) ;
    add_filter ('bbp_get_reply_post_date' , 'rew_change_to_freshness', 10 , 6) ;
    
    function rew_change_to_freshness ($result, $topic_id, $humanize, $gmt, $date, $time) {
    	$result = bbp_get_time_since( bbp_convert_date( $time ) ) ;
    	
    return $result ;
    }
    #235036

    In reply to: Customizing lead topic

    Robin W
    Moderator

    you can leave the template for time unchanged.

    add_filter ('bbp_get_topic_post_date' , 'rew_change_to_freshness', 10 , 6) ;
    add_filter ('bbp_get_reply_post_date' , 'rew_change_to_freshness', 10 , 6) ;
    
    function rew_change_to_freshness ($result, $topic_id, $humanize, $gmt, $date, $time) {
    	$result = bbp_get_time_since( bbp_convert_date( $time ) ) ;
    	
    return $result ;
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    #228449
    Robin W
    Moderator

    untested, but this should work

    add_filter( 'bbp_get_topic_post_date', 'rew_date_only' , 20, 6) ;
    
    function rew_date_only ($result, $topic_id, $humanize, $gmt, $date, $time ){
    		$topic_id = bbp_get_topic_id( $topic_id );
    
    		// 4 days, 4 hours ago
    		if ( ! empty( $humanize ) ) {
    			$gmt_s  = ! empty( $gmt ) ? 'G' : 'U';
    			$date   = get_post_time( $gmt_s, $gmt, $topic_id );
    			$time   = false; // For filter below
    			$result = bbp_get_time_since( $date );
    
    		// August 4, 2012 at 2:37 pm
    		} else {
    			$date   = get_post_time( get_option( 'date_format' ), $gmt, $topic_id, true );
    			$result = $date;
    		}
    
    		// Filter & return
    		return apply_filters( 'rew_date_only', $result, $topic_id, $humanize, $gmt, $date, $time );
    	}
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    #221208
    Robin W
    Moderator

    ok, try this

    add_filter ('bbp_get_time_since' , 'rew_time_since_translate' ) ;
    		
    	
    	function rew_time_since_translate ($output) {
    		$output = preg_replace('/years/', 'new word', $output);
    		$output = preg_replace('/year/', 'new word', $output);
    		$output = preg_replace('/days/', 'new word', $output);
    		$output = preg_replace('/day/', 'new word', $output);
    		
    		return $output ;
    	}

    so change ‘new word’ in each case for what you want to show

    you can add as many lines as you need, but always do the plural first so ‘years’ followed by ‘year’

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    #218228
    Longbow
    Participant

    I’m digging through php and can’t locate where the word “On” gets inserted.

    bbpress/includes/replies/template/php

    lines 660-680

    
    	function bbp_get_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) {
    		$reply_id = bbp_get_reply_id( $reply_id );
    
    		// 4 days, 4 hours ago
    		if ( ! empty( $humanize ) ) {
    			$gmt_s  = ! empty( $gmt ) ? 'G' : 'U';
    			$date   = get_post_time( $gmt_s, $gmt, $reply_id );
    			$time   = false; // For filter below
    			$result = bbp_get_time_since( $date );
    
    		// August 4, 2012 at 2:37 pm
    		} else {
    			$date   = get_post_time( get_option( 'date_format' ), $gmt, $reply_id, true );
    			$time   = get_post_time( get_option( 'time_format' ), $gmt, $reply_id, true );
    			$result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time );
    		}
    
    		// Filter & return
    		return apply_filters( 'bbp_get_reply_post_date', $result, $reply_id, $humanize, $gmt, $date, $time );
    	}
    
    wpturk
    Participant

    You can remove everything between comma “,” and “ago” this way: (put in functions.php)

    function short_time ($output) {
        $output = preg_replace( '/, .*[^ago]/', ' ', $output );
        echo $output;
    }
    add_action ('bbp_get_time_since', 'short_time') ;
    #205379
    Robin W
    Moderator

    ok, the existing function is

    function bbp_get_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
    		$topic_id = bbp_get_topic_id( $topic_id );
    
    		// 4 days, 4 hours ago
    		if ( !empty( $humanize ) ) {
    			$gmt_s  = !empty( $gmt ) ? 'U' : 'G';
    			$date   = get_post_time( $gmt_s, $gmt, $topic_id );
    			$time   = false; // For filter below
    			$result = bbp_get_time_since( $date );
    
    		// August 4, 2012 at 2:37 pm
    		} else {
    			$date   = get_post_time( get_option( 'date_format' ), $gmt, $topic_id, true );
    			$time   = get_post_time( get_option( 'time_format' ), $gmt, $topic_id, true );
    			$result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time );
    		}
    
    		return apply_filters( 'bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time );
    	}

    so we can filter this as follows :

    add_filter ('bbp_get_topic_post_date' , 'rew_date' , 10 , 6) ;
    
    function rew_date ($result, $topic_id, $humanize, $gmt, $date, $time) {
    	$result = 'hello' ;
    
    return $result ;
    }

    This should then say ‘hello’ so all we want to do is change $result to read whatever you want – so what do you want it to say ?

    #194668
    siparker
    Participant

    Hi,

    The function bbp_get_time_since in includes/common/formatting.php always returns “right now”.

    bbPress Version: 2.6 release candidate 6

    #175383
    lflier
    Participant

    Here is a straightforward approach to abbreviating the time. Just put it in your functions.php file. You can modify the abbreviations as you wish:

    add_filter( 'bbp_get_time_since', 'abbreviate_time' );
    function abbreviate_time ( $output ) {
        $output = str_replace( 'minutes', 'min', $output );
        $output = str_replace( 'minute', 'min', $output );
        $output = str_replace( 'hours', 'hr', $output );
        $output = str_replace( 'hour', 'hr', $output );
        $output = str_replace( 'weeks', 'wk', $output );
        $output = str_replace( 'week', 'wk', $output );	
        $output = str_replace( 'months', 'mo', $output );
        $output = str_replace( 'month', 'mo', $output );    
        $output = str_replace( 'years', 'yr', $output );
        $output = str_replace( 'year', 'yr', $output );    
        return $output;
    }
    
    #173024
    Pascal Casier
    Moderator

    2 tips:
    – Install my bbP Toolkit
    – Use the code below:

    // Change freshness time by removing the last part, so '1 month, 3 days ago' becomes '1 month ago'
    function casiepa_shorten_freshness_time($return) {
    	$return = preg_replace( '/, .*[^ago]/', ' ', $return );
    	return $return;
    }
    add_filter( 'bbp_get_time_since', 'casiepa_shorten_freshness_time' );
    add_filter( 'bp_core_time_since', 'casiepa_shorten_freshness_time');

    PS. Ben je niet op https://wpnl.slack.com ?

    #168775
    Pascal Casier
    Moderator

    Well, for your specific case, you would probably go with:

    function bbptoolkitpc_shorten_freshness_time($return) {
    	$return = str_replace( "hour", "hr", $return );
    	$return = str_replace( "minutes", "min", $return );
    	return $return;
    }
    add_filter( 'bbp_get_time_since', 'bbptoolkitpc_shorten_freshness_time' );
    add_filter( 'bp_core_time_since', 'bbptoolkitpc_shorten_freshness_time');

    Pascal.

    #168768
    Pascal Casier
    Moderator

    Hi,
    The section is fine 🙂

    You will have to change the regular expression inside, but the basic function would look like this:

    function bbptoolkitpc_shorten_freshness_time($return) {
    	$bbptoolkit_short_fresh = get_option('bbptoolkit-short-fresh', false);
    	if ($bbptoolkit_short_fresh) {
    		$return = preg_replace( '/, .*[^ago]/', ' ', $return );
    	}
    	return $return;
    }
    add_filter( 'bbp_get_time_since', 'bbptoolkitpc_shorten_freshness_time' );
    add_filter( 'bp_core_time_since', 'bbptoolkitpc_shorten_freshness_time');

    Pascal.

    #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
    Keymaster
    #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(‘

Viewing 25 results - 1 through 25 (of 28 total)
Skip to toolbar