I want to save the output of do_action in a variable to use it later. How could I save these output?
do_action( string $hook_name, mixed $arg ) Calls the callback functions that have been added to an action hook.
Action Hooks are a very useful tool in WordPress and they are used to perform functions (actions) in specific places of a theme or plugin. Many themes and plugins, such as Total, use action hooks as an easy way for users to modify the output of the project or to add their own custom code.
use ob_start() and ob_get_contents() and ob_end_clean() see example #1 on the following page in the PHP manual http://php.net/manual/en/function.ob-get-contents.php
It looks scary the first time, but it works well. Just make sure to always use ob_end_clean() for every time you use ob_start()
ob_start(); // start capturing output.
do_action('any_action_you_want');
$save_output_here = ob_get_contents(); // the actions output will now be stored in the variable as a string!
ob_end_clean(); // never forget this or you will keep capturing output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With