Support » Plugins » Bootstrap admin (Incl. auth) to generate image data

  • As part of a plugin I’m developing I want to query the database and generate some image data based on that. I have the code to do that – however I need to make sure that the script can only be called by a logged in, authenticated admin user.

    If I call the script via the standard wp-admin/index.php it sets headers, and outputs a bunch of HTML which I don’t want/need.

    Ideally I’m looking for either:
    – A minimal code snippet that bootstraps the right files to give me $wpdb, config settings etc. and be able to check/know that the user is a logged in admin so I can include the code in my script and reference it directly (E.g. <img src="">)
    – An alternative to wp-admin/index.php that contains the above code so I can call my script through that (Something like <img src="/wp-admin/index-bare.php?page=my_plugin">)

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m not sure if this is the best way of achieving this, however what I’ve ended up doing is using admin-ajax.php, e.g.

    <img src="/wp-admin/admin-ajax.php?action=ses_wpscd_sales_graph">

    Then registering an action in my code as follows to a function to actually generate the image data:


    While this seems to work I’m a bit concerned that this isn’t really a supported way to use admin-ajax.php so I’m still on the lookout or something better if anyone has any ideas?

    Hi leewillis77,

    I just found your question while searching for something similar. The solution I found (on adrogen) was working fine:


    Afterwards you can check for admin:

    if (!is_super_admin()) {
     die('No admin, no luck!');

    (You cannot use is_admin(), because that checks if the script is used inside the administration panel, which is not the case).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bootstrap admin (Incl. auth) to generate image data’ is closed to new replies.