Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/22/2015 08:17:12 PM (9 years ago)
Author:
djpaul
Message:

BP-Legacy: add a new param to locate_asset_in_stack to allow the enqueued asset's $handleto be explicitly set.

Originally designed to load a template pack's main CSS and JS files in a theme compatibility manner, in r8686 locate_asset_in_stack was used to enqueue a JS file for password strength meters (registration and settings screens). This worked, but the $handle, dynamically constructed and passed to wp_enqueue_script, for the password strength JS file is likely to be the exact same handle as that used for a template pack's main JS file. This has the consequence of making the file(s) registered first unenqueue-able.

The new parameter introduced by this change allows us to explicitly set the name of an enqueued asset's handle, which avoids this problem. Technically the script handle for the password strength meter JS was never intentionally set, so we avoid most of the concerns of a backwards compatibility break, and now allow developers to actually unenqueue a template pack's CSS and JS.

Fixes #5972.
See also #5797.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r9497 r9524  
    265265
    266266            // Locate the Register Page JS file
    267             $asset = $this->locate_asset_in_stack( "password-verify{$min}.js", 'js' );
     267            $asset = $this->locate_asset_in_stack( "password-verify{$min}.js", 'js', 'bp-legacy-password-verify' );
    268268
    269269            $dependencies = array_merge( bp_core_get_js_dependencies(), array(
     
    300300     * @since BuddyPress (1.8)
    301301     * @access private
    302      * @param string $file A filename like buddypress.cs
    303      * @param string $type css|js
     302     * @param string $file A filename like buddypress.css
     303     * @param string $type Optional. Either "js" or "css" (the default).
     304     * @param string $script_handle Optional. If set, used as the script name in `wp_enqueue_script`.
    304305     * @return array An array of data for the wp_enqueue_* function:
    305306     *   'handle' (eg 'bp-child-css') and a 'location' (the URI of the
    306307     *   asset)
    307308     */
    308     private function locate_asset_in_stack( $file, $type = 'css' ) {
     309    private function locate_asset_in_stack( $file, $type = 'css', $script_handle = '' ) {
    309310        // Child, parent, theme compat
    310311        $locations = array();
     
    344345                if ( file_exists( trailingslashit( $location['dir'] ) . trailingslashit( $subdir ) . $location['file'] ) ) {
    345346                    $retval['location'] = trailingslashit( $location['uri'] ) . trailingslashit( $subdir ) . $location['file'];
    346                     $retval['handle']   = $location_type . '-' . $type;
     347                    $retval['handle']   = ( $script_handle ) ? $script_handle : "{$location_type}-{$type}";
     348
    347349                    break 2;
    348350                }
Note: See TracChangeset for help on using the changeset viewer.