zoukankan      html  css  js  c++  java
  • 黄聪:走进wordpress do_action函数

    再看do_action函数。位于plugin.php352行。我把源码放在西街口这里,略去了其它辅助处理的语句。

    如下:

    function do_action($tag, $arg = '') {     ++$wp_actions[$tag]; //计数器加1,did_action中用到       do {         foreach ( (array) current($wp_filter[$tag]) as $the_ )             if ( !is_null($the_['function']) )                 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));       } while ( next($wp_filter[$tag]) !== false );       array_pop($wp_current_filter); }

    可以看出,主要是个do-while循环,其中涉及了两个标准函数:

    current 是php标准函数,返回数组当前元素。

    call_user_func_array是php标准函数,执行用户自定义的函数,第一个参数是函数名,第二个是自定义函数的参数数组。

    这样do_action函数一目了然,首先计数器加1,然后执行循环。

    循环体中,执行名字保存于全局数组$wp_filter的自定义函数。

    关于$wp_filter,$wp_current_filter是什么,马上讲到。

  • 相关阅读:
    eclipse 中配置maven环境
    洛谷 P5015 标题统计
    洛谷 P1228 【地毯填补问题】
    洛谷 P3328 【[SDOI2015]音质检测】
    OJ 大整数减法
    NOIP 2018数据点
    NOIP 2017 图书管理员
    NOIP 成绩
    洛谷P1001 A+B Problem
    洛谷P1000 超级玛丽游戏
  • 原文地址:https://www.cnblogs.com/huangcong/p/4741050.html
Copyright © 2011-2022 走看看