Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  bump to 1.12.0
  Introduce new Actions method `add_filter_as_action`
  • Loading branch information
lipemat committed Nov 28, 2018
2 parents 9658673 + 4b58732 commit 31192d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# WordPress Libs
WordPress library which supports a core plugin and theme.

**Version [1.11.2](https://github.com/lipemat/wordpress-lipe-libs/releases/tag/1.11.2)**
**Version [1.12.0](https://github.com/lipemat/wordpress-lipe-libs/releases/tag/1.12.0)**

### Requirements
1. PHP Version 7.1.3+ (Recommended 7.2.0+)
Expand Down
24 changes: 24 additions & 0 deletions src/Util/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
class Actions {
use Singleton;


/**
* Add a filter but always return the original value.
* Useful for cases where we want to treat an
* `apply_filters` as an `do_actions` and call a function
* without actually changing the original value.
*
* @since 1.12.0
*
* @param string $filter
* @param callable $callable
* @param int $priority
* @param int $accepted_args
*
* @return void
*/
public function add_filter_as_action( string $filter, callable $callable, int $priority = 10, int $accepted_args = 1 ) : void {
\add_filter( $filter, function ( ...$args ) use ( $filter, $callable ) {
\call_user_func( $callable, ...$args );

return reset( $args );
}, $priority, $accepted_args );
}

/**
* Add a callable to multiple actions at once
*
Expand Down

0 comments on commit 31192d2

Please sign in to comment.