1

I'm trying to track down why menu switching by language in the polylang filter is not working correctly.

I'm looking at the function nav_menu_locations which is added as a filter as such:

add_filter('theme_mod_nav_menu_locations', array($this, 'nav_menu_locations'), 20);

and then defined subsequently as:

public function nav_menu_locations($menus) {
    ...
    return $menus;
}

I inserted statements to echo $menus at the start and just before the altered value is returned, and can confirm that the function is being called.

But the curious thing is that searching the entire plug-in code–and then the entire WordPress core–I can find no matching apply_filters for theme_mod_nav_menu_locations, and no direct calls to the function either as far as I can tell. So I can't see where the $menus parameter is being generated.

I thought I understood how filter hooks work, and yet can't see how the function nav_menu_locations is being run, although it clearly is.

It might not help me solve the problems with my menu switching, but I'd at least like to clarify how the filter is being triggered.

2
  • Ok, that's odd because I'm not using Genesis or Woo Commerce. That filter is being added in the polylang plug-in, but, as I say in the question, it is not being applied anywhere.
    – terraling
    Commented Feb 10, 2015 at 17:29
  • It is not off-topic, the filter in question is created by WordPress. See my answer.
    – cybmeta
    Commented Feb 10, 2015 at 17:36

2 Answers 2

2

WordPress creates automatically filters for each theme_mod with this format theme_mod_{name}. The filters are called in get_theme_mod(). In your case, nav_menu_locations is the theme_mod and this filter is created by WordPress:

//$value of the mod is passed to filter callbacks
apply_filters('theme_mod_nav_menu_locations', $value);

For reference:

2

Some of the filters and actions are hybrids of a constant part and a variable part, something like (not a real hook) {$post_type}_save_post can be used in the code and trigger the action/filter for post_save_post and page_save_post depending on your code flow. Therefore it is not always obvious how to find the place which triggers the action in the code, and might take a little guessing.

As for theme_mod specifically, since @cybmeta already have explained there in his answer is no point in repeating here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.