Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding signature with post from form content

  • @devfind

    Participant

    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);

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • @robin-w

    Moderator

    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);

    @devfind

    Participant

    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

    Moderator

    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

    Moderator

    alternately just put an <hr> in 🙂

    @devfind

    Participant

    Thanks Robin!

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

    @robin-w

    Moderator

    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