I have a scenario like this , since its a big code, I’m asking this in an easy way:
In a file called One.php
, I have something like this:
add_filter('eshopaddtocheckout','eshop_extras_checkout');
function eshop_extras_checkout($echo){
//blah blah..
}
In a file, Two.php
, I have something like this:
$echo = apply_filters('eshopaddtocheckout',$echo);
My doubts are:
-
I don’t understood how
Two.php
made a connection with theOne.php
file? I didnt even find a line using something likeinclude One.php
inside theTwo.php
file (BUT the functionality is working perfectly between the 2 files) -
what does apply_filters do?
There is no php function
apply_filters
. It must be defined by some additional software you are using; perhaps wordpress? If so, there’s an answer here that may help: What does apply_filters(…) actually do in WordPress?You can register filters with WordPress, passing a name and a function to
add_filter
. These can contain actions you want to perform on some data before it is used.apply_filters
calls these with arguments,$echo
in your example.See the WordPress documentation on filters for more details.
As stated before, there is no PHP function called apply_filters nor do_action. These are WordPress event driven hooks; specifically made for extensions.
For a better understanding, please refer to: https://wpshout.com/apply_filters-do_action/
Hope this helps.