Question

In a plugin I have this code..

            $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() ),
        ));

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.

Suppose I wanted to change the value of

__( 'My Account', 'jigoshop' ) => get_permalink( jigoshop_get_page_id('myaccount') )

to

__( 'Logout', 'jigoshop' ) =>'test'

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' );

Thank you

Was it helpful?

Solution

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 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top