/** * @group cache * @group group_types * @ticket BP5451 * @ticket BP6643 */ public function test_get_query_caches_should_be_busted_by_group_term_removal() { global $wpdb; bp_groups_register_group_type('foo'); $groups = $this->factory->group->create_many(2); bp_groups_set_group_type($groups[0], 'foo'); bp_groups_set_group_type($groups[1], 'foo'); $found1 = BP_Groups_Group::get(array('group_type' => 'foo')); $this->assertEqualSets(array($groups[0], $groups[1]), wp_list_pluck($found1['groups'], 'id')); bp_groups_remove_group_type($groups[1], 'foo'); $found2 = BP_Groups_Group::get(array('group_type' => 'foo')); $this->assertEqualSets(array($groups[0]), wp_list_pluck($found2['groups'], 'id')); }
/** * Process input from the Group Type bulk change select. * * @since 2.7.0 * * @param string $doaction Current $_GET action being performed in admin screen. */ function bp_groups_admin_process_group_type_bulk_changes($doaction) { // Bail if no groups are specified or if this isn't a relevant action. if (empty($_REQUEST['gid']) || empty($_REQUEST['bp_change_type']) && empty($_REQUEST['bp_change_type2']) || empty($_REQUEST['bp_change_group_type'])) { return; } // Bail if nonce check fails. check_admin_referer('bp-bulk-groups-change-type-' . bp_loggedin_user_id(), 'bp-bulk-groups-change-type-nonce'); if (!bp_current_user_can('bp_moderate')) { return; } $new_type = ''; if (!empty($_REQUEST['bp_change_type2'])) { $new_type = sanitize_text_field($_REQUEST['bp_change_type2']); } elseif (!empty($_REQUEST['bp_change_type'])) { $new_type = sanitize_text_field($_REQUEST['bp_change_type']); } // Check that the selected type actually exists. if ('remove_group_type' !== $new_type && null === bp_groups_get_group_type_object($new_type)) { $error = true; } else { // Run through group ids. $error = false; foreach ((array) $_REQUEST['gid'] as $group_id) { $group_id = (int) $group_id; // Get the old group type to check against. $group_type = bp_groups_get_group_type($group_id); if ('remove_group_type' === $new_type) { // Remove the current group type, if there's one to remove. if ($group_type) { $removed = bp_groups_remove_group_type($group_id, $group_type); if (false === $removed || is_wp_error($removed)) { $error = true; } } } else { // Set the new group type. if ($new_type !== $group_type) { $set = bp_groups_set_group_type($group_id, $new_type); if (false === $set || is_wp_error($set)) { $error = true; } } } } } // If there were any errors, show the error message. if ($error) { $redirect = add_query_arg(array('updated' => 'group-type-change-error'), wp_get_referer()); } else { $redirect = add_query_arg(array('updated' => 'group-type-change-success'), wp_get_referer()); } wp_redirect($redirect); exit; }
public function tests_groups_remove_type_should_return_true_on_successful_deletion() { $g = $this->factory->group->create(array('creator_id' => self::$u1)); bp_groups_register_group_type('foo'); bp_groups_register_group_type('bar'); bp_groups_set_group_type($g, 'foo'); bp_groups_set_group_type($g, 'bar', true); $this->assertTrue(bp_groups_remove_group_type($g, 'foo')); $this->assertEquals(array('bar'), bp_groups_get_group_type($g, false)); }