WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can WordPress Support Pictures Inside Comments? (17 posts)

  1. aBieker
    Member
    Posted 8 years ago #

    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.

  2. Kafkaesqui

    Posted 8 years ago #

    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.

  3. aBieker
    Member
    Posted 8 years ago #

    Thanks.. I'll try that.

  4. aBieker
    Member
    Posted 8 years ago #

    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>

  5. Kafkaesqui

    Posted 8 years ago #

    This is the start of the array:

    $allowedtags = array(

    This is the end:

    );

  6. aBieker
    Member
    Posted 8 years ago #

    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?

  7. Kafkaesqui

    Posted 8 years ago #

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

    <?php

    and the last line is:

    ?>

  8. aBieker
    Member
    Posted 8 years ago #

    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.

  9. Jaxia
    Member
    Posted 8 years ago #

    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?

  10. Kafkaesqui

    Posted 8 years ago #

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

  11. Marc
    Member
    Posted 8 years ago #

    "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.

  12. dbasulto
    Member
    Posted 8 years ago #

    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...

  13. Slowfinger
    Member
    Posted 7 years ago #

    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!

  14. Slowfinger
    Member
    Posted 7 years ago #

    Anyone?

  15. Dgold
    Member
    Posted 7 years ago #

    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.

  16. Slowfinger
    Member
    Posted 7 years ago #

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

  17. Dgold
    Member
    Posted 7 years ago #

    To what Marc said -- I've got a site where registering is NOT open to anyone, so I don't think it would be abused by spammers in this case. My site has some 20+ trusted users. Like Slowfinger, I would like them to be able to reply with a picture in their comment.

    I'm not even so concerned about uploading... Even just letting them post a pic from their own website/server/shutterfly would be fine. It's just this trick of allowing IMG SRC to be used in comments, that I need.

    Is the wp-hacks method still useful under WP2.0.3?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags