如何在WordPress中添加过滤器,更改数组 [英] how to add_filter in wordpress, change array

查看:112
本文介绍了如何在WordPress中添加过滤器,更改数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在插件中我有此代码。

            $links = apply_filters( 'jigoshop_widget_logout_user_links' , array(
            __( 'My Account', 'jigoshop' )     => get_permalink( jigoshop_get_page_id('myaccount') ),
            __( 'Change Password', 'jigoshop' )=> get_permalink( jigoshop_get_page_id('change_password') ),
            __( 'Logout', 'jigoshop' )         => wp_logout_url( home_url() ),
        ));

是否可以使用 add_filter 函数更改此数组的值?

Is it possible to use the add_filter function to change the values of this array?

我目前正在尝试学习过滤器,并试图将其用作简单示例。

Im currently trying to learn filters and am trying to use this as a simply example.

我不确定如果可能的话,如何将新信息传递给此数组。

Im not sure how you pass the new information to this array , if thats even possible.

假设我想更改

__('我的帐户','jigoshop')=> get_permalink(jigoshop_get_page_id('myaccount'))

__('Logout','jigoshop')=>'测试'

到目前为止,我有这个。 p>

So far I have this..

function change_links() {
            $links = apply_filters( 'jigoshop_widget_logout_user_links' , array(
            __( 'My Account', 'jigoshop' )     => get_permalink( jigoshop_get_page_id('myaccount') ),
            __( 'Change Password', 'jigoshop' )=> get_permalink( jigoshop_get_page_id('change_password') ),
            __( 'Logout', 'jigoshop' )         =>'test',
        ));
    return $links;
}

 add_filter( 'jigoshop_widget_logout_user_links', 'change_links' );

谢谢

推荐答案

通过传递参数来更改添加过滤器的方式,也无需执行其他 apply_filter

Change the way of adding the filter by passing parameters, also you don't need to do another apply_filter:

function change_links($arr) {
    $arr = array(
            __( 'My Account', 'jigoshop' )     => get_permalink( jigoshop_get_page_id('myaccount') ),
            __( 'Change Password', 'jigoshop' )=> get_permalink( jigoshop_get_page_id('change_password') ),
            __( 'Logout', 'jigoshop' )         =>'test',
        );
    return $arr;
}

 add_filter( 'jigoshop_widget_logout_user_links', 'change_links', 10, 1 );

这篇关于如何在WordPress中添加过滤器,更改数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆