0

I need to add a filter to a specific wordpress function which is defined in a file which is included by a pluggable function theme's functions f

functions.php:

if (!function_exists('nectar_colors_css_output')) {
    function nectar_colors_css_output(){
        include('css/colors.php');
    }
}

colors.php:

<?php 
function nectar_colors() {
    // not relevant what happens here, but I have 
    // to call another function before this one is called!
}
?>

I use a child theme and when I try to filter this function from the child theme's functions.php, nothing happens. This is because pluggable functions of the parent theme will be called after calling the filters from the child theme.

My filter function in the child theme's functions.php is

function filter_function() {
  // some custom actions...
}
add_filter('nectar_colors', 'filter_function');

How can I get this filter working?

jannnik
  • 102
  • 1
  • 13

1 Answers1

0

What exactly are you trying to filter on? You might be misunderstanding the concepts.

Take your example provided. The parent checks if a function exists before creating it. So basically, if you define it in your child's theme, the parent will know it's there and won't create a default one.

#themename-child

function nectar_colors_css_output(){
    error_log("It worked!");
}
George Nemes
  • 196
  • 7
  • That would be a solution, but it's a bit more complicated: The pluggable parent theme function includes another php script, which contains the function I need to filter. I need a solution which calls the parent theme function before the filter of my child is used. I could remove the if `(!function_exists('nectar_colors_css_output')) {` but I don't want to change the parent theme's files! – jannnik Jan 14 '15 at 11:47
  • Sorry for my mistake, I changed the question :) – jannnik Jan 14 '15 at 11:57
  • Sorry for this, but I still can't quite understand what you are trying to do. I understood you can't modify the parent theme code? In that case you can only use "hooks" they provided. Look for `do_action()` or `apply_filter()`. – George Nemes Jan 14 '15 at 12:23
  • Yes, I don't want to modify the parent theme code. The problem is that the hook does not work for functions which are included (defined) after the filter is defined. – jannnik Jan 15 '15 at 19:24
  • Can you please provide the actual code where this happens? It would help a lot. – George Nemes Jan 15 '15 at 19:47
  • I changed the question a bit, now it contains the actual code. I removed the method bodies because they are more than 200 lines long ;) Please try to reconstruct my problem with the actual code and you will see that the filter is not working. – jannnik Jan 30 '15 at 12:23