Skip to:
Content

BuddyPress.org

Changeset 8612


Ignore:
Timestamp:
07/15/2014 07:14:28 PM (5 years ago)
Author:
djpaul
Message:

Core: make the filter in bp_core_register_common_scripts() more useful.

Prior to this change, the data passed to the filter was pretty limited, making the filter
not very useful. This change makes the filter provide a full path for the scripts being
registered and allows scripts' dependencies to be set.

Minor codestyle improvements have also been included.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-cssjs.php

    r8559 r8612  
    1111
    1212/**
    13  * Register scripts commonly used by BuddyPress plugins and themes.
     13 * Register scripts commonly used by BuddyPress.
    1414 *
    1515 * @since BuddyPress (2.1.0)
    1616 */
    1717function bp_core_register_common_scripts() {
    18 
    19     // Whether or not to use minified versions
    20     $min  = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
    21 
    22     // Get the version for busting caches
    23     $ver  = bp_get_version();
    24 
    25     // Get the common core JS URL
    26     $url  = buddypress()->plugin_url . 'bp-core/js/';
     18    $ext = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
     19    $url = buddypress()->plugin_url . 'bp-core/js/';
    2720   
    28     // Array of common scripts
    2921    $scripts = apply_filters( 'bp_core_register_common_scripts', array(
    30         'bp-confirm'          => 'confirm',
    31         'bp-widget-members'   => 'widget-members',
    32         'bp-jquery-query'     => 'jquery-query',
    33         'bp-jquery-cookie'    => 'jquery-cookie',
     22        'bp-confirm'        => array( 'file' => "{$url}confirm{$ext}",        'dependencies' => array( 'jquery' ) ),
     23        'bp-widget-members' => array( 'file' => "{$url}widget-members{$ext}", 'dependencies' => array( 'jquery' ) ),
     24        'bp-jquery-query'   => array( 'file' => "{$url}jquery-query{$ext}",   'dependencies' => array( 'jquery' ) ),
     25        'bp-jquery-cookie'  => array( 'file' => "{$url}jquery-cookie{$ext}",  'dependencies' => array( 'jquery' ) ),
    3426    ) );
    3527
    36     // Register scripts commonly used by BuddyPress themes
    37     foreach ( $scripts as $id => $file ) {
    38         wp_register_script( $id, $url . $file . $min, array( 'jquery' ), $ver );
     28    foreach ( $scripts as $id => $script ) {
     29        wp_register_script( $id, $script['file'], $script['dependencies'], bp_get_version() );
    3930    }
    4031}
Note: See TracChangeset for help on using the changeset viewer.