使“all”数组获取$wp_Filter中的过滤器的源代码在哪里?

时间:2017-01-03 作者:Mohamed Omar

正如问题所述,在$wp\\u过滤器中生成“all”数组抓取过滤器的源代码在哪里?

我已经搜索了整个核心关于这个的任何定义,我只是可以找到如果( isset($wp_filter[\'all\']) ) .. 所以如果有isset 它必须设置在某个地方。。。使所有数组抓取过滤器的源代码在哪里设置条件是什么if ( isset($wp_filter[\'all\']) ) 至true

1 个回复
最合适的回答,由SO网友:prosti 整理而成

我认为您对该功能感兴趣:_wp_call_all_hook.

File: wp-includes/plugin.php
816: /**
817:  * Call the \'all\' hook, which will process the functions hooked into it.
818:  *
819:  * The \'all\' hook passes all of the arguments or parameters that were used for
820:  * the hook, which this function was called for.
821:  *
822:  * This function is used internally for apply_filters(), do_action(), and
823:  * do_action_ref_array() and is not meant to be used from outside those
824:  * functions. This function does not check for the existence of the all hook, so
825:  * it will fail unless the all hook exists prior to this function call.
826:  *
827:  * @since 2.5.0
828:  * @access private
829:  *
830:  * @global array $wp_filter  Stores all of the filters
831:  *
832:  * @param array $args The collected parameters from the hook that was called.
833:  */
834: function _wp_call_all_hook($args) {
835:    global $wp_filter;
836: 
837:    $wp_filter[\'all\']->do_all_hook( $args );
838: }
请记住添加过滤器时,会将其写入$wp_filter 全球的动作也是如此。

File: wp-includes/plugin.php
106: function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
107:    global $wp_filter;
108:    if ( ! isset( $wp_filter[ $tag ] ) ) {
109:        $wp_filter[ $tag ] = new WP_Hook();
110:    }
111:    $wp_filter[ $tag ]->add_filter( $tag, $function_to_add, $priority, $accepted_args );
112:    return true;
113: }
事实上,操作和过滤器非常接近:看看这个:

File: wp-includes/plugin.php
398: function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
399:    return add_filter($tag, $function_to_add, $priority, $accepted_args);
400: }

相关推荐

插件放置在/wp-content/plugins内的文件夹中时不保存值

我得到了WordPRess插件的以下代码,它在每个页面/后期编辑屏幕上添加了两个自定义输入。然后将这些值保存并输出到前端页面的标题中。如果代码位于内部,则可以正常工作。php文件并直接放入“wp内容/插件”。然而,如果我把它放在插件(如“wp-content/plugins/myplugin”)中自己的文件夹中,那么在通过编辑屏幕保存帖子/页面时,输入字段不会保存。此外,它不会向前端页面html标题部分输出任何内容。这似乎是一个被放弃的项目,所以我无法与原始开发人员一起制定解决方案。然而,代码中的某些内容