Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

BuddyPress enqueue question WordPress

  • SOLVED

I created a BuddyPress child theme. I DO NOT want to depend on BuddyPress Template Pack in order to add ajax functionality to the theme.

Apparently I need to call these..


/* Load the default BuddyPress AJAX functions */
if ( !(int)get_option( 'bp_tpack_disable_js' ) ) {
require_once( BP_PLUGIN_DIR . '/bp-themes/bp-default/_inc/ajax.php' );

/* Load the default BuddyPress javascript */
wp_enqueue_script( 'bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array( 'jquery' ) );
}


Here's what I need...

I only want to call these IF the BuddyPress plugin is activated. If it is not, do not call these items.

Also, as you you can see, the code calls for BP_PLUGIN_URL. What would I change that to?

Thanks.


Answers (2)

2011-03-22

Denzel Chia answers:

Hi,

Just wrap your code in a if function exists to check for buddy press function in order to load the above codes, and else load your own theme ajax script.
This is because, buddy press functions will only exists if the buddy press plugin is activated.


if(function_exists('bp_has_groups')){
/* Load the default BuddyPress AJAX functions */

if ( !(int)get_option( 'bp_tpack_disable_js' ) ) {

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



/* Load the default BuddyPress javascript */

wp_enqueue_script( 'bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array( 'jquery' ) );

}
}else{

//register and enqueue your own ajax script from your theme folder.

}



Thanks.
Denzel


Armand Morin comments:

Denzel,

You the man as always. Works perfectly. Thanks.

2011-03-22

yves vu answers:

Please group your code to a function as: "my_plugin_init" and then call in "add_action"
function my_plugin_init() {
/* Load the default BuddyPress AJAX functions */

if ( !(int)get_option( 'bp_tpack_disable_js' ) ) {

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



/* Load the default BuddyPress javascript */

wp_enqueue_script( 'bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array( 'jquery' ) );

}
}
//check whether BuddyPress is active
add_action( 'bp_include', 'my_plugin_init' );

Notes:
Using “function_exists()” will cause you problems if your plugin gets called before the plugin you’re checking for.
Tnks for reading