[wp-trac] [WordPress Trac] #40292: Use echo file_get_contents() instead of require_once() to pull in SVG file contents in Twenty Seventeen

WordPress Trac noreply at wordpress.org
Wed Mar 29 04:16:13 UTC 2017


#40292: Use echo file_get_contents() instead of require_once() to pull in SVG file
contents in Twenty Seventeen
---------------------------+-----------------------------
 Reporter:  kellenmace     |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Bundled Theme  |    Version:  4.7.3
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Using require_once() to pull in the contents of SVG files can result in
 the PHP parser throwing a
 {{{
 PHP Parse error: syntax error, unexpected version (T_STRING)
 }}}
 error if any of the SVG files begin with
 {{{
 <?xml version="1.0" encoding="UTF-8"?>
 }}}
 The proposed solution is to use echo file_get_contents() instead.

 A few recommendations for using that method are here:
 https://css-tricks.com/using-svg/#article-header-id-7
 http://sheelahb.com/blog/how-to-get-php-to-play-nicely-with-svg-files/

 It could be argued that using require_once() is fine in Twenty Seventeen,
 since we know that none of the SVGs in /assets/images/svg-icons.svg
 contain the problematic <?xml … ?> tag. However, there are of course many
 developers who fork Twenty Seventeen, or copy its code into their own
 themes, so it seems wise to me to pull in SVG file contents using a method
 that won't throw errors in the event that <?xml … ?> tags are present in
 any SVG files.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40292>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list