Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I load buddypress ajax without using the template pack plugi n? I had this in a non-buddypress compatible theme's functions.php.

include( BP_PLUGIN_DIR . '/bp-themes/bp-default/_inc/ajax.php' );


function mytheme_enqueue_bp_default_js() {
wp_enqueue_script( 'dtheme-ajax-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array( 'jquery' ), bp_get_version() );

$params = array(
    'my_favs'           => __( 'My Favorites', 'buddypress' ),
    'accepted'          => __( 'Accepted', 'buddypress' ),
    'rejected'          => __( 'Rejected', 'buddypress' ),
    'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
    'show_all'          => __( 'Show all', 'buddypress' ),
    'comments'          => __( 'comments', 'buddypress' ),
    'close'             => __( 'Close', 'buddypress' ),
    'view'              => __( 'View', 'buddypress' ),
    'mark_as_fav'       => __( 'Favorite', 'buddypress' ),
    'remove_fav'        => __( 'Remove Favorite', 'buddypress' )
);
wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_bp_default_js' );
share|improve this question
1  
Show us what you've tried? –  its_me Jul 10 '12 at 8:01
add comment

2 Answers

up vote 2 down vote accepted

This is how I have used the default BP ajax queries/scripts in a custom BuddyPress theme:

(gist with code: https://gist.github.com/3154297 )

function bp_custom_include_ajax() {
  global $bp;
  require_once( BP_PLUGIN_DIR . '/bp-themes/bp-default/_inc/ajax.php' );
    if ( !is_admin() ) {
    // Register buttons for the relevant component templates
    // Messages button
    if ( bp_is_active( 'messages' ) )
      add_action( 'bp_member_header_actions',    'bp_send_private_message_button' );
  }
      // Group buttons
    if ( bp_is_active( 'groups' ) ) {
      add_action( 'bp_group_header_actions',     'bp_group_join_button' );
      add_action( 'bp_group_header_actions',     'bp_group_new_topic_button' );
      add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
    }
}
add_action( 'after_setup_theme', 'bp_custom_include_ajax', 11 );


function bp_custom_enqueue_global_script() {

    // Add words that we need to use in JS to the end of the page so they can be translated and still used.
  $params = array(
    'my_favs'           => __( 'My Favorites', 'buddypress' ),
    'accepted'          => __( 'Accepted', 'buddypress' ),
    'rejected'          => __( 'Rejected', 'buddypress' ),
    'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
    'show_all'          => __( 'Show all', 'buddypress' ),
    'comments'          => __( 'comments', 'buddypress' ),
    'close'             => __( 'Close', 'buddypress' )
  );

  // Bump this when changes are made to bust cache
  $version = '20120712';
  $params['view']     = __( 'View', 'buddypress' );

  // Enqueue the global JS - Ajax will not work without it
  wp_enqueue_script( 'dtheme-ajax-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array( 'jquery' ), $version );

  // Localize the JS strings
  wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params );
}
add_action('wp_enqueue_scripts', 'bp_custom_enqueue_global_script');
share|improve this answer
    
Awesome Rachel! I'm gonna test it in a non-bp theme right now! –  Aliyah Jul 21 '12 at 19:22
add comment

Nevermind. I found a quick solution myself, although it doesn't load as fast as the ajax on the default theme.

In my functions.php, I have this:

<?php
require_once( BP_PLUGIN_DIR . '/bp-themes/bp-default/_inc/ajax.php' );
wp_enqueue_script( 
    'bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js',
    array( 'jquery' ) 
);
?>
share|improve this answer
1  
When one votes down, usually leaves a message indicating the reason. And it simply means something like "the question/answer is not well formulatted/researched/scoped" and you can revert it editing your Q&A. Don't take it personally and please check the FAQ ('cause you don't have the Analytical Badge ;) –  brasofilo Jul 10 '12 at 9:47
    
Lol thanx Brasofilo. –  Aliyah Jul 10 '12 at 10:01
2  
I'm gonna get me an Analytical badge if its the last thing I do! –  Aliyah Jul 10 '12 at 10:02
    
If anyone has a better way, feel free to share it, pwease :)! This does the job but it doesnt load as fast as the default theme's ajax. I wonder what Im missing –  Aliyah Jul 10 '12 at 10:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.