WordPress.org

Forums

[resolved] get_post () stripping (some) html (4 posts)

  1. jessicadennis
    Member
    Posted 3 years ago #

    I'm modifying a plugin (post2mail) to modernize it, thinking that that would resolve the issue I'm having -- namely, that while the plugin does indeed email something, it isn't quite correct, in that p tags in post_content are gone. a tags are there, and ul and li tags, but not p. This is infuriating, as my output looks terrible. The p tags are simply gone. Is this by design? Is there some way I could make this not so? It's so close to working the way I want it to. the code:

    function post2mail($post_ID){
    	global $linktext;
    	require_once('post2mail.config.php');
    
    	$the_post = get_post($post_ID, ARRAY_A);
    	$subject = stripslashes($the_post['post_title']);
    
    	/* message */
    	if ($sendHTML) {
    		/* To send HTML mail, you can set the Content-type header. */
    		$headers  = "MIME-Version: 1.0\r\n";
    		$headers .= "Content-type: text/html; charset=utf-8\r\n";
    		$headers .= "Content-Transfer-Encoding: 8bit\r\n";
    		$message = convert_chars($the_post['post_content']);
    		$message .= addMailLinkBack($post_ID);
    	}
    	else {
    		$headers  = "MIME-Version: 1.0\r\n";
    		$headers .= "Content-type: text/plain; charset=utf-8\r\n";
    		$headers .= "Content-Transfer-Encoding: 8bit\r\n";
    		$message = stripslashes(strip_tags($the_post['Content']));
    		$message .= "\r\n\r\n" . $linktext . ': ' . get_permalink($post_ID);
    		$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
    	}
    
    	/* additional headers */
    	$headers .= "From: $from\r\n";
    	if ($cc != '') {
    		$headers .= "Cc: $cc\r\n";
    	}
    	if ($bcc != '') {
    		$headers .= "Bcc: $bcc\r\n";
    	}
    
    	/* and now mail it */
    	mail($to, $subject, $message, $headers);
    
    	return $post_ID;
    }
    
    add_action('publish_post', 'post2mail', 5);

    Any help will be enormously appreciated.

  2. jessicadennis
    Member
    Posted 3 years ago #

    I'm wrong -- the p tags aren't present in the database, so get_post couldn't get them if it wanted to.

  3. jessicadennis
    Member
    Posted 3 years ago #

    If anyone else has this issue, the solution is on line 24 of the above code; corrected code is:

    $message = wpautop($the_post['post_content']);

  4. j0nwarr3n
    Member
    Posted 3 years ago #

    If anyone else sees this and is initially confused by why the solution would be the closing curly-brace of the else block, in the above quoted code, the line is line 14. In the original php file, it's line 24.

    In other words, change this line:
    $message = convert_chars($the_post['post_content']);

Topic Closed

This topic has been closed to new replies.

About this Topic