[wp-trac] [WordPress Trac] #13078: Make wp_register_style and wp_enqueue_style consistent

WordPress Trac noreply at wordpress.org
Sat Mar 30 23:11:44 UTC 2013


#13078: Make wp_register_style and wp_enqueue_style consistent
-------------------------------------+-----------------------------
 Reporter:  koopersmith              |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  General                  |     Version:  3.0
 Severity:  minor                    |  Resolution:
 Keywords:  has-patch needs-refresh  |
-------------------------------------+-----------------------------

Comment (by kitchin):

 Replying to [comment:2 hakre]:
 > Yeah both functions should be propagated for theme and plugin authors. A
 user does not expect a difference in handling the URLs here, so this
 should be streamlined.

 The URL parameter is treated the same. The '?' parameter at issue is in
 the handle, not the URL. The intended use (documented anywhere?) seems to
 be:

 {{{
 wp_register_style( 'mystyle', plugins_url( 'style.css', __FILE__) );
 wp_enqueue_style( 'mystyle?foo=bar');
 }}}

 or
 {{{
 wp_enqueue_style( 'mystyle?foo=bar', plugins_url( 'style.css', __FILE__)
 );
 }}}

 Either way produces:
 {{{
 <link rel='stylesheet' id='mystyle'
  href='http://domain.tld/wp-
 content/plugins/my/style.css?ver=3.5.1&#038;foo=bar'
  type='text/css' media='all' />
 }}}

 However this does not work at all:
 {{{
 wp_register_style( 'mystyle?foo=bar', plugins_url( 'style.css', __FILE__)
 );
 wp_enqueue_style( 'mystyle?foo=bar');
 }}}

 Changing this behavior would break any themes or styles using it.

 Also when reading the code, be sure to note the difference between
 "$handle" and "$_handle". Function wp_enqueue_style() only strips the '?'
 argument so it can register the plain handle. Then it enqueues the handle
 with the argument. That's why the first two snippets above are equivalent.

 Finally, if anyone rewrites the code, it would be great to comment the two
 different uses of '''$args''' in `class.wp-dependencies.php`. The one
 we're talking about is part of the `WP_Dependencies` class. But the
 `$args` in the `_WP_Dependency` class is unrelated and serves as a
 placeholder for the fifth parameter in the functions used by authors,
 `wp_register_*()` and `wp_enqueue_*()`. So it's '''$media''' in `functions
 .wp-styles.php` and '''$in_footer''' in `functions.wp-scripts.php`.

 I'll add a note to Codex about the first two snippets above.

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


More information about the wp-trac mailing list