I’m trying to create a custom button and link it to a file within the plugin. How do I get this link pointing to the path of my choice?

Download Donors should point to the link I choose

I’ve tried the following but it does now work.

function _pfund_register_types() {
    $pfund_options = get_option( 'pfund_options' );
    $template_def = array(
        'public' => true,
        'query_var' => 'pfund_cause',
        'rewrite' => array(
            'slug' => $pfund_options['cause_slug'],
            'with_front' => false,
        ),
        'hierarchical' => true,
        'label' => __( 'Causes', 'pfund' ),
        'labels' => array(
            'name' => __( 'Causes', 'pfund' ),
            'singular_name' => __( 'Cause', 'pfund' ),
            'add_new' => __( 'Add New Cause', 'pfund' ),
            'add_new_item' => __( 'Add New Cause', 'pfund' ),
            'edit_item' => __( 'Edit Cause', 'pfund' ),
            'view_item' => __( 'View Cause', 'pfund' ),
            'search_items' => __( 'Search Causes', 'pfund' ),
            'not_found' => __( 'No Causes Found', 'pfund' ),
            'not_found_in_trash' => __( 'No Causes Found In Trash', 'pfund' ),
        )
    );
    register_post_type( 'pfund_cause', $template_def );
    register_post_type( 'pfund_cause_list' );

    $campaign_def = array(
        'public' => true,
        'query_var' => 'pfund_campaign',
        'rewrite' => array(
            'slug' => $pfund_options['campaign_slug'],
            'with_front' => false
        ),
        'hierarchical' => true,
        'label' => __( 'Campaigns', 'pfund' ),
        'labels' => array(
            'name' => __( 'Campaigns', 'pfund' ),
            'singular_name' => __( 'Campaign', 'pfund' ),
            'add_new' => __( 'Add New Campaign', 'pfund' ),
            'add_new_item' => __( 'Add New Campaign', 'pfund' ),
            'download_donors' => __( 'Download Donors', 'pfund' ),
            'all_items' => __( 'Download Donors', 'pfund' ),
            'edit_item' => __( 'Edit Campaign', 'pfund' ),
            'view_item' => __( 'View Campaign', 'pfund' ),
            'search_items' => __( 'Search Campaigns', 'pfund' ),
            'not_found' => __( 'No Campaigns Found', 'pfund' ),
            'not_found_in_trash' => __( 'No Campaigns Found In Trash', 'pfund' ),
        ),
        'supports' => array(
            'title'
        ),
        'capabilities' => array(
            'edit_post' => 'edit_campaign'
        ),
        'map_meta_cap' => true
    );
    register_post_type( 'pfund_campaign', $campaign_def );
    register_post_type( 'pfund_campaign_list' );
}

Notice the lines

'download_donors' => __( 'Download Donors', 'pfund' ),
        'all_items' => __( 'Download Donors', 'pfund' ),

The ‘download_donors’ label doesn’t work. I have to use the ‘all_items’. Not sure why this is but when I try to add the filter it doesn’t get overwritten. Instead the link points to wp-admin/edit.php?post_type=pfund_campaign

add_filter('post_row_actions','all_items', 10, 2);

function download_donors($actions, $post){
    //check for your post type
    if ($post->post_type =="pfund_campaign"){
        //remove the default edit
        unset($actions['edit']);
        //set new action
        $actions['download_donors'] = '<a href="http://www.google.com">Download Donors</a>';
    }
    return $actions;
}

1 Answer
1

I’m not sure where you got the idea that adding ‘download_donors’ would do what you want, it’s nowhere in the documentation, and it IS being bundled with the labels, it’s just that nothing makes use of it.

The labels when registering a post type are not definitions for admin menus.

If you want to add an admin menu, you need to do it the same way everything else does it via add_submenu_page

http://codex.wordpress.org/Function_Reference/add_submenu_page

e.g.:

add_action('admin_menu', 'register_my_custom_submenu_page');

function register_my_custom_submenu_page() {
    add_submenu_page( 'tools.php', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' ); 
}

function my_custom_submenu_page_callback() {
    echo '<h3>My Custom Submenu Page</h3>';

}

Making the menu link to an external page won’t be possible, you’d need to intercept the page load and do a wp_redirect call, but that would be misleading to the user and bad UI. You’d be better off putting a big download button on your new subpage

Leave a Reply

Your email address will not be published. Required fields are marked *