Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do you load buddypress scripts on custom wordpress templates?

  • @teslavolt

    Participant

    I have a custom template page that I’ve added specific bp-activities and its comments (pulled some code from the activity-loop).

    In Buddypress v11.4.3, everything was working fine, the activity displays and comments + reply functionality works – click on a reply and the .ac-form moves to selected reply/comment and it nests it as expected.

    Since Buddypress 12, replies no longer work. I think it’s because the Buddypress scripts no longer load on NON-buddypress pages. I tried enqueueing Buddypress scripts myself using a function:

     function load_bp_activity_scripts(){
        wp_register_script("bpnouveau", "/wp-content/plugins/buddypress/bp-templates/bp-nouveau/js/buddypress-nouveau.js");
        wp_register_script("bpactivity", "/wp-content/plugins/buddypress/bp-templates/bp-nouveau/js/buddypress-activity.js");
        wp_register_script("bpactivitypost", "/wp-content/plugins/buddypress/bp-templates/bp-nouveau/js/buddypress-activity-post-form.min.js");
        wp_register_script("bpmentions", "/wp-content/plugins/buddypress/bp-activity/js/mentions.min.js");
        wp_register_script("corecaret", "/wp-content/plugins/buddypress/bp-core/js/vendor/jquery.caret.min.js");
        wp_register_script("coreatwho", "/wp-content/plugins/buddypress/bp-core/js/vendor/jquery.atwho.min.js");
        wp_enqueue_script("bpnouveau");
        wp_enqueue_script("bpactivity");
        wp_enqueue_script("bpactivitypost");
        wp_enqueue_script("bpmentions");
        wp_enqueue_script("corecaret");
        wp_enqueue_script("coreatwho");
    }
    add_action("load_bp_activity", "load_bp_activity_scripts");
    function load_bp_activity(){ do_action( 'load_bp_activity' );}

    but just loading the scripts is not enough. When I replaced buddypress-activity.js with my own version to debug, I noticed that BP_Nouveau returns as ‘undefined’ and so none of the script functionality would run.

    I’m probably missing something really simple but how can I load Buddypress core scripts or styles in my own custom wordpress template?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @teslavolt

    Participant

    I checked on the my buddypress’s /activity stream page and I noticed in the page source, there’s something defined:

    
    <script id="bp-nouveau-js-extra">
    var BP_Nouveau = {"ajaxurl":"https:\/\/mysite.com\/wp-admin\/admin-ajax.php","confirm":"Are you sure?","show_x_comments":"Show all %d comments","unsaved_changes":"Your profile has unsaved changes. If you leave the page, the changes will be lost.","object_nav_parent":"#buddypress","objects":{"0":"activity","1":"members","3":"blogs","4":"xprofile","5":"friends","7":"settings","8":"notifications"},"nonces":{"activity":"945da9770f","members":"3c2b470980","blogs":"0a006184ba","xprofile":"56da19c4b1","friends":"a437ee2b51","settings":"ce8e7d03fe","notifications":"ac5a574aa8"},"newest":"Load Newest","pulse":"15","activity":{"params":{"user_id":20,"object":"user","backcompat":{"before_post_form":false,"post_form_options":false},"post_nonce":"a7c93b3f4e","avatar_url":"\/\/www.gravatar.com\/avatar\/c4568b23422db4e779e93c73130989dd?s=50&r=g&d=mm","avatar_width":50,"avatar_height":50,"user_domain":"https:\/\/mysite.com\/members\/pen\/","avatar_alt":"Profile photo of Pen","objects":{"profile":{"text":"Post in: Profile","autocomplete_placeholder":"","priority":5}}},"strings":{"whatsnewPlaceholder":"What's new, Pen?","whatsnewLabel":"Post what's new","whatsnewpostinLabel":"Post in","postUpdateButton":"Post Update","cancelButton":"Cancel"}}};
    

    I can’t find what creates this script / variable.

    @emaralive

    Moderator

    The answer to your initial post can be found at the following:

    BP Template Pack JavaScript and Style assets are now only loaded into the community area of your site

    As to your 2nd post, most likely via the following:

    wp_localize_script( 'bp-nouveau', 'BP_Nouveau', apply_filters( 'bp_core_get_js_strings', $params ) );

    @teslavolt

    Participant

    Thanks! adding the bp_enqueue_assets_in_bp_pages_only allowed buddypress scripts to be loaded outside of the buddypress generated pages.

    For some reason, the ‘bp_has_activities’ in my activity loop no longer respects the array I pass in. Instead of just displaying the one bp_activity_id and the comments, it’s pulling all activities.

    
     $prj_activity_args = array("include"=>$bp_activity_id);
    <div class="activity" data-bp-single="<?php echo $bp_activity_id; ?>">
    if ( bp_has_activities( $prj_activity_args ) ) : ?>
            <?php if ( empty( $_POST['page'] ) || 1 === (int) $_POST['page'] ) :?>
                <div id="activity-stream" class="activity-list item-list bp-list" data-bp-list="activity">
                    <ul class="activity-list item-list bp-list">
            <?php endif; ?>
            <?php
                while ( bp_activities() ) :
                    bp_the_activity();
            ?>
                <?php bp_get_template_part( 'activity/entry' );?>
            <?php endwhile; ?>
            <?php if ( empty( $_POST['page'] ) || 1 === (int) $_POST['page'] ) : ?>
                    </ul> <!-- .activity-list -->
                </div> <!-- #activity-stream -->
            <?php endif; ?>
        <?php else : ?>
            <?php bp_nouveau_user_feedback( 'activity-loop-none' ); ?>
        <?php endif; ?>
        <?php// bp_nouveau_after_loop(); ?>
        </div> <!--#comments-->
    </div> <!--#buddypress-->
    
    

    @teslavolt

    Participant

    Found this to try and override the has_activities via a filter https://codex.buddypress.org/developer/using-bp_parse_args-to-filter-buddypress-template-loops/

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar