There are no advantages to calling such a function, because I think that it is mainly used to call the user function (for example, a plug-in), because editing the kernel file is not a good option. here is a dirty example used by wordpress
<?php function myLocation($content){ return str_replace('@', 'world', $content); } function myName($content){ return $content."Tasikmalaya"; } add_filter('the_content', 'myLocation'); add_filter('the_content', 'myName'); ?>
...
<?php /* * core.php * read only */ $content = "hello @ my name is "; $listFunc = array(); // store user function to array (in my_plugin.php) function add_filter($fName, $funct) { $listFunc[$fName]= $funct; } // execute list user defined function function apply_filter($funct, $content) { global $listFunc; if(isset($listFunc)) { foreach($listFunc as $key => $value) { if($key == $funct) { $content = call_user_func($listFunc[$key], $content); } } } return $content; } function the_content() { $content = apply_filter('the_content', $content); echo $content; } ?>
....
<?php require_once("core.php"); require_once("my_plugin.php"); the_content();
Exit
hello world my name is Tasikmalaya
uingtea Jan 27 '16 at 7:46 2016-01-27 07:46
source share