I am currently designing a plugin which will export some data in admin panel, only when a GET parameter export=data is passed. In normal PHP it will do something like:

 if(isset($_GET['export']) && ($_GET['export']=='data')){
 abc(); //Execute this function on GET request

function abc(){
 //function data

Now I want the same thing to happen in my plugin in admin area, assuming the slug of my plugin is '_my-plugin'. So basically I would like to call the function when this URL is visited: http://myblogaddress.com/wp-admin/admin.php?page=_my-plugin&export=data

Thanks in advance


One of the earlier hooks that is aware of the page (I think) is load-{$slug}:

add_action( 'load-_my-plugin', 'wpse143915_maybe_trigger_export' );
function wpse143915_maybe_trigger_export(){
    if( isset( $_GET['export'] ) && ( $_GET['export'] == 'data' ) ){

If you want to find out what your page slug is, checkout this plug-in by Kaiser: https://github.com/franz-josef-kaiser/current-admin-info

But personally, I wouldn't bother waiting for the (admin) screen to be initalised. Just send them to admin-post.php?action=myprefix-export, and then you know when that url is hit:

add_action( 'admin_post_myprefix-export', 'wpse143915_initiate_export' );
function wpse143915_initiate_export(){
   //Any security / validation checks

   //... export data...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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