Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add reply programatically


  • egathernl
    Participant

    @egathernl

    Hi,

    I’ve created a custom module for bbpress to combine all new topics and replies in one overview. From there the moderator can comment on all the incoming messages. This works only i’ve one problem. To add a new reply i use the next code:

    reply_data = array('post_parent'=>$post_parent, 'post_content' => $post_content);
    $reply_meta = array('forum_id'=>$post_forum_id, 'topic_id' => $post_topic_id);
    bbp_insert_reply($reply_data,$reply_meta);
    

    When this is a reply on an other reply everything works fine. But when it is a reply on a new topic then the Topic starter ip-adres is changed to the ip-address of the moderator. I can turn some things off in the core function includes/topics/functions.php

    // Update poster IP if not editing
    update_post_meta( $topic_id, '_bbp_author_ip', bbp_current_author_ip(), false );
    

    But that isn’t what I prefer of course.

    Could someone help me out?

    Thanks in advance.

    Niels

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

  • Robin W
    Moderator

    @robin-w

    sorry can you just clarify

    Topic A
    Reply B

    Does topic A acquire reply B authors’s IP address, or does reply B get Topic A authors IP address ?


    egathernl
    Participant

    @egathernl

    Topic A gets reply B Authors ip-address.


    Robin W
    Moderator

    @robin-w

    ok, I know why it is doing it, I’ll do some digging to see how to get around

    your function calls

    bbp_insert_reply

    this function is in

    /includes/replies/functions.php starts line 29

    This creates the reply, and then on line 64 it has

    // Update the topic
    	$topic_id = bbp_get_reply_topic_id( $reply_id );
    	if ( !empty( $topic_id ) ) {
    		bbp_update_topic( $topic_id );
    	}

    bbp_update_topic is held in

    /includes/topics/functions.php starting line 818

    has a check to see if you are creating or editing a topic.

    if you are not editing a topic, it presumes that you are creating so starting line 884

    // Update associated topic values if this is a new topic
    	if ( empty( $is_edit ) ) {
    
    		// Update poster IP if not editing
    		update_post_meta( $topic_id, '_bbp_author_ip', bbp_current_author_ip(), false );

    since at that point your call via bbp_insert_reply and bbp_update_topic is NOT an edit, it assumes it is a new topic and updates with the current user IP as above.

    let me think about easiest way to fix.


    Robin W
    Moderator

    @robin-w

    the quick and dirty solution is to get the topic IP before executing bbp_insert_reply and reset it afterwards

    eg (untested)

    $reply_data = array('post_parent'=>$post_parent, 'post_content' => $post_content);
    $reply_meta = array('forum_id'=>$post_forum_id, 'topic_id' => $post_topic_id);
    //get the topic IP so we can reset it later
    $ip = get_post_meta( $topic_id, '_bbp_author_ip', false );
    bbp_insert_reply($reply_data,$reply_meta);
    //reset the topic IP
    update_post_meta( $topic_id, '_bbp_author_ip', $ip, false );

    I could spend a long time working out a more elegant fix, but hopefully the above will be enough !


    egathernl
    Participant

    @egathernl

    Just wondering how the script makes the decision if I’m creating or editing a topic. Because I can’t give the $is_edit variable a value in the bbp_insert_reply and I give a excisting topic_id when insert a reply.. Well, maybe when I’ve more time I will look in to this and post the solution here if I find one. For now I will use your other solution.

    Thanks for your help and thoughts Robin!


    Robin W
    Moderator

    @robin-w

    Just wondering how the script makes the decision if I’m creating or editing a topic.

    not an area of the plugin I’ve yet delved into ! hense the quick and dirty !

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar