我刚刚开始学习Wordpress并浏览标准/默认主题。如果我正确理解了过滤器的想法,那么在我们应用它们之前,我们需要通过add_filter($hook, $callback, $args)
添加回调函数。但是,查看"二十七"主题,我看不到twentyseventeen_starter_content
的声明,然后与:$starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
(文件功能.php)和twentyseventeen_front_page_sections
-$num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
(文件首页.php)一起使用。我错过了什么,如果不设置回调函数,它是如何工作的?
apply_filters
通过add_filter
到同一个钩子/标签来运行附加到它的所有回调。如果没有附加到该钩子/标签的回调,则返回apply_filters
的第二个参数(即过滤的值 beng)。 因此,如果没有add_filter('twentyseventeen_front_page_sections', 'callbackfunc');
,apply_filters( 'twentyseventeen_front_page_sections', 4 );
将返回4。否则,它将在完成所有回调后返回优先级最高的add_filter回调的结果。
优先级在add_filter
中设置为第三个参数。
我不知道这是否是你要找的,但我想这可能会让你更好地理解。