/** * Resets the registry. * * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog * is used in a multisite install. Here is a list of things that are NOT reset. * * - $_dependency_map * - $_class_abbreviations * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. * - $REQ: Still on the same request so no need to change. * - $CAP: There is no site specific state in the EE_Capability class. * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session * can be active in a single request. Resetting could resolve in "headers already sent" errors. * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the * switch or on the restore. * - $modules * - $shortcodes * - $widgets * * @param boolean $hard whether to reset data in the database too, or just refresh * the Registry to its state at the beginning of the request * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN * currently reinstantiate the singletons at the moment) * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client * code instead can just change the model context to a different blog id if necessary * * @return EE_Registry */ public static function reset($hard = false, $reinstantiate = true, $reset_models = true) { $instance = self::instance(); EEH_Activation::reset(); //properties that get reset $instance->_cache_on = true; $instance->CFG = EE_Config::reset($hard, $reinstantiate); $instance->CART = null; $instance->MRM = null; $instance->LIB = new stdClass(); //messages reset EED_Messages::reset(); if ($reset_models) { foreach (array_keys($instance->non_abstract_db_models) as $model_name) { $instance->reset_model($model_name); } } return $instance; }
/** * Ensure getting default creator works as expected * @since 4.6.0 */ public function test_get_default_creator_id() { //clear out any previous users that may be lurking in teh system foreach (get_users() as $wp_user) { wp_delete_user($wp_user->ID); } //set some users; and just make it interesting by having the first user NOT be an admin $non_admin_users = $this->factory->user->create_many(2); $users = $this->factory->user->create_many(2); //make users administrators. foreach ($users as $user_id) { $user = $this->factory->user->get_object_by_id($user_id); //verify $this->assertInstanceOf('WP_User', $user); //add role $user->add_role('administrator'); } //get all users so we know who is the first one that we should be expecting. $expected_id = reset($users); $this->assertEquals(EEH_Activation::get_default_creator_id(), $expected_id); /** * ok now let's verify EEH_Activation::reset() properly clears the cache * on EEH_Activation. This is important for subsequent unit tests (because * EEH_Activation::reset() is called beween unit tests), but also when an admin * resets their EE database, or when anyone wants to reset that cache) * clear out any previous users that may be lurking in teh system */ EEH_Activation::reset(); foreach (get_users() as $wp_user) { wp_delete_user($wp_user->ID); } //set some users; and just make it interesting by having the first user NOT be an admin $this->factory->user->create_many(2); $users_created_after_reset = $this->factory->user->create_many(2); //make users administrators. foreach ($users_created_after_reset as $user_id) { $user = $this->factory->user->get_object_by_id($user_id); //verify $this->assertInstanceOf('WP_User', $user); //add role $user->add_role('administrator'); } //get all users so we know who is the first one that we should be expecting. $new_expected_id = reset($users_created_after_reset); $this->assertEquals(EEH_Activation::get_default_creator_id(), $new_expected_id); }
/** * Resets the registry and everything in it (eventually, getting it to properly * reset absolutely everything will probably be tricky. right now it just resets * the config, data migration manager, and the models) * @param boolean $hard whether to reset data in the database too, or just refresh * the Registry to its state at the bginning of the request * @param boolean $reinstantiate whether to create new instances of EE_REgistry's singletons too, * or just reset without reinstantiating (handy to set to FALSE if you're not sure if you CAN * currently reinstantiate the singletons at the moment) * @return EE_Registry */ public static function reset($hard = FALSE, $reinstantiate = TRUE) { $instance = self::instance(); $instance->load_helper('Activation'); EEH_Activation::reset(); $instance->CFG = EE_Config::reset($hard, $reinstantiate); $instance->LIB->EE_Data_Migration_Manager = EE_Data_Migration_Manager::reset(); $instance->LIB = new stdClass(); foreach (array_keys($instance->non_abstract_db_models) as $model_name) { $instance->reset_model($model_name); } return $instance; }