php 理解动作的概念并在wordpress中过滤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 理解动作的概念并在wordpress中过滤相关的知识,希望对你有一定的参考价值。

##Now understand this code:-
1. First we create a sample array of fruits with two key value pair.
2. Now seconds line shows that to modify this array we create a filter  which we name as `amrt_cust`.
3. Simple by passing the "name" as first param & "variable to modify" on second param.
4. So think it as some variable whose value is required at many points and we want to chnage it at some certain actions, so we need to accomplish this using filters in wordpress.
5. Now when we created a filter, lets use it and modify the data.
6. we going to use `add_filter()` for this, this function takes the name of already created filter as first param and <i>callback</i> function as second.
7. If you see in the defination of callback function we use one argument. Now the logic is, no. of arguments can be used is equal to the no. of variable to change in `apply_filter()` function.
8. So in this callback function what we did, change the value of second key in this array. Now understand this , when we changed the value, it got change globelly. Which means in your one php execuation the chnaged value will get procceded as $array.

Thanks!
$array = array(
    0 => 'orange',
    1 => 'banana'
);

apply_filters('amrt_cust', $array);
function applynow($array) {
    $array[1] = 'grapes';
    print_r($array);
    die;
}

add_filter('amrt_cust', 'applynow');

以上是关于php 理解动作的概念并在wordpress中过滤的主要内容,如果未能解决你的问题,请参考以下文章

WordPress中函数钩子hook的作用及基本用法

PHP Wordpress分类法在管理员中过滤

php 过滤*显示* WordPress中帖子的时间,将其移动到过去/未来。

php 过滤以停止WordPress用文件名中的破折号替换空格。

在我的Wordpress主题的functions.php中添加过滤器的位置?

使用下拉菜单动态过滤 Wordpress 帖子(使用 php 和 ajax)