Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/11/2010 10:41:14 PM (14 years ago)
Author:
djpaul
Message:

Load javascript in the init action. Fixes #2942

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-themes/bp-default/functions.php

    r3496 r3527  
    8181    //End of changeable header section
    8282
    83     // Load the javascript for the theme
     83    // Register buttons for the relevant component templates
     84    // Friends button
     85    if ( bp_is_active( 'friends' ) )
     86        add_action( 'bp_member_header_actions',    'bp_add_friend_button' );
     87
     88    // Activity button
     89    if ( bp_is_active( 'activity' ) )
     90        add_action( 'bp_member_header_actions',    'bp_send_public_message_button' );
     91
     92    // Messages button
     93    if ( bp_is_active( 'messages' ) )
     94        add_action( 'bp_member_header_actions',    'bp_send_private_message_button' );
     95
     96    // Group buttons
     97    if ( bp_is_active( 'groups' ) ) {
     98        add_action( 'bp_group_header_actions',     'bp_group_join_button' );
     99        add_action( 'bp_group_header_actions',     'bp_group_new_topic_button' );
     100        add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
     101    }
     102
     103    // Blog button
     104    if ( bp_is_active( 'blogs' ) )
     105        add_action( 'bp_directory_blogs_actions',  'bp_blogs_visit_blog_button' );
     106}
     107add_action( 'after_setup_theme', 'bp_dtheme_setup' );
     108endif;
     109
     110/**
     111 * Enqueue theme javascript safely after the 'init' action, per WordPress Codex.
     112 *
     113 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     114 * @see http://codex.wordpress.org/Function_Reference/wp_enqueue_script
     115 * @since 1.3
     116 */
     117function bp_dtheme_enqueue_scripts() {
     118    global $bp;
     119
    84120    wp_enqueue_script( 'dtheme-ajax-js', get_template_directory_uri() . '/_inc/global.js', array( 'jquery' ) );
    85121
     
    99135
    100136    wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params );
    101 
    102     // Register buttons for the relevant component templates
    103     // Friends button
    104     if ( bp_is_active( 'friends' ) )
    105         add_action( 'bp_member_header_actions',    'bp_add_friend_button' );
    106 
    107     // Activity button
    108     if ( bp_is_active( 'activity' ) )
    109         add_action( 'bp_member_header_actions',    'bp_send_public_message_button' );
    110 
    111     // Messages button
    112     if ( bp_is_active( 'messages' ) )
    113         add_action( 'bp_member_header_actions',    'bp_send_private_message_button' );
    114 
    115     // Group buttons
    116     if ( bp_is_active( 'groups' ) ) {
    117         add_action( 'bp_group_header_actions',     'bp_group_join_button' );
    118         add_action( 'bp_group_header_actions',     'bp_group_new_topic_button' );
    119         add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
    120     }
    121 
    122     // Blog button
    123     if ( bp_is_active( 'blogs' ) )
    124         add_action( 'bp_directory_blogs_actions',  'bp_blogs_visit_blog_button' );
    125 }
    126 add_action( 'after_setup_theme', 'bp_dtheme_setup' );
    127 endif;
     137}
     138add_action( 'wp_enqueue_scripts', 'bp_dtheme_enqueue_scripts' );
    128139
    129140if ( !function_exists( 'bp_dtheme_admin_header_style' ) ) :
Note: See TracChangeset for help on using the changeset viewer.