[wp-trac] [WordPress Trac] #24770: Function "do_items" calls "do_item" with an unexpected parameter

WordPress Trac noreply at wordpress.org
Tue Jul 16 20:56:14 UTC 2013


#24770: Function "do_items" calls "do_item" with an unexpected parameter
---------------------------------------------------+----------------------
 Reporter:  riccardo.raneri                        |       Owner:
     Type:  defect (bug)                           |      Status:  closed
 Priority:  normal                                 |   Milestone:
Component:  General                                |     Version:  2.8
 Severity:  normal                                 |  Resolution:  invalid
 Keywords:  needs-patch 2nd-opinion needs-testing  |
---------------------------------------------------+----------------------

Comment (by riccardo.raneri):

 Replying to [comment:2 azaozz]:
 > This is simple class inheritance. The `do_item()` method in
 [http://core.trac.wordpress.org/browser/trunk/wp-includes/class.wp-
 dependencies.php#L59 class.wp-dependencies.php] is a placeholder meant to
 be overwritten when extending the class. When handling scripts
 [http://core.trac.wordpress.org/browser/trunk/wp-includes/class.wp-
 scripts.php#L19 WP_Dependencies is extended with WP_Scripts]. So
 `$this->do_item()` executes the `do_item()` method of
 [http://core.trac.wordpress.org/browser/trunk/wp-includes/class.wp-
 scripts.php#L77 WP_Scripts] that expects the second argument. (The
 WP_Dependencies::do_item() is still used in WP_Scripts but note how it's
 called with `parent::do_item($handle)`.)
 >
 > Not sure what exactly you're trying to do but enqueueing `'jquery-ui-
 core'` works as expected. It outputs jquery.js, jquery-migrate.js (in 3.6
 only), and jquery.ui.core.min.js. However jQuery UI core by itself
 wouldn't do anything, it's a common component/requirement for the other UI
 components. For example if you want to use UI accordion, you'll need to
 also add UI core and widget.
 >
 > In WordPress this is handled by wp_enqueue_script(). To use accordion
 you only need to enqueue `'jquery-ui-accordion'`. All other scripts that
 accordion depends on will be added automatically.


 Hi, thank you so much for your answer.

 I didn't know about WP_Scripts inheritance of WP_Dependencies, now I see
 that $group is supported by the do_item() in WP_Scripts.
 Anyway, it still doesn't work as expected:

 {{{
                 if ( 0 === $group && $this->groups[$handle] > 0 ) {
                         $this->in_footer[] = $handle;
                         return false;
                 }
 }}}

 This piece of code (line 81-84 in class.wp-scripts.php) makes do_item()
 return false, so the two scripts that I'm trying to add to the queue
 aren't added to the HTML page. My theme is a child of twentytwelve, with
 these lines in its functions.php:


 {{{
 function my_scripts() {
   wp_enqueue_script( 'jquery-ui-core' );
   wp_enqueue_script( 'jquery-ui-datepicker' );
   wp_enqueue_script( 'jquery-ui-i18n-it',
 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/i18n/jquery.ui
 .datepicker-it.min.js' );

   wp_register_style('jquery-ui',
 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-
 ui.css');
   wp_enqueue_style( 'jquery-ui' );
 }
 add_action( 'wp_enqueue_scripts', 'my_scripts' );
 }}}

 If I remove $group from the parameters in class.wp-dependencies.php, as I
 described in my first message, everything works. As soon as I restore the
 original version, every script and css that I'm trying to enqueue
 disappear.

 Sorry, I admit that I'm not deeply experienced with WP core files to
 understand where the problem is, but this is my experience :)

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


More information about the wp-trac mailing list