Make WordPress Core

Opened 9 years ago

Closed 5 months ago

#40134 closed defect (bug) (worksforme)

Invalid data for scripts in footer

Reported by: sebastianpisula's profile sebastian.pisula Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Script Loader Keywords:
Focuses: Cc:

Description

During register scripts via wp_register_script in last param I can choose that script should be in footer. In function we see:

<?php
if ( $in_footer ) {
     $wp_scripts->add_data( $handle, 'group', 1 );
}

so footer scripts I should check use this code:

<?php
$wp_scripts = wp_scripts();

if ( $wp_scripts->get_data( $handle, 'group' ) ) {
        echo 'in footer';
} else {
        echo 'in header';
}

I check for this: admin-bar and I have false -> in header. We can see this code:

<?php
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );

This should be in footer (and is, but I can't check it via my script).

I think that this is bug.

Attachments (1)

40134.patch (640 bytes) - added by sebastian.pisula 9 years ago.

Download all attachments as: .zip

Change History (2)

#1 @jonsurrell
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I don't understand the issue being described. It seems like the issue is about the basic functionality of ::add_data() and ::get_data(). I don't see any problems with their behavior.

I adapted the example and tested:

<?php
wp_enqueue_script(
        '_',
        plugins_url( 'x.js', __FILE__ ),
        array(),
        '0.0.0',
        true
);

global $wp_scripts;
$wp_scripts->add_data( '_', 'group', 1 );
add_action(
        'wp_footer',
        function () {
                global $wp_scripts;
                echo '<plaintext>';
                var_dump( $wp_scripts->get_data( '_', 'group' ) );
        }
);

int(1) is printed as expected.

Note: See TracTickets for help on using tickets.