Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2023 10:46:04 AM (3 years ago)
Author:
imath
Message:

Prevent potential errors in bp_get_the_profile_field_ids()

In case this function is used inside an xProfile group loop having no attached profile fields, instead of generating a notice error, let's simply return an empty string.

Props shawfactor

Fixes #8789
Closes ​https://github.com/buddypress/buddypress/pull/140

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r13503 r13528  
    474474
    475475                $field_ids = array();
    476                 foreach ( $profile_template->groups as $group ) {
    477                         if ( ! empty( $group->fields ) ) {
    478                                 $field_ids = array_merge( $field_ids, wp_list_pluck( $group->fields, 'id' ) );
     476
     477                if ( isset( $profile_template->groups ) && $profile_template->groups ) {
     478                        foreach ( $profile_template->groups as $group ) {
     479                                if ( ! empty( $group->fields ) ) {
     480                                        $field_ids = array_merge( $field_ids, wp_list_pluck( $group->fields, 'id' ) );
     481                                }
    479482                        }
    480                 }
    481 
    482                 $field_ids = implode( ',', wp_parse_id_list( $field_ids ) );
     483
     484                        $field_ids = implode( ',', wp_parse_id_list( $field_ids ) );
     485                } else {
     486                        $field_ids = '';
     487                }
    483488
    484489                /**
Note: See TracChangeset for help on using the changeset viewer.