I am about to start my first WordPress project and I have the task of moving customized core code that override the core into separate functions/files (this way it'll be easier to maintain when we upgrade in the future.
I have been doing research and it looks like add_filter
and apply_filter
and do_action
and add_action
seem to be the way to go. I'm still unsure about how they work though. Are those methods what I use to overwrite core methods? I am confused because add_filter
uses the word add
when I feel like it is more on the lines of replace
or overwrite
(unless I am misunderstanding)
I just read the first answer to this (the one about the tacos)
So there were three steps the author used in describing how to use add_filter:
Step 1: a static value for the $taco variable
<?php $taco = 'chicken'; ?>
Step 2:
<?php
$taco = apply_filters( 'get_taco', 'chicken' );
?>
Step 3:
<?php
add_filter( 'get_taco', 'my_special_order' );
function my_special_order( $content ) {
return 'shredded beef';
}
?>
So in this situation is the apply_filter
just creating a dynamic method on the fly and making it return the chicken
string? Or is the assumption here that there is a core WordPress method called get_taco
and that using apply_filter
would help in overriding whatever the original functionality was?
Also, can you only apply_filter
something that you've add_filter
ed? In other words, would apply_filter('get_taco');
not work if I did not define add_filter('get_taco', 'my_special_order');
AND function my_special_order ($content) ...
first?
Do I put these filters in my functions.php file? Sorry for bombarding you with questions, I am coming from Ruby on Rails so I'm completely clueless in WordPress.