To allow unregistered users to post embedded images from other sites in comments, you will need to modify wp comment handling to permit certain HTML
tags for unregistered users. By default, wp sanitizes
HTML input from unregistered users for security reasons.
You need to modify the list of allowed HTML tags in comments for unregistered users. You can use preprocess_comment
wp filters
add code your functions.php
file
// Allow unregistered users to post embedded images in comments
function allow_unregistered_users_to_post_images($comment_data) {
// Check if the user is unregistered
if (!is_user_logged_in()) {
// Define the allowed HTML tags for unregistered users
$allowed_tags = array(
'a' => array(
'href' => array(),
'title' => array()
),
'img' => array(
'src' => array(),
'alt' => array(),
'title' => array(),
'width' => array(),
'height' => array()
),
'br' => array(),
'em' => array(),
'strong' => array()
// Add more tags if needed
);
// Set the allowed HTML tags for unregistered users
$comment_data['comment_content'] = wp_kses($comment_data['comment_content'], $allowed_tags);
}
return $comment_data;
}
add_filter('preprocess_comment', 'allow_unregistered_users_to_post_images');
above code allow unregistered users to post embedded images <img>
tags in comments. Adjust the $allowed_tags
array as needed to permit other HTML tags or attributes