web-dev-qa-db-fra.com

comment éditer le format bbp_forum_freshness_link ()

J'essaie de trouver comment éditer le format de la fonction bbp_forum_freshness_link() dans le plugin bbpress. Par exemple. actuellement, il affiche le nombre de jours de la dernière activité et j'aimerais afficher la date. Donc, si quelqu'un souhaite partager des réflexions ou des extraits de code, ce serait formidable.

1
Ed T.

Je ne peux pas le tester pour l'instant, mais cela devrait fonctionner comme ceci:

add_filter( 'bbp_get_forum_freshness_link', 'wpse_77441_change_time_format', 10, 2 );

function wpse_77441_change_time_format( $anchor, $forum_id )
{
    $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );

    if ( empty( $last_active ) ) {
        $reply_id = bbp_get_forum_last_reply_id( $forum_id );

        if ( !empty( $reply_id ) ) {
            $last_active = get_post_field( 'post_date', $reply_id );
        } else {
            $topic_id = bbp_get_forum_last_topic_id( $forum_id );

            if ( !empty( $topic_id ) ) {
                $last_active = bbp_get_topic_last_active_time( $topic_id );
            }
        }
    }

    $date       = bbp_convert_date( $last_active );
    $time_since = bbp_get_forum_last_active_time( $forum_id );

    return str_replace( "$time_since</a>", "$date</a>", $anchor );
}
2
fuxia
function wpse_77441_change_time_format( $anchor, $forum_id )
{
    $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );

    if ( empty( $last_active ) ) {
        $reply_id = bbp_get_forum_last_reply_id( $forum_id );

        if ( !empty( $reply_id ) ) {
            $last_active = get_post_field( 'post_date', $reply_id );
        } else {
            $topic_id = bbp_get_forum_last_topic_id( $forum_id );

            if ( !empty( $topic_id ) ) {
                $last_active = bbp_get_topic_last_active_time( $topic_id );
            }
        }
    }

      $date   = get_post_time( get_option( 'date_format' ), $gmt, $reply_id, true );
      $time   = get_post_time( get_option( 'time_format' ), $gmt, $reply_id, true );
      $dt = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time );    

    $time_since = bbp_get_forum_last_active_time( $forum_id );


    return str_replace( "$time_since</a>", "$dt</a>", $anchor );
}
add_filter( 'bbp_get_forum_freshness_link', 'wpse_77441_change_time_format', 10, 2 );
0
user39260