[wp-trac] [WordPress Trac] #20870: error notice when $post = NULL with gallery_shortcode

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 7 11:05:47 UTC 2012


#20870: error notice when $post = NULL with gallery_shortcode
--------------------------+-----------------------------
 Reporter:  thomask       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  3.4
 Severity:  trivial       |   Keywords:
--------------------------+-----------------------------
 i have noticed with many relevant plugins and functions it may happen,
 that gallery_shortcode is called when global $post returns NULL. problem
 is, that gallery_shortcode function media.php containts

 {{{
                 'id'         => $post->ID,
 }}}

 (row 798 on 3.4 or 783 on 3.3.2) so when $post is NULL it returns error
 notice

 there is trivial solution - adding (!$post) check just after the $output
 filter (so it could be rewriten by plugin authors) - see last line:


 {{{
 function gallery_shortcode($attr) {
         global $post;

         static $instance = 0;
         $instance++;

         // Allow plugins/themes to override the default gallery template.
         $output = apply_filters('post_gallery', '', $attr);
         if ( $output != '' )
                 return $output;

         if (!$post) return;
 }}}


 (sorry, i do not know how to change it on svn). This bug is even on 3.3.2
 even on latest 3.4

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20870>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list