Skip to:
Content
Pages
Categories
Search
Top
Bottom

writing to contents


  • Clivesmith
    Participant

    @clivesmith

    Is there a hook or action I am missing to add something to the bottom of the contents of a reply when I publish, I don’t mean just show it on a reply but to write it to the table.
    I have a custom field that I populate in a topic I want to add it to the end of each reply. I know how to check if it is already there etc.
    I want it to write it to the contents so it is passed out with the rss feed to twitter etc.

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

  • Robin W
    Moderator

    @robin-w

    something like this should do it

    add_filter( 'bbp_new_reply_pre_content', 'my_function'  );
    
    function my_function ($reply_content) {
    $extra_text = 'hello' ;
    //append extra text to the end of reply content
    $reply_content.= $extra_text ;
    
    return $reply_content ;
    }

    Clivesmith
    Participant

    @clivesmith

    Hi Robin,

    Thank you, if I add that to my functions file, it adds it to a new reply perfectly if I as admin create that new reply.
    But it does not work if a guest replies (it is normal for my replies to be from guests) all replies go to moderation and at the moment, before I approve the reply by publishing I add test at the end of each content. It is when I click publish that I want it to add the text.

    Regards

    Clive


    Robin W
    Moderator

    @robin-w

    do you have a plugin sending them to moderation ?


    Clivesmith
    Participant

    @clivesmith

    No, if I remember rightly, it is set up under settings / discussions to allow anyone to post comments and all go to moderation, no-one can join so all replies are all


    Clivesmith
    Participant

    @clivesmith

    Sorry I lied, just found I do have a plugin bbpress moderation tools by digital arm


    Robin W
    Moderator

    @robin-w

    so how do you ‘publish’ them

    eg dashboard>something>something else

    and what is the status of the reply before and after?


    Clivesmith
    Participant

    @clivesmith

    In dashboard I see in “all replies” a pending reply.
    When I click on edit, in the reply attributes box the status is Pending
    I have a publish button

    (this is when at the moment I add my text to the contents)

    When I publish the Status changes to Publish and the button changes to update


    Robin W
    Moderator

    @robin-w

    try this

    function waa_content( $content, $post_id ) {
     $extra_text = 'hello' ;
    //append extra text to the end of reply content
    $content.= $extra_text ;
    return content ;
    }
      
    add_filter( 'content_edit_pre', 'waa_content', 10, 2 );

    Clivesmith
    Participant

    @clivesmith

    Many Thanks Robin

    I added $ to content on line 5 and it works but it also works on topics and forums, I will add a
    if ($post->post_type ==’reply’){

    around it, thanks again

    Clive


    Clivesmith
    Participant

    @clivesmith

    oops must have got the IF wrong, does not work with that


    Robin W
    Moderator

    @robin-w

    the $post array does not exist in this function

    try

    if (get_post_type ($post_id) == bbp_get_reply_post_type() ) {


    Clivesmith
    Participant

    @clivesmith

    Just to update, all seems to be working so I thought I would share this. I am sure the coding is bad but it works !!
    I am the only one that can create topics, I moderate all replies and want to add to the end of each reply ‘#plasticfree’ and a custom metadata value for each topic that I put in when I create a topic.
    This means that the hashtag and twitter name goes out with the RSS feed to tiwtter etc.
    Thank you Robin for all your help.

    /***   
    To add #plasticfree and twitter name to reply
    ***/
    
    function waa_content( $content, $post_id ){
    	// get the topic id 		
    	$post_id = get_the_ID();
    	$reply_topic_id = bbp_get_reply_topic_id( $post_id );
    	// get value from table
        $twitname = get_post_meta( $reply_topic_id, 'bbp_twitname', true );
    	$twithash = '#plasticfree';
    
    	$post = get_post($id);
    
    if ($post->post_type =='reply'){
    $pos = strpos($content, '#plasticfree');
    
        if ($pos == false) {
    		$content .= '<br>'. $twithash .' ' .$twitname;
        } 
    }
    	return $content;
    }
    add_filter( 'content_edit_pre', 'waa_content', 10, 2 );
    

    Robin W
    Moderator

    @robin-w

    code that works is never bad !!

    thanks for posting the final solution, and great that it works !

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