Comment puis-je charger buddypress ajax sans utiliser le template pack plugi n? J'ai eu cela dans functions.php d'un thème compatible non-buddypress.
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' );
Voici comment j’ai utilisé les requêtes/scripts ajax BP par défaut dans un thème BuddyPress personnalisé:
(Gist avec 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');
Ça ne fait rien. J'ai moi-même trouvé une solution rapide, bien que le chargement ne soit pas aussi rapide que l'ajax sur le thème par défaut.
Dans mon functions.php, j'ai ceci:
<?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' )
);
?>