[wp-trac] [WordPress Trac] #11394: Image shortcode

WordPress Trac wp-trac at lists.automattic.com
Fri Apr 9 17:38:37 UTC 2010


#11394: Image shortcode
-----------------------------+----------------------------------------------
 Reporter:  caesarsgrunt     |       Owner:                          
     Type:  feature request  |      Status:  new                     
 Priority:  normal           |   Milestone:  3.1                     
Component:  Media            |     Version:  2.9                     
 Severity:  normal           |    Keywords:  needs-patch dev-feedback
-----------------------------+----------------------------------------------

Comment(by Otto42):

 What really bugs me is that you don't need to make a shortcode to
 accomplish any of the stated goals in the original ticket. It's overkill.

 Look at the goals:

 * allowing images to be trashed
 * allowing plugins and themes to modify the code used to show images
 * removing broken img tags from posts when the image is deleted

 All of these can be done with some clever use of classes and
 preg_matching. And it would be simpler and faster than using shortcodes to
 do it, in fact, because you wouldn't need to modify the existing code much
 at all.

 Look, I'll give you an example. This code will find all img tags in a post
 and parse them, then spit out their src and class.

 global $post;
 if ( preg_match_all('/<img (.+?)>/', $post->post_content, $matches) ) {
         foreach ($matches[1] as $match) {
                 foreach ( wp_kses_hair($match, array('http')) as $attr)
                         echo $img['src'];
                         echo $img['class'];
                 }
         }
 }

 Pretty simple, really. If the class contained something like,
 attachment-123, then finding the 123 and checking to see if the image was
 deleted would be rather straightforward, wouldn't it?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11394#comment:45>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list