Support » Fixing WordPress » Can WordPress Support Pictures Inside Comments?

  • Resolved aBieker

    (@abieker)


    Is it possible to make wordpress display pictures inside comments? I’ve tried uploading pics to my “/images” directory and then linking to them by putting a standard <img> tag in my comment, but it just displays the tag, not the pic. Is it possible to get WP to recognize the HTML tag when it’s simply written into a comment?

    Ideally, I would like to allow visitors to upload small pics and include them in their comments, but I’m trying to tackle this one issue at a time. That should give you some context. Nevertheless, if you happen to have any great ideas for how to design a simple little pop-up upload window that would automatically link the uploaded pics with the comment being posted, that would be good too… but that’s still a little ways off for the momment. Any help would be greatly appreciated. Thanks.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Can’t say anything about the whole uploading image to comments, but you can override what tags are allowed. There are two ways to do this:

    1. Edit kses.php in your wp-includes/ directory, and in the $allowedtags array insert something like:

    'img' => array('src' => array(), 'alt' => array, 'height' => array(), 'width' => array()),

    2. Copy the entire $allowedtags array to your my-hacks.php file, make what modifications to it you want, and just under it add:

    define('CUSTOM_TAGS', true);

    2 is a bit more work, but you benefit from not having to keep track of your changes to $allowedtags whenever you update WordPress.

    Thanks.. I’ll try that.

    Okay… so I’m trying the second option, but being new to WP, I’m a little stuck.. when I copy the $allowedtags array, where do I copy from and to?

    <i>HERE>>?</i>
    if (!defined(‘CUSTOM_TAGS’))
    define(‘CUSTOM_TAGS’, false);

    // You can override this in your my-hacks.php file

    <i>OR HERE>>>?</i>

    if (!CUSTOM_TAGS) {
    $allowedtags = array(
    ‘a’ => array(
    ‘href’ => array(),
    ‘title’ => array()
    ),
    ‘abbr’ => array(‘title’ => array()),
    ‘acronym’ => array(‘title’ => array()),
    ‘b’ => array(),
    ‘blockquote’ => array(‘cite’ => array()),
    // ‘br’ => array(),
    ‘code’ => array(),
    // ‘del’ => array(‘datetime’ => array()),
    // ‘dd’ => array(),
    // ‘dl’ => array(),
    // ‘dt’ => array(),
    ’em’ => array(),
    ‘i’ => array(),
    // ‘ins’ => array(‘datetime’ => array(), ‘cite’ => array()),
    // ‘li’ => array(),
    // ‘ol’ => array(),
    // ‘p’ => array(),
    // ‘q’ => array(),
    ‘strike’ => array(),
    ‘strong’ => array(),
    // ‘sub’ => array(),
    // ‘sup’ => array(),
    // ‘u’ => array(),
    // ‘ul’ => array(),
    ); <i> >>>HERE? </i>
    } <i> >>HERE? </i>
    function wp_kses($string, $allowed_html, $allowed_protocols =
    array(‘http’, ‘https’, ‘ftp’, ‘news’, ‘nntp’, ‘feed’, ‘gopher’, ‘mailto’))
    <i>>>OR HERE? </i>

    This is the start of the array:

    $allowedtags = array(

    This is the end:

    );

    Okay.. last part of my question…

    I don’t currently have a my-hacks.php file as I’ve just started modifying the original code. I DID enable hacks in my admin panel. Do I simply create a file “my-hacks.php” with NOTHING in it other than this array (and the ‘custom_tags’ true command) and then plunk it down in my root folder?

    Pretty much, but make sure the first line in your my-hacks.php is:

    <?php

    and the last line is:

    ?>

    Got it… although I ended up deciding to nest an icon image that links to the actual image. If anyone ever wants to put images in their comments though, this seems like a good way to go. Thanks for the help, Kafkaesqui.

    Hey Kafkaesqui – I am trying to add that line to my kses file to allow images in comments, but I get this error when I try to view my site:

    Parse error: parse error, unexpected ‘,’, expecting ‘(‘ in /home/youknow/public_html/wp-includes/kses.php on line 34

    Any ideas?

    The error points out a mistake in your PHP syntax, most likely from placing the ‘img’ array on the wrong line. A simple step-by-step for editing the $allowedtags array in kses.php is:

    1. Start with a fresh (unedited) version of kses.php.

    2. The full if statement in which $allowedtags is located starts:

    if (!CUSTOM_TAGS) {

    and ends:
        );
    }

    3. Add the line right before the end of the $allowedtags array and the if statement, like so:

    'img' => array('src' => array(), 'alt' => array, 'height' => array(), 'width' => array())
        );
    }

    “Ideally, I would like to allow visitors to upload small pics and include them in their comments.”

    A word of caution: I understand you want to provide this option for your visitors, but.

    If your comments are open, i.e. comment without registering, you may soon find spammers discovering a new toy to play with and you’ll see less than desirable pics on your site.

    i’m using default 1.5.2 install an im able to post pics (for registered users) using the img tags. no need to update anything…

    Slowfinger

    (@slowfinger)

    Hi Kafkaesqui,

    2. Copy the entire $allowedtags array to your my-hacks.php file, make what modifications to it you want, and just under it add:

    define(‘CUSTOM_TAGS’, true);

    assuming that the $allowedtags array should include the new
    'img' => array
    when creating the new my-hacks.php file,

    1) should the line
    define('CUSTOM_TAGS', true);
    be inserted between
    );
    and
    }
    or right under the latter?
    2) Should it be level with
    ); ?
    3) Total newbie to wp and coding, any hints/source on how to edit the look of the
    'img' => array
    line in order for commentors to be able to upload images?
    I can vaguely grasp some attributes, but any clue would be tremendously welcome to prevent from scattering disaster across wp ALAP. Thanks!

    Slowfinger

    (@slowfinger)

    Anyone?

    Dgold

    (@dgold)

    I’ve found that I, as admin, can post a picture in the Edit Comments page. However my users can’t post it themselves, at best they can paste in the URL, and I edit it to show up as an image.

    Slowfinger

    (@slowfinger)

    I know, thanks. I’m interested in enabling direct image uploading by users.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Can WordPress Support Pictures Inside Comments?’ is closed to new replies.