0

I'm using wp-crowdfunding plugin, and i try to add something in a filter. Here the original filter :

 apply_filters('wpneo_crowdfunding_frontend_dashboard_menus', array(
        'dashboard' =>
            array(
                'tab'             => 'dashboard',
                'tab_name'        => __('Dashboard','wp-crowdfunding'),
                'load_form_file'  => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/dashboard.php'
            ),
        'profile' =>
            array(
                'tab'             => 'account',
                'tab_name'        => __('Profile','wp-crowdfunding'),
                'load_form_file'  => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/profile.php'
            ),
        'contact' =>
            array(
                'tab'             => 'account',
                'tab_name'        => __('Contact','wp-crowdfunding'),
                'load_form_file'  => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/contact.php'
            ),
        'campaign' =>
            array(
                'tab'             => 'campaign',
                'tab_name'        => __('My Campaigns','wp-crowdfunding'),
                'load_form_file'  => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/campaign.php'
            ),
        'backed_campaigns' =>
            array(
                'tab'             => 'campaign',
                'tab_name'        => __('Backed Campaigns','wp-crowdfunding'),
                'load_form_file'  => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/investment.php'
            ),
        'pledges_received' =>
            array(
                'tab'            => 'campaign',
                'tab_name'       => __('Pledges Received','wp-crowdfunding'),
                'load_form_file' => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/order.php'
            ),
        'bookmark' =>
            array(
                'tab'            => 'campaign',
                'tab_name'       => __('Bookmarks','wp-crowdfunding'),
                'load_form_file' => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/bookmark.php'
            ),
        'password' =>
            array(
                'tab'            => 'account',
                'tab_name'       => __('Password','wp-crowdfunding'),
                'load_form_file' => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/password.php'
            ),
        'rewards' =>
            array(
                'tab'            => 'account',
                'tab_name'       => __('Rewards','wp-crowdfunding'),
                'load_form_file' => WPNEO_CROWDFUNDING_DIR_PATH.'includes/woocommerce/dashboard/rewards.php'
            ),
    ));

What i need is just add this to the end with i suppose the same filter :

    'myform' =>
        array(
            'tab'            => 'myform',
            'tab_name'       => __('My Form'),
            'load_form_file' => MY_THEME_DIR.'wpcrowdfunding/dashboard/myform.php'
        ),

Is it possible ?

2

1 Answer 1

1

that's exactly what the filter is here for! apply_filters is a hook that allows you to modify the array that is passed there as a second argument. Try this:

function example_additional_wpneo_menus( $menus ) {

    // check the type just in case
    if ( ! is_array( $menus ) ) {
        return $menus;
    }

    $menus['myform'] = [
        'tab'            => 'myform',
        // here the second arg is a name of your theme/plugin textdomain, used for translations only
        'tab_name'       => __('My Form','your_textodomain'),
        // MY_THEME_DIR doesn't seem to be a wordpress constant, try this if you want to get current theme directory
        // https://developer.wordpress.org/reference/functions/get_template_directory/
        'load_form_file' => get_template_directory() . '/wpcrowdfunding/dashboard/myform.php'
    ];

    return $menus;
}

// now you hook that into the filter
add_filter( 'wpneo_crowdfunding_frontend_dashboard_menus', 'example_additional_wpneo_menus', 10, 1 );
3
  • Ok i think i misunderstanded filters, i thought they was replacing things only. Thanks you a lot for all these explanations ! I didn't tested it yet but one more thing, i don't get it about $menus var, it didn't get called in the add_filter function so how this var can not be empty ? sry i'm a nooby in wordpress dev !! ^^'
    – Quentin
    Commented Jul 25, 2018 at 10:10
  • no worries! The $menus variable contains the same value that is used as a second argument in apply_filters(). You can call it however you want, it's just used to pass original values into your custom function that hooks into the filter. Filter and action hooks might be confusing at the beggining but are very important in WordPress, you might wanna do some additional reading to make sure you understand how it works :) Commented Jul 25, 2018 at 12:40
  • AHhh Ok ! i understand now ! You're right i need some more read and practise to get used to that ^^ Thanks a lot man, have a great day :)
    – Quentin
    Commented Jul 25, 2018 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.