Do not point the URL to admin.php, use admin-post.php instead:
'<a href="' . admin_url( 'admin-post.php?action=print.csv' ) . '">'
In your plugin register a callback for that action:
add_action( 'admin_post_print.csv', 'print_csv' );
function print_csv()
{
if ( ! current_user_can( 'manage_options' ) )
return;
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=example.csv');
header('Pragma: no-cache');
// output the CSV data
}
If you want to make the data available for anonymous users (not logged in), then register the callback again with:
add_action( 'admin_post_nopriv_print.csv', 'print_csv' );
… and remove the capability check from the function.
Related Posts:
- How can I add an image upload field directly to a custom write panel?
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How do i best handle custom plugin page actions?
- How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
- Plugin API for easy admin list table generation, handling & exporting of MySQL tables?
- Completely remove WP_Admin_Bar for specific user roles
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Using a database view = evil incarnate?
- Hook the Keydown Event in the TinyMCE Post Editor
- Is it possible to add an admin page using add_submenu_page() and pass a var in the query string?
- how to use thickbox in admin?
- How do you create a custom edit.php / edit pages page
- Cancel post save
- Add a jQuery function to admin pages
- WP Cron doesn’t save or in post body
- Create a clickable name in WP_List_Table for Plugin Admin
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- Check if I am in the Admin Panel (wp-admin)?
- How to add custom content under plugin row in WordPress admin plugin list?
- How to put placeholder text in the main post input area?
- How to load the plugin only when logged in?
- Creating a Wordpess Plugin that writes data to a csv file. The data doesn’t show in the csv file?
- How to redirect to action on custom page within admin section
- WP AJAX is not working, always returns 0
- Add notification bubble notice in navigation using transients
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- add a class when login
- Add a panel to edit post
- Where should I put “run once” plugin pages?
- Using the default wordpress uploader inside plugin
- Modify users.php page to create page/post on button clicked
- Issue plugin commands in admin settings page
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Replacing Scripts in Admin Load_Scripts
- Programmatically modify an admin page UI of a WordPress site from my WordPress plugin
- Problems with: manage_${post_type}_posts_columns
- Global State During an Admin Post
- Render content after post title in wp-admin
- On cliking add new post redirect user to a custom page first
- Failed to Open Stream: Permission Denied While Writing to an XML File in a WordPress Plugin
- What should happen when a WordPress Plugin is activated across the network (Network Wide Activation)
- Prevent third party plugin’s admin page access based on user type
- How to add WordPress Admin “Insert Link” UI (searches through existing posts for URL) and functionality into a custom plugin?
- Is it possible to restrict all admin pages except theme customisation and storefront using plugin?
- How do I update a field of a meta box?
- Admin – Handle data before creating or updating a post, page or custom post
- wp_filesystem put_contents issue with owner/group
- Password field is empty when using wp_signon();
- How can I replace content in the WP Admin area before an admin page is rendered?
- Using ReactJS in the WordPress admin for plugin development
- You do not have sufficient permissions to access this page on a submenu
- How to load library scripts in admin from plugins in noConflict wrapper?
- Show error message after exception handled
- Issue with contextual help overwriting existing content
- Enqueue script globally
- How do I add a favicon that only shows during viewing of my plugin’s admin panel?
- How do I link to a php file in my plugin directory?
- WordPress Admin Login Custom Logo
- How to create custom settings page for custom plugin
- 400 Bad Request, in wordpress theme development, wp_ajax
- How to import the css in the plugin admin area?
- Creating multiple wp_editer() text fields in for loop — the text/visual switch only works for first editor
- Displaying “One Time” Notification in Plugins
- Wp-admin Custom User Management
- Admin Subpages without Menu entry
- Filter for admin (back end) ‘reply to’ comment
- Data not insert and update through ajax and jQuery in admin page?
- Catching Form Submission in WordPress Admin Panel
- Redirect in WordPress plugin
- Page is loading after submit before the file is processed
- How to add custom view links to wp-admin/post.php?
- Is it possible to load the css just on my plugin admin page?
- AJAX button with success callback. (Titan Framework)
- Import user data using CSV
- Disable Auto-Expanding Menu in WordPress Admin Menus
- How do I force a download in the admin area?
- Plugin Development – Get Admin Url (Including cases where wp-admin is not used)
- Remove Permalink Meta Box not working?
- How do I duplicate a single post, with all its properties, and save it as a different post?
- insufficient permissions; coding an action for plugin governed by custom capability
- check_admin_referer()
- WordPress admin panel not working
- I cant add is_admin control to plugin
- 400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true
- Change Label of custom post type
- Stop unauthorised file access
- How to enable or disable check boxes in custom post type
- Redirect with message after admin_post.php
- Same header/footer in Admin, across all network sites in multisite
- Plugin dev: How to multiply instances of a plugin in the same metabox?
- Issue with iframe in TinyMCE
- Forcing ALL plugin Admin menus into a separate menu
- admin page passing $_POST variables to itself
- WordPress multiple user roles accessing on their information on one site?
- modify buddpress adminbar only in admin pages
- How to change the headline title for an admin page in a plugin?
- How do I display and edit other posts within the ‘Edit Post’ area of Wp-Admin Dashboard
- How to prepend a header section to all pages related to my WordPress Plugin
- Load specific CSS file
- Customize Message