Skip to:
Content

BuddyPress.org

Changeset 12211


Ignore:
Timestamp:
08/31/2018 06:43:30 PM (6 years ago)
Author:
boonebgorges
Message:

Prevent notices on PHP 7.2 when deleting xprofile groups.

Merges [12210] to the 3.0 branch.

Fixes #7916.

Location:
branches/3.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0

  • branches/3.0/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r11808 r12211  
    212212
    213213            // Remove profile data for the groups fields.
    214             for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) {
    215                 BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id );
     214            if ( ! empty( $this->fields ) ) {
     215                for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) {
     216                    BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id );
     217                }
    216218            }
    217219        }
  • branches/3.0/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php

    r11737 r12211  
    1717
    1818        $this->assertEquals( $g, $saved );
     19    }
     20
     21    /**
     22     * @ticket BP7916
     23     */
     24    public function test_delete() {
     25        $g = self::factory()->xprofile_group->create();
     26
     27        $groups    = bp_xprofile_get_groups();
     28        $group_ids = wp_list_pluck( $groups, 'id' );
     29        $this->assertContains( $g, $group_ids );
     30
     31        $group = new BP_XProfile_Group( $g );
     32        $this->assertTrue( $group->delete() );
     33
     34        $groups    = bp_xprofile_get_groups();
     35        $group_ids = wp_list_pluck( $groups, 'id' );
     36        $this->assertNotContains( $g, $group_ids );
    1937    }
    2038
Note: See TracChangeset for help on using the changeset viewer.