What does apply_filters(…) actually do in WordPress?

后端 未结 4 1472
谎友^
谎友^ 2020-12-12 12:13

I\'m trying to understand some of the function in WordPress, but I can\'t get my head around what apply_filters(...) actually does.

Is someone able to clear this up

4条回答
  •  北海茫月
    2020-12-12 13:08

    late answer

    Short explanation

    apply_filters() interacts with the global $wp_filters array. Basically it just checks the array if the current filter (or hook) has an action(/callback function) attached and then calls it.

    Long explanation

    When you attach a callback/action to a filter or hook, then you just add the callback name to global filters array. When then, in code (for e.g. a template, core or plugin file) a call to do_action() or apply_filters() happens, then WordPress searched through the array and calls the callback. The only thing more special with filters than with hooks is, that it returns the value (for further handling) instead of just firing the callback. So summed up: Hooks are to insert data, while filters are to modify data.

提交回复
热议问题