BP 11: bp_has_profile() Now Accepts an Array of Profile Group IDs

In the upcoming BuddyPress 11.0 release, we’ve added some developer frosting 🧁 to make working with profile groups more straightforward. The template function bp_has_profile() and its underlying function BP_XProfile_Group::get() now accept a single profile group ID or an array of profile group IDs, making it easier to loop through your members’ profile data.

For example, the following code:

<?php
$profile_args = array(
    'user_id'          => 1,
    'profile_group_id' => array( 1, 2 ),
);

if ( bp_has_profile( $profile_args ) ) :
    while ( bp_profile_groups() ) : bp_the_profile_group();
        if ( bp_profile_group_has_fields() ) : ?>
            <h2><?php bp_the_profile_group_name(); ?></h2>

            <table class="profile-fields">

                <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

                    <?php if ( bp_field_has_data() ) : ?>

                        <tr<?php bp_field_css_class(); ?>>

                            <td class="label"><?php bp_the_profile_field_name(); ?></td>

                            <td class="data"><?php bp_the_profile_field_value(); ?></td>

                        </tr>

                    <?php endif; ?>

                <?php endwhile; ?>

            </table>

        <?php
        endif;
    endwhile;
endif;

produces the following output:

Without having to add an extra profile group loop! You can test this new functionality out in the most recent BuddyPress v11 release beta.

BP 11: Fetch Activities for or Excluding a Group of Users

Coming soon in 11.0, we’ve made it possible to fetch activity items for a specific group of users, or to fetch activity items excluding a group of users. The new parameters are user_id__in and user_id__not_in, following a familiar WordPress naming convention.

<?php 
// A couple of users are so cool I would like to do something
// featuring just their updates 
$activity_args = array(
	'user_id__in' => array( 3, 7 ),
);

$activity_items = bp_activity_get( $activity_args );

foreach ( $activity_items as $activity ) {
	// Do soemthing interesting with these activities...
}
?>

Or to find activities, excluding updates from users with the ID 3 and 7, simply use the other new option.

<?php 
// I'd like to block updates from a couple of annoying users. 😮
$activity_args = array(
	'user_id__not_in' => array( 3, 7 ),
);

$activity_items = bp_activity_get( $activity_args );

foreach ( $activity_items as $activity ) {
	// Do soemthing interesting with these activities...
}
?>

This change is simple but powerful! For instance, you could create custom interest activity streams, or build a mute feature to let your members take a break from other, too-chatty users!. 🙂

.webp support is arriving in BuddyPress 11.0.0

If your site is using a WordPress version that is upper than 5.8, you’ll see BuddyPress 11.0.0 is bringing support for .webp image files when you need to upload a profile image or a cover image.

You can read the full story of this change from this ticket #8643. You’ll discover we do read reviews of the plugin and we do listen to users suggestions and needs 🤗

#11-0-0, #cover-image, #profile-image

BuddyPress will soon only load its JavaScript and Style assets into the community area of your site

For quite a long time, BuddyPress users has regularly requested us to improve how the plugin’s JavaScript and Style assets are loaded into the front-end of their WordPress site.

How come BP JavaScript and CSS files are loaded everywhere on my site?

A BuddyPress user probably wishing it wasn’t the case!

That’s the question I’m often asked about BuddyPress, maybe you wondered about it too 😁. We’re not sure there’s a specific reason explaining this fact. As it was necessary before we introduced the BP Theme Compat API (see the 1.7 version announcement post) to use a BuddyPress compatible theme like the one we bundle by default (BP Default), I think we kept the way this theme was loading these assets into the first Template Pack (BP Legacy) we added to BuddyPress.

Let’s only load what we need when we need it… progressively!

In version 11.0.0 we are taking a first step towards restricting JavaScript and Style assets loading to BuddyPress pages only (or what I also call the community area of your WordPress site). To take no risks with potential BP plugins or themes needing these assets, we will carry on loading these everywhere on your site in 11.0.0. BUT if you want to avoid this, you now have an easy way to only have these loaded into the community area of your site. Simply put a bp-custom.php file in place (or use the one you already put in place) and add the following code into it:

add_filter( 'bp_enqueue_assets_in_bp_pages_only', '__return_true' );

If using the above filter, you notice something is going wrong with your website due to the use of a specific BP plugin or theme, report it here and we’ll then have another development cycle to fix things before we completely restrict these assets to BuddyPress generated pages in a second step & in version 12.0.0.

To read more about the story of this change, you can have a look at this ticket #8679.

#11-0-0, #developer-documentation

The way BuddyPress loads deprecated code will change in version 11.0.0

During a development cycle, we can deprecate functions the plugin is not using anymore. In this case we are moving this deprecated code into a specific file named according to the BuddyPress version when it was deprecated. For example, the bp_insert_site_hook() function was deprecated during the 10.0.0 development cycle and was moved into the /bp-core/deprecated/10.0.php file.

Before 11.0.0, deprecated code was never loaded when BuddyPress was first installed or if the BP_IGNORE_DEPRECATED constant was set to true. Deprecated code was only loaded if this constant wasn’t set to true and if BuddyPress has been regularly upgraded since version 2.7. This means if you first installed version 8.0.0 of BuddyPress, deprecated code was never loaded. This was wrong considering BuddyPress Plugin and Theme authors who were not able to be informed by setting their WP_DEBUG constant to true that a function was deprecated (and eventually replaced by another one) and no more available.

Starting in 11.0.0, we’re improving our deprecated code loading strategy

First we are keeping these 2 behaviors from previous versions:

  • Deprecated code is never loaded when you first install BuddyPress.
  • Deprecated code is not loaded when you define the BP_IGNORE_DEPRECATED constant to true.

Second we’re introducing a new constant to force all deprecated code to be loaded: BP_LOAD_DEPRECATED. Defining this constant to true can help you to identify deprecated functions one of your plugins or you active theme is still using although it shouldn’t.

Third, when BuddyPress has been upgraded, we are loading the code that was deprecated during the 2 previous versions.

To read more about the story of this change, you can have a look at this ticket #8687.

At the time I’m writing these lines, we’ve started the 11.0.0 beta testing period. As this change is pretty important, we strongly advise BuddyPress Plugin and Theme authors to test BuddyPress 11.0.0 pre-versions.

#11-0-0, #developer-documentation

PHP tests suite improvements

Following WordPress’s effort about improving PHPUnit compatibility, we’ve just improved our PHP tests suite so that it now uses latest PHPUnit version (9.5.21). We’ve also updated our GitHub action so that it now includes PHP 8.1 tests to our PHP testing matrix. This action will now also run each time a Pull Request is submitted to our GitHub repository.

Next time you’ll check out our development version, don’t forget to run the composer install command and if you want to use latest PHPUnit version without installing it globally, you can run composer run test to launch BuddyPress PHPUnit tests.

For more information about it, please read this ticket #8649. Many thanks to @espellcaste & @rafiahmedd for their contributions to this great improvements 😍.

#11-0-0, #phpunit

WordPress required version update

Hi !

Please note that BuddyPress 11.0.0 will require WordPress >= 5.7.

To learn more about this change: https://buddypress.trac.wordpress.org/ticket/8709

To learn more about how we decide to bump our WordPress required version: https://codex.buddypress.org/getting-started/wordpress-version-compatibility/

#11-0-0, #wp-requirements