get_fieldset_select('user', 'id', ''); foreach ($users as $user) { // Check if private page exists. if ($page = $DB->get_record('my_pages', array('userid' => $user, 'private' => true))) { $context = context_user::instance($user); // Find all blocks for private page. if ($blocks = $DB->get_records('block_instances', array('parentcontextid' => $context->id, 'pagetypepattern' => 'my-index'))) { foreach ($blocks as $block) { // Remove all blocks. if (is_null($block->subpagepattern) || $block->subpagepattern == $page->id) { blocks_delete_instance($block); } } } // Remove the private page itself. if ($DB->delete_records('my_pages', array('userid' => $user, 'private' => true))) { echo "Private page for userid {$user} deleted! \n"; } } } ?>