Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to display when the User Edited His post


  • icypopsicle
    Member

    @icypopsicle

    Hello, I want to display on the forum topic post if the user has edited their post. Like if the user, OR a mod or admin have edited a post, i want text to appear below the content

    “Last Edit By **name** on **date*

    how can I do this?

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

  • Brandon Allen
    Participant

    @cnorris23

    This would take some code work, because neither bbPress or BuddyPress store this information. You would need to hook into ‘groups_edit_forum_post’ and the use bb_update_postmeta() and bb_get_postmeta() to save/retrieve the information. The following will get you started:

    `my_update_forum_post_last_edited( $post_id ) {
    global $bp;

    do_action( ‘bbpress_init’ );

    $post_id = (int) $post_id;

    if ( empty( $post_id ) )
    return;

    bb_update_postmeta( $post_meta, ‘last_edited_date’, bp_core_current_time() );
    bb_update_postmeta( $post_meta, ‘last_edited_user’, $bp->loggedin_user->id );
    }
    add_action( ‘groups_edit_forum_post’, ‘my_update_post_lasted_edited’ );

    function my_display_forum_post_last_edited() {
    do_action( ‘bbpress_init’ );

    $last_edited_user = bb_get_postmeta( bp_get_the_topic_post_id(), ‘last_edited_user’ );
    $last_edited_date = bb_get_postmeta( bp_get_the_topic_post_id(), ‘last_edited_date’ );

    if ( empty( $last_edited_user ) || empty( $last_edited_date ) )
    return;

    echo ‘Last edited by ‘ . bp_core_get_user_display_name( $last_edited_user ) . ‘ on ‘ . bp_format_time( $last_edited_date ) . ‘ ‘;
    }
    add_action( ‘bp_group_forum_post_meta’, ‘my_display_forum_post_last_edited’ );`


    icypopsicle
    Member

    @icypopsicle

    “should get you started”

    what else do I need to do?


    Brandon Allen
    Participant

    @cnorris23

    Try it. I should do everything for you. “Get you started” means just that. It will get you started, and then you can tweak it to your needs.


    icypopsicle
    Member

    @icypopsicle

    do I put in my topic.php

    `<?php my_update_forum_post_last_edited( my_display_forum_post_last_edited() );`

    Because the code by itself does not do anything


    Brandon Allen
    Participant

    @cnorris23

    No, the code goes in your functions.php file. You won’t need to make any other changes.


    Brandon Allen
    Participant

    @cnorris23

    You’ll also need to edit a post before anything will show.


    Brandon Allen
    Participant

    @cnorris23

    Also, I haven’t tested any of this, so you may need to play around a little more to make it functional.


    icypopsicle
    Member

    @icypopsicle

    i put it in bp-custom.php which is the same thing, and it does nothing.

    -Side Note, I am running TinyMCE editors on my forum texareas. Not sure if that could be breaking it.


    Brandon Allen
    Participant

    @cnorris23

    Yeah, that’s because I put in the wrong variable so nothing was saving. Replace the first function with this, and then see what happens. You’ll need to edit a post again.

    `my_update_forum_post_last_edited( $post_id ) {
    global $bp;

    do_action( ‘bbpress_init’ );

    $post_id = (int) $post_id;

    if ( empty( $post_id ) )
    return;

    bb_update_postmeta( $post_id, ‘last_edited_date’, bp_core_current_time() );
    bb_update_postmeta( $post_id, ‘last_edited_user’, $bp->loggedin_user->id );
    }
    add_action( ‘groups_edit_forum_post’, ‘my_update_post_lasted_edited’ );`


    icypopsicle
    Member

    @icypopsicle

    Still nothing appeared. :( :(

    I don’t know how to do code at all, so thanks for helping! :)


    Brandon Allen
    Participant

    @cnorris23

    Apparently I have an issue today with fat fingers or bad copy/paste-itus. Try this:

    `my_update_forum_post_last_edited( $post_id ) {
    global $bp;

    do_action( ‘bbpress_init’ );

    $post_id = (int) $post_id;

    if ( empty( $post_id ) )
    return;

    bb_update_postmeta( $post_id, ‘last_edited_date’, bp_core_current_time() );
    bb_update_postmeta( $post_id, ‘last_edited_user’, $bp->loggedin_user->id );
    }
    add_action( ‘groups_edit_forum_post’, ‘my_update_forum_post_last_edited’ );`


    icypopsicle
    Member

    @icypopsicle

    :)

    :( No avail. Still nothing appears. :???:

    Where is the text supposed to appear?


    Brandon Allen
    Participant

    @cnorris23

    Theoretically it should show up at the top of the post that was edited, right beside the #. Are you using the bp-default theme?


    icypopsicle
    Member

    @icypopsicle

    No. I have a very weird forum layout. It’s actually so modified that the “#” is next to the topic Meta.


    Brandon Allen
    Participant

    @cnorris23

    Well that could be the reason. Do you have `do_action( ‘bp_group_forum_post_meta’ );` anywhere in your template in the meta section? My guess is no, which is why nothing is displaying. You can try adding `my_display_forum_post_last_edited()` where you’d like the “Last edited…” text to appear.


    icypopsicle
    Member

    @icypopsicle

    Ok, looks good, but the date is wrong.

    It says it was edited on “December 31, 1969” 😆 :)


    Brandon Allen
    Participant

    @cnorris23

    Try changing `bp_format_time( $last_edited_date )` to `bp_format_time( strtotime( $last_edited_date ) )`


    icypopsicle
    Member

    @icypopsicle

    The time is still an hour behind my local time.

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘How to display when the User Edited His post’ is closed to new replies.
Skip to toolbar