threadi / easy-transients-for-wordpress
Provides a simple wrapper to handle transients in the WordPress-backend.
Package info
github.com/threadi/easy-transients-for-wordpress
pkg:composer/threadi/easy-transients-for-wordpress
Requires
None
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feature/addTests
- dev-feature/checkForCapabilities
- dev-feature/excludeHookFromWcs
- dev-feature/optimizedStyleForWp70
- dev-feature/addMoreMessageTypes
- dev-fix/typos
- dev-fix/missingCheckForDirectRequest
- dev-feature/doNotDismissIfNotSet
- dev-fix/deleteOfTransientDuringActionRun
- dev-feature/addDismissSingleTransientByRequest
- dev-fix/missingParameterForShowDismissed
- dev-feature/addOptionToLoadDismissedTransients
- dev-fix/wrongTransientHeight
- dev-feature/addFilterForTransients
- dev-fix/translationsInTemplates
- dev-feature/setTranslations
- dev-feature/checkForOurObject
- dev-feature/addMarginRightForTextInGrouped
- dev-feature/optimizedStylingWithMultipleButtons
- dev-fixed/missingDefaultValueForGetAllTransients
- dev-feature/addSeparateActionHandling
- dev-fix/missingClassPrefixInSingleView
- dev-feature/addedStylingForHintNotice
- dev-fixed/missingRemovingOfDismissedTransients
- dev-fixed/missingIndexVarInAllTransientsLoop
- dev-feature/ignoreDismissedTransients
- dev-feature/moveFilesAndTemplatesToSrc
- dev-fix/checkForHideOnSettingInTransient
- dev-fixed/groupedStylingNotVisible
- dev-feature/switchToSingleIfOnlyOneTransientIsActive
- dev-feature/hideGroupWrapperIfEmpty
- dev-fix/missingCheckForListInGroupView
- dev-fix/missingClassLoading
This package is auto-updated.
Last update: 2026-11-23 20:55:39 UTC
README
Provides a simple wrapper to handle transients in the WordPress-backend as admin_notices or actions.
Requirements
- PHP 8.2 or newer.
- composer to install this package.
- WordPress-plugin, theme or Code Snippet-plugin to embed them in your project.
Installation
composer require threadi/easy-transients-for-wordpress- Use a tool like Strauss or PHP-Scoper to prefix the namespace
easyTransientsForWordPressin your project (see "Usage in multiple projects"). - Add the configuration (see below) to your WordPress-project (plugin or theme).
Configuration
Configure the library early (e.g. on plugins_loaded) and call init() afterward:
use easyTransientsForWordPress\Transients; $transients_obj = Transients::get_instance(); $transients_obj->set_slug( 'my-plugin' ); $transients_obj->set_capability( 'manage_options' ); $transients_obj->set_path( plugin_dir_path( __FILE__ ) . 'vendor/threadi/easy-transients-for-wordpress/src/' ); $transients_obj->set_url( plugin_dir_url( __FILE__ ) . 'vendor/threadi/easy-transients-for-wordpress/src/' ); $transients_obj->set_vendor_path( plugin_dir_path( __FILE__ ) . 'vendor/' ); // optional. $transients_obj->set_display_method( 'grouped' ); // "single" (default) or "grouped". $transients_obj->set_translations( array( 'hide_message' => __( 'Hide this message for %1$d days.', 'my-plugin' ), 'dismiss' => __( 'Dismiss', 'my-plugin' ), 'dismiss_error' => __( 'The message could not be hidden. Please reload the page and try again.', 'my-plugin' ), ) ); $transients_obj->init();
Usage
Show a notice
$transient_obj = Transients::get_instance()->add(); $transient_obj->set_name( 'my_plugin_hint' ); $transient_obj->set_message( __( 'My message', 'my-plugin' ) ); $transient_obj->set_type( 'success' ); // error, warning, success, hint or info. $transient_obj->set_dismissible_days( 14 ); // 0 = show only once. $transient_obj->save();
Run an action
A transient without message but with an action will be run at the end of the next request (frontend or backend). The action must be a static method.
$transient_obj = Transients::get_instance()->add(); $transient_obj->set_name( 'my_plugin_task' ); $transient_obj->set_action( array( 'MyPlugin\Tasks', 'run_task' ) ); $transient_obj->save();
Hint: transients are not a permanent storage. If an external object cache (e.g. Redis) is used, transients could be removed at any time. Do not use actions for tasks which must be run in any case.
Templates
The templates could be overridden. They will be searched in this order:
- In the active theme:
{theme}/{slug}/vendor/threadi/easy-transients-for-wordpress/templates/{template} - In your project:
{vendor-path}/../templates/vendor/threadi/easy-transients-for-wordpress/templates/{template} - The templates of this library in
src/Templates/.
The resulting path could also be changed with the filter etfw_{slug}_template.
Usage in multiple projects
If more than one plugin uses this library, each of them must prefix the namespace (e.g. with Strauss). Without that, all plugins would share the same object and overwrite the settings of each other.
All projects should use version 1.5.0 or newer, as older versions answer the AJAX-request to dismiss notices also for notices of other projects.
Development
Requirements: PHP 8.0 or newer, Composer, a local MySQL/MariaDB for the tests.
composer install composer test-install # sets up the WordPress test environment, see bin/install-wp-tests.sh composer test # runs PHPUnit composer phpcs # checks the coding standards (phpcbf fixes most of them) composer phpstan # runs PHPStan
GitHub Actions run PHPCS, PHPStan and the tests for each pull request.
Release
- Update the version in
composer.jsonand add an entry inchangelog.md. - Push a tag
build-<version>(e.g.build-1.5.0) or start the workflow "Release" manually. - The workflow checks the version and the code, creates the tag
<version>and a GitHub release with the notes fromchangelog.md.
Changelog
See changelog.md.