Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Buddypress.js not working with custom theme and BP1.7

  • Hi all-

    Upon updating to BP1.7 from the last 1.7-beta, actions that used to be handled by buddypress.js (“Add friend,” “post reply”–all of the AJAX action buttons) aren’t working anymore in my custom theme based on Twenty Twelve. I’ve made the sure the js file is being added via my theme’s functions file:

    //Manually load the BP-default javascript
    function buddypress_js_load(){
      wp_register_script('buddypress', plugins_url( '/buddypress/bp-templates/bp-legacy/js/buddypress.js' , 'buddypress' ), array('jquery'), '1.7' ); 
      wp_enqueue_script('buddypress'); 
    }
    add_action('wp_enqueue_scripts', 'buddypress_js_load');

    Side note: even if I don’t declare add_theme_support( 'buddypress' );, buddypress.js isn’t being included unless I specifically call it. (Which isn’t the behavior I was expecting: http://bpdevel.wordpress.com/2013/02/25/bp-theme-authors-make-sure-your-theme-registers-buddypress-support/)

    What am I missing to make this theme compatible with 1.7?

    Thanks for your help,

    -David

Viewing 10 replies - 1 through 10 (of 10 total)
  • Should have mentioned: Using WP 3.5.1 with BP 1.7. This is on a closed dev site (production site is still running 1.6.x perfectly, so I’m not freaking out or anything.) Thanks again for your help.

    Theme compat changes the way Ajax is handled, you’ll need to call the older bp-default ajax.php file. or are you actually allowing theme compat to run?

    Hi Hugo-

    Thanks for your reply. I’m not doing anything to prevent theme compat from running (as far as I know–I thought that add_theme_support(‘buddypress’) was the flag to stop compat, and I’m not setting that).

    Basically, I’ve provided php and css files via my theme but would like the js bits to continue to be provided by BP.

    I thought I understood how theme compat worked via the 1.7-betas (my theme behaved just like it did under 1.6.x), but it seems to be different with the actual release.

    Is there a document somewhere describing what triggers/short-circuits theme compat, so I can know either how to get BP to provide the theme compat via js, or, alternatively, duplicate the right files from bp-default into my theme to get the functionality back?

    Thanks again for your reply,

    -David

    If you are running under theme compat then you shouldn’t need to call in the js file from legacy, if you are simply modifying template files and styling then files need to live in either /buddypress/ or /community/ with css in theme root; how have you got things configured?

    Hi Hugo-

    Thanks for following up. The theme was built against BP1.6 & 1.7-beta, so the buddypress-related template folders (activity, blogs, groups, etc) were in the root of the theme. This resulted in the theme being rendered correctly, but, with BP1.7, the js support disappeared.

    I’ve moved the bp-related folders into a “buddypress” folder at the root of the theme (as described in your article: https://codex.buddypress.org/developer/theme-development/a-quick-look-at-1-7-theme-compatibility/). Moving the files causes the output to be garbled. For instance, on a single member’s profile page, a div#content is being created inside of the div#content provided in the main template `buddypress.js`, and, while the object-nav (activity, messages, etc) is being rendered, the header and the main content area aren’t being populated. Structurally, it’s like the entire buddypress output is being wrapped in the theme’s page template. But not completely, because the end of the file isn’t being rendered.

    As you can tell, I’m not exactly sure what’s going on. 🙂

    Thanks again for your advice,

    -David

    Hi Hugo-

    I came across this comment on trac that appeared to be in the wrong place but sounded similar to my problem: https://buddypress.trac.wordpress.org/ticket/4869#comment:17

    I’ve found that if I install Boone’s GitHub version of the template pack and only enable the JS file portion of it, it works (if my buddypress templates are back at the root of the theme, not in a buddypress folder).

    Is there a better way? (I’m also concerned that 1.7 is going to unexpectedly break a number of customized themes like mine.) What’s funny about this is that with 1.6 I used the template pack, then deactivated it while working with 1.7-beta, but it appears that I need it again.

    Thanks for your help,

    -David

    Trying to make sense of what your process has been here as you shouldn’t be having issues.
    Going back up two posts if as you say you built originally for template pack or using template pack then when you tried to switch to 1.7 theme compat you should not have tried to move the existing folders/files into the theme compat folder structure, that will not work older bp-default templates and newer legacy ones are not the same new templates do not have head/footer elements.
    I think you need to continue on with BP as a child theme but probably with the add_theme_suport line added and then handle enqueueing / including the styles/js yourself.

    Hi Hugo-

    You just cleared something important up for me: The new file structure is not just a restructuring of where the files are, but also within the files themselves. (And the files in /buddypress/bp-templates/bp-legacy/buddypress/ are the new style. Are these the template files that theme compat uses, too?)

    Yes, I built this theme the old way, where you create a child theme of whatever (I used Twenty Twelve), then copied the templates and css over from bp-default into the child theme, then went to work. It’s not a child theme of bp-default (precisely, but more or less). The BP Template Pack took care of the JS with BP1.6.

    I’ve tried adding theme support and the js file, but as you mentioned earlier, it also needs ajax.php to do the work. (I don’t know how to make that happen.)

    Thanks,

    -David


    modemlooper
    Moderator

    @modemlooper

    your-theme/_inc/ajax.php

    is your style.css still showing bp-default as Template:

    Hi Modemlooper-

    My theme is a child theme of Twenty Twelve, so my style.css declares Template: twentytwelve.

    I followed your suggestion then took it a step farther and included slightly modified version of the js setup functions from the template pack in my `functions.php` file. I’ll post them here in case somebody else has the same problem I’m having:

    `function bp_support_theme_setup() {
    global $bp;

    // Load the default BuddyPress AJAX functions if it isn’t explicitly disabled or if it isn’t already included in a custom theme
    if ( ! function_exists( ‘bp_dtheme_ajax_querystring’ ) )
    require_once( BP_PLUGIN_DIR . ‘/bp-themes/bp-default/_inc/ajax.php’ );

    // Let’s tell BP that we support it!
    add_theme_support( ‘buddypress’ );

    if ( ! is_admin() ) {
    // Register buttons for the relevant component templates
    // Friends button
    if ( bp_is_active( ‘friends’ ) )
    add_action( ‘bp_member_header_actions’, ‘bp_add_friend_button’ );

    // Activity button
    if ( bp_is_active( ‘activity’ ) )
    add_action( ‘bp_member_header_actions’, ‘bp_send_public_message_button’ );

    // 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’ );
    }

    // Blog button
    if ( bp_is_active( ‘blogs’ ) )
    add_action( ‘bp_directory_blogs_actions’, ‘bp_blogs_visit_blog_button’ );
    }
    }
    add_action( ‘after_setup_theme’, ‘bp_support_theme_setup’, 11 );

    /**
    * Enqueues BuddyPress JS and related AJAX functions
    *
    * @since 1.2
    */
    function bp_support_enqueue_scripts() {

    // 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’ )
    );

    // BP 1.5+
    if ( version_compare( BP_VERSION, ‘1.3’, ‘>’ ) ) {
    // Bump this when changes are made to bust cache
    $version = ‘20120412’;

    $params[‘view’] = __( ‘View’, ‘buddypress’ );
    $params[‘mark_as_fav’] = __( ‘Favorite’, ‘buddypress’ );
    $params[‘remove_fav’] = __( ‘Remove Favorite’, ‘buddypress’ );
    }
    // BP 1.2.x
    else {
    $version = ‘20110729’;

    if ( bp_displayed_user_id() )
    $params[‘mention_explain’] = sprintf( __( “%s is a unique identifier for %s that you can type into any message on this site. %s will be sent a notification and a link to your message any time you use it.”, ‘buddypress’ ), ‘@’ . bp_get_displayed_user_username(), bp_get_user_firstname( bp_get_displayed_user_fullname() ), bp_get_user_firstname( bp_get_displayed_user_fullname() ) );
    }

    // 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_support_enqueue_scripts’ );
    `

    Which is identical to installing the template pack only for the JS, I think. Everything’s working as expected, so I think we can consider this problem resolved. Thanks for your attention, Hugo and Modemlooper.

    -David

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Buddypress.js not working with custom theme and BP1.7’ is closed to new replies.
Skip to toolbar