[wp-trac] [WordPress Trac] #19806: do_allowed_shortcodes to allow processing of limited list of shortcodes

WordPress Trac wp-trac at lists.automattic.com
Wed Jan 11 22:22:52 UTC 2012


#19806: do_allowed_shortcodes to allow processing of limited list of shortcodes
-------------------------+------------------------------
 Reporter:  beezeee      |       Owner:  beezeee
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------

Comment (by beezeee):

 realized there was a typo, here's the correct code


 {{{
 function do_allowed_shortcodes($content, $shortcodes=array())
 {
     //if no allowed shortcodes are provided, strip all shortcodes and
 return content
         if (empty($shortcodes))
         {
                 return(strip_shortcodes($content));
         }
     //foreach allowed shortcode provided, build the necessary regex to
 temporarily change [shortcode] to {shortcode} and then back
         foreach ($shortcodes as $shortcode)
         {
                 $allowed_matches[] = '/\[('.$shortcode.'[^\]]*)\]/';
                 $restore_allowed_matches[] =
 '/\{('.$shortcode.'[^\}]*)\}/';
         }
     //change safe shortcodes from [shortcode] to {shortcode}
         $safe_content = preg_replace($allowed_matches, '{$1}', $content);
     //strip remaining [shortcodes]
         $clean_content = strip_shortcodes($safe_content);
     //change {shortcodes} back to [shortcodes] and return result of
 do_shortcode() on that content
         $trimmed_content = preg_replace($restore_allowed_matches, '[$1]',
 $clean_content);
         return do_shortcode($trimmed_content);
 }
 }}}

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


More information about the wp-trac mailing list