Download the PHP package pollora/hook without Composer

On this page you can find all versions of the php package pollora/hook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hook

Pollora Hook: WordPress actions and filters with a clean PHP API

Latest version Total downloads Tests

A small, dependency-free PHP layer over WordPress actions and filters. It registers class-based callbacks by hook name, detects how many arguments a callback accepts, and removes hooks reliably, so you stop counting $accepted_args by hand and stop keeping closures around just to unhook them.

Part of Pollora, the Laravel framework for WordPress. In a Pollora project it is already installed: use the #[Action] / #[Filter] attributes or the Pollora\Support\Facades\Action / Filter facades instead. The standalone classes emit a notice when the framework is present.

Installation

Requires PHP 8.3+ and WordPress (the adapters call add_action(), add_filter() and friends).

Quick start

What you get

Class-based callbacks

A static method stays as you pass it, and a class that is not loaded yet is left for WordPress to resolve when the hook fires.

To build those classes through a container, use the adapter directly and give it a CallbackResolverInterface:

Asynchronous actions

Add async() after add() and the handler no longer runs inside the request that fires the hook: it is queued, then run later by Action Scheduler or WP-Cron.

An asynchronous handler changes guarantees. Four rules to keep in mind:

The handler is written as a synchronous one. It receives the hook arguments and, if it declares a parameter of that type, an AsyncContext:

Arguments. Scalars and arrays keep their value. WP_Post, WP_Term, WP_User and WP_Comment travel as a reference and are reloaded, in their state at execution time; if one was deleted in the meantime, the handler is dropped (keepMissing() runs it with null instead). Enums and dates are rebuilt, a JsonSerializable object becomes its array. Any other object is refused.

Capturing values at trigger time. At execution there is no request any more, and the content may have changed. capture() runs in the original request, with the hook arguments, and its values are read back through $context->get(). A handler class's public capture() method is used when capture() is not called. Capture an ID rather than personal data or a secret: values wait in the database.

Options, chained after async():

Method Effect
delay(60) Minimum delay, in seconds or as a DateInterval
when(fn (...) => bool) Queue only when the condition, given the hook arguments, returns true
capture(fn (...) => [...]) Record values at trigger time
unique() Merge identical triggers (same hook, handler and arguments) until the first one runs; unique(for: 3600) sets how long the lock lasts if never released (a day by default)
tries(3) Attempts when the handler throws; backoff([10, 60, 300]) sets the seconds before each retry (the default)
asUser() Run as the user who fired the hook, with that user's capabilities. Without it, there is no current user
via('sync') Driver for this registration
onQueue('integrations') Queue name: the Action Scheduler group
keepMissing() Run with null in place of a deleted object
except('save_post_page') Keep some hooks of the same add() synchronous; also async(except: …)

Drivers. The default, auto, picks Action Scheduler when a plugin bundling it (WooCommerce, for example) is active and initialised, WP-Cron otherwise.

Choose the default with the POLLORA_ASYNC_DRIVER constant in wp-config.php, or the pollora/hook/async_driver filter. More drivers register through Async::extend().

Dependencies. Async::injectParametersUsing($resolver) injects, at execution, the handler parameters typed with a class that does not travel as a hook argument, such as a mailer or an API client. Pollora resolves them from its container.

Closures. With laravel/serializable-closure installed, a closure can be queued. It is serialized and signed with a key derived from the WordPress salts, and the signature is checked before anything is unserialized. Declare it static and let it use IDs rather than objects.

Failures. At execution, the original site and locale are restored, and a handler that fires its own hook does not queue itself again. A handler that throws is retried while it has attempts left; the last failure is reported and announced through the pollora/async/failed action. Each handler queued is announced through pollora/async/dispatched (the payload and the delay), for debugging tools. When an action cannot be queued, WP_DEBUG throws; otherwise the incident goes to the PHP error log (or Async::reportUsing()) and the handler runs in place, so the work always happens.

Testing. Async::fake() records queued handlers instead of queuing them:

Documentation

Hooks in a Pollora project: Actions & filters.

Testing

Contributing

Contributions are welcome: see the contributing guide. Report security issues privately, as described in the security policy.

License

Pollora Hook is open-source software licensed under the RuBee group


All versions of hook with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
pollora/schedule Version ^0.1.2 || ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pollora/hook contains the following files

Loading the files please wait ...