Version 3.1.0 of WordPress Libs is now available and ready for general use. This version focused on improving the Actions
functionality as well as various enhancements and bug fixes.
Introduce add_looping_action
on Actions
class
WordPress supports short circuiting various methods using filters to allow handling the process in an external way. Sometimes you need to call the original API to run your external process.
Complications arise when the short circuit is part of original API as you end up in an endless loop. A common case for this would be special handling of metadata. This is where the add_looping_action
and its partner method add_looping_filter
come in. These methods automatically handle the register, unregister, and re-register process to prevent infinite loops.
Remove $accepted_args
Requirement From Actions
Class
The filters system supports a 4th argument to specify how many arguments will be passed to the callback’s parameters. Omitting this argument will only pass the first argument to the callback.
Failure to specify a large enough number of accepted arguments will prevent your callbacks parameters from populating, but specifying too large a number has virtually no side effects. For this reason, all methods in the Actions
class no longer have an acccepted_args
parameter and will automatically pass the first 10 arguments to callbacks.
Fix Versions Sorting
PHP8 changed the way version_compare
functions when an operator is used for sorting. version_compare
will return bool
instead of int
when using an operator. It’s best to sort using the returned int
instead of using an operator in PHP8. For this reason we have updated the Versions
class to no longer use an operator and therefore fix a bug with PHP8.
Simplify Cache Posts Group Handling
Instead of using our own cache constant for specifying we want a group’s cache to be flushed when a post is updated then translating it back to posts
, we removed the middleman. Now the constant’s value is posts
and will continue to function the same way without the extra logic.
Introduce Initial_Data::is_retrieving
method
Sometimes you need to adjust the REST responses specifically when doing the initial render of the data to wp_localize_script
. Instead of cluttering up the template by adding a filter directly to it, you now have a method to use directly in the filter’s callback. The method will return true
if currently rendering initial data.
Support Setting Object
Properties Within Mutator_Trait
Previously you were able to retrieve any property from the retrieved object using the magic __get
method. Now there is a partner __set
magic method for setting any of the objects properties as well.
Both the __get
and __set
methods now support retrieving and setting properties on the objects data
property as well.
Introduce Styles::crossorigin_javascript
Method
Like the previously existing defer_javascript
and async_javascript
this method adds a simple way to add a “crossorigin” attribute to script tags. If no value is passed it will add a crossorigin
flag to the tag, otherwise the crossorigin
will be set to the provided value.
Misc
- Prevent
sanitization_cb
from doubling within the meta repo. - Properly store encryption ‘iterations’ for maintainability.
- Fixed
Comment_Trait
@property types. - Improved PHPStan validations.