0
votes

On my WP powered site, I have a plugin that manages my sites payments & members. This plugin doesn't have any inbuilt "admin access restrictions" meaning if I allow somebody admin access to my WP site, they automatically get full & unrestricted access to every URL of this particular plugin.

The plugin loads it's pages within an iFrame on the admin backend. So when you're logged into the WP admin area, and you click this plugin, it loads an entire UI within an iFrame and that UI has it's own menu bar that leads to various areas of that particular plugin's UI. As an example, when you are logged into the WP admin area, and you click this particular plugin on the left hand side menu bar, it takes you to this URL within the WP admin area:

http://MySite.com/wp-admin/admin.php?page=MemberManagementPlugin

My idea for restricting access to certain areas of that plugin, was to get the username of the currently logged in WP user and get the URL of the child frame, and then do something like this (pseudo code):

$username-of-logged-in-wp-user = somehow get the username of the logged in wp user
$childframeurl = the url of the currently iframed page
if ($username-of-logged-in-wp-user != $a-username-i-want-to-give-full-access-to && $childframeurl == $url-i-dont-want-every-user-to-be-able-to-see) 
{ $childframeurl = 'http://mysite.com/sorry-you-cant-view-this }

I'll work out the rest of the details, but this idea hinges entirely upon me being able to get the username of the logged in WP user while at the BACKEND of the WP site. I already know how to get the username of a logged in WP user from the frontend, which can be done like this (from: http://codex.wordpress.org/Function_Reference/get_currentuserinfo ):

<?php global $current_user;
get_currentuserinfo();
echo 'Username: ' . $current_user->user_login . "\n";
?>

However, that method does not work on the backend of the site in the admin area.

So, does anybody know how to return the username of a logged in WP user when in the backend/admin area of the WP site?

1

1 Answers

2
votes

Nevermind, got it. Just included this at the bottom of wp-admin/admin-header.php

$currentloggedinuser = $current_user->user_login;

And I can handle the rest...boy do I feel dumb.