Container Setup
do_action( 'vikupdater_container_setup', Container $container )
Fires the action after completing the set up of the container used to dispatch the classes.
Description
The Container is a global class used to collect and construct the resources needed by VikUpdater, such as the cache engine and the API requestors.
This action is useful to override the default classes provided by the system. It is possible to overwrite a default class by invoking the $container->get()
method, which must receive the class identifier (string) and the provider used for the instantiation (callable).
Here are listed all the default classes used by the system:
- vikupdater.pluginapi - The API transporter used to download the manifest and the package of the plugins. Must be an instance of
UpdateInterface
. - vikupdater.themeapi - The API transporter used to download the manifest and the package of the themes. Must be an instance of
UpdateInterface
. - vikupdater.cache.engine - The engine used to cache the performed API requests. Must be an instance of
CacheInterface
. - vikupdater.keywallet - The wallet used to collect all the registered license keys. Must be an instance of
Keywallet
. - vikupdater.messages - An helper class used to enqueue and display the system messages. Must be an instance of
MessagesQueue
. - vikupdater.updates.observer - The observer used to support the subscription of the plugins and themes. Must be an instance of
UpdatesObserver
.
Parameters
- $container
-
(Container) The container instance.
Example
The example below explains how to decrease the expiration of the cache to 5 minutes.
function vikupdater_cache_no_longer_than_5_minutes( $container ) {
// overwrite the default caching system provided by VikUpdater
$container->set( 'vikupdater.cache.engine', function( array $options = [] ) {
// do not cache for more than 5 minutes
$options['expiration'] = min( 5, $options['expiration'] ?? 5 );
// cache within a WordPress transient for no more than 5 minutes
return new \VikWP\VikUpdater\WordPress\Cache\TransientCache( $options );
} );
}
add_action( 'vikupdater_container_setup', 'vikupdater_cache_no_longer_than_5_minutes' );
The example below explains how to completely disable the cache instead. This means that, at every page load, WordPress will make a request to the update server for each subscribed plugin/theme. Using the snippet below might show up the presence of a new update instantly, but the pages loading might extremely slow down.
function vikupdater_cache_engine_turned_off( $container ) {
// overwrite the default caching system provided by VikUpdater
$container->set( 'vikupdater.cache.engine', function( array $options = [] ) {
// The static engine temporarily caches the resources within the PHP memory.
// The cache will be automatically cleared at every page loading.
return new \VikWP\VikUpdater\WordPress\Cache\StaticCache;
} );
}
add_action( 'vikupdater_container_setup', 'vikupdater_cache_engine_turned_off' );
Changelog
Version | Description |
---|---|
2.0 | Introduced. |