[wp-trac] Re: [WordPress Trac] #9870: Fix for WP_Dependencies::dequeue

WordPress Trac wp-trac at lists.automattic.com
Tue May 19 11:37:50 GMT 2009


#9870: Fix for WP_Dependencies::dequeue
--------------------------+-------------------------------------------------
 Reporter:  chrisbliss18  |       Owner:  chrisbliss18    
     Type:  defect (bug)  |      Status:  new             
 Priority:  normal        |   Milestone:  2.8             
Component:  JavaScript    |     Version:  2.8             
 Severity:  normal        |    Keywords:  has-patch tested
--------------------------+-------------------------------------------------

Comment(by chrisbliss18):

 Frankly, I don't understand that either; however, I'm matching the
 functionality found in the WP_Dependencies::enqueue method. The existing
 code for the two methods is as follows:

 {{{
     function enqueue( $handles ) {
         foreach ( (array) $handles as $handle ) {
             $handle = explode('?', $handle);
             if ( !in_array($handle[0], $this->queue) &&
 isset($this->registered[$handle[0]]) ) {
                 $this->queue[] = $handle[0];
                 if ( isset($handle[1]) )
                     $this->args[$handle[0]] = $handle[1];
             }
         }
     }

     function dequeue( $handles ) {
         foreach ( (array) $handles as $handle )
             unset( $this->queue[$handle] );
     }
 }}}

 As you can see, the enqueue method does a number of things that the
 dequeue method does not attempt to duplicate. In addition, the fact that
 it attempts to improperly remove an item from the array using a value as
 an index causes a complete failure of the method. Thus, it is extremely
 easy to create unexpected results. The code I used to test the
 functionality of the class is as follows:

 {{{
     $dep = new WP_Dependencies;

     $dep->add( 'test', '' );
     $dep->add( 'another', '' );
     $dep->add( 'this', '' );
     $dep->add( 'that', '' );
     $dep->add( 'the_other', '' );
     $dep->add( 'handle', '' );
     $dep->add( 'not_used', '' );
     $dep->add( 'data_handle', '' );

     $dep->enqueue( array( 'test', 'another' ) );
     $dep->enqueue( array( 'this', 'that' ) );
     $dep->enqueue( 'the_other' );
     $dep->enqueue( 'handle?data' );
     $dep->enqueue( 'data_handle?dh_data' );

     $dep->dequeue( array( 'test', 'another', 'handle?data' ) );

     print_r( $dep->queue );
     print_r( $dep->args );
 }}}

 When run, you can see that the dequeue call fails to remove anything from
 the queue and args.

 While I may not understand all the use cases, it does not change the fact
 that the dequeue method as it stands now fails to remove what is added by
 the queue method. My patch resolves the issues and allows the method to
 properly remove handles and args added by the queue method.

 FYI: Not that it matters to me, but it may somewhere internally. This
 isn't a JavaScript component. The class is used as a parent class for both
 WP_Styles and WP_Scripts.

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


More information about the wp-trac mailing list