You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 17, 2022. It is now read-only.
- Smart default values - You can now typehint the return value on your event's `default()` method. If the typehint does not match with the filtered value the default() method will get called with the original and filtered value. ([Commit](https://github.com/calvinalkan/better-wordpress-hooks/commit/8d564babae2f448f607ceb1aea73edae487d2bfc#diff-6f76b222b1d42b154e0ca5f9cca9c766227cb56a75f7bff262e412a5f85a9378R182))
15
+
- It's now possible to resolve mapped events from the service container ([Commit](https://github.com/calvinalkan/better-wordpress-hooks/commit/3b48f0b7951c28e1f1c8ff7ce94ce7e842e89ef6)). See example under [Bootstrapping](https://github.com/calvinalkan/better-wordpress-hooks/blob/master/README.md#bootstrapping).
16
+
17
+
### Changed
18
+
- It's now possible to dispatch event objects without having to pass an empty array for events without constructor arguments.([Commit](https://github.com/calvinalkan/better-wordpress-hooks/commit/6165c5b3b0c810839fa02c43ebec87e78d91c6f1))
19
+
- the default() method now receives the original payload, and the filtered value. ([Commit](https://github.com/calvinalkan/better-wordpress-hooks/commit/8d564babae2f448f607ceb1aea73edae487d2bfc))
20
+
21
+
### Fixed
22
+
23
+
- Some docblocks mistakes that led to false positive errors in code editors.
24
+
- Logic error. Removed code that attempted to map several custom events to a WordPress Hook.
25
+
This should have never been possible. Only one custom event should be mapped to a WordPress Hook.
@@ -698,6 +696,43 @@ Default return values are evaluated in the following order:
698
696
699
697
3. If #1 and #2 are not possible the first parameter passed into the ````dispatch()```` method will be returned.
700
698
699
+
#### Return values for invalid callback
700
+
701
+
A common pain point when offering filters is that users don't respect the API of your filter and return incompatible values.
702
+
If you are using object events you can typehint the expected return value on the `default()` method.
703
+
If the value returned from a filter is either:
704
+
1. The same as the original payload or
705
+
2. NOT of the same type as the typehint on `default()` the filtered value will be discarded, and your event`s default method will be called with both the payload, and the filtered value, giving you the option to fix things.
706
+
707
+
**Example**
708
+
````php
709
+
class MyEvent extends AcmeEvents {
710
+
711
+
public function default($original_payload, $filtered_value) :array {
712
+
713
+
return [$filtered_value];
714
+
715
+
}
716
+
717
+
}
718
+
````
719
+
Assuming a third party developer would hook into your filter like this:
0 commit comments