Skip to:

Adding signature with post from form content

  • devfind


    The signature of the user comes from an external system and is retrieved through an API.
    I have the signature in the form in an hidden input before a new post or reply is created.
    All I need is to use a hook to automatically include this with the content.

    I am trying the following with no success.
    I am new to bbPress programming and I am trying to piece up information found on different sites, so bare with me if part of what I wrote is incorrect

    function add_signature_to_post($topic_id=0) {
    $content = get_post_field( ‘post_content’, $topic_id );
    $signature = “”;

    if (isset($_POST) && $_POST[‘bbp_signature’]!=”)
    $signature = $_POST[‘bbp_signature’];

    echo ‘<script>’;
    echo “console.log(‘Signature:”. $_POST[‘bbp_signature’] .”‘);”;
    echo ‘</script>’;

    return $content . $signature;

    add_action(‘bbp_new_topic’, ‘add_signature_to_post’, 10, 0);
    add_action(‘bbp_new_reply’, ‘add_signature_to_post’, 10, 0);


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

  • Robin W


    untested, but possibly

    function add_signature_to_post($topic_id=0) {
    $content = get_post_field( 'post_content', $topic_id );
    $signature = '';
    if (isset($_POST) && $_POST['bbp_signature']!='')
    $signature = $_POST['bbp_signature'];
    $content = $content . $signature;
    $topic_data = array(
    		'ID'           => $topic_id,
    		'post_content'   => $content
    	// update topic
    	$topic_id = wp_update_post( $topic_data);
    add_action('bbp_new_topic', 'add_signature_to_post', 10, 1);
    add_action('bbp_new_reply', 'add_signature_to_post', 10, 1);



    Thanks Robin.
    We tried the proposed solution, but it did not work.

    We have found an alternative way that works, but now we cannot include any html other than an anchor.
    Our <span>’s are simply remove and only the text is added.
    Any ideas how to get around this?

    This is the code that works:

      function bbp_convert_content($post_content){
    		$signature = "<span class='signature-separator'>----------</span>";	
            if (isset($_POST) && $_POST['bbp_sig_name']!='')
                $signature = $signature . "<span class='signature-name signature-field'>" . $_POST['bbp_sig_name'] . "</span>";
    		if (isset($_POST) && $_POST['bbp_sig_url']!='')
    			$signature = $signature . "<span class='signature-url signature-field'><a target='_blank' rel="noopener">  " . $_POST['bbp_sig_url'] . "</a></span>";
    		$signature = $signature . "<span class='signature-separator'>----------</span>";	
            return $post_content . $signature;
     add_filter('bbp_new_reply_pre_content', 'bbp_convert_content', 10, 3);
     add_filter('bbp_new_topic_pre_content', 'bbp_convert_content', 10, 1);

    Robin W


    content has a filter on it that prevents users using HTML tags to prevent code injections (apart form admins), so your <span> tags are probably being stripped by that.

    look around line 140 of \includes\topics\functions.php for removal for admins.

    you can use the filter in bbp_kses_allowed_tags() in \includes\common\formatting.php starting line 24

    to amend this.

    Robin W


    alternately just put an <hr> in 🙂



    Thanks Robin!

    Modifying bbp_kses_allowed_tags() worked for me!
    Adding the hr did not change anything 🙁

    Robin W


    glad you are fixed !

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