0
votes

How do I verify a user is_admin() in a wordpress plugin file that looks similar to this:

// Load WP core
define( 'WP_USE_THEMES', false );
require( '../../../wp-load.php' );

if (is_admin()) {
    header('Content-Type: application/pdf');
    echo base64_decode($pdf_data);
}

Basically, a user will go to a php file within the plugin and if they are logged in as Admin, they get to see the pdf data. If they are not logged in, they don't see anything.

1
Don't directly load a .php file located in the plugins folder - everything needs to go through the wordpress api. codex.wordpress.org/Adding_Administration_MenusTim G

1 Answers

0
votes

I think would look a lot like this:

// Load WP core
define( 'WP_USE_THEMES', false );
require( '../../../wp-load.php' );

function so_48351789(){
  global $user;
  $the_ID = $user->ID;
  if (is_admin($the_ID)) {
      header('Content-Type: application/pdf');
      echo base64_decode($pdf_data);
  }
}
add_action( 'send_headers', 'so_48351789' );

You'd also only want to fire that on one-page, see: Example from the WordPress Codex