| User | Post |
|
6:02 am March 14, 2010
| beredon
Member
| | | |
|
| posts 4 |
|
|
Hi,
I've installed and configured Role Scoper on my WordPress 2.9.2 installation. I have a custom front-end and the beginning of my index.php attempts to retrieve the user's information.
global $current_user;
get_currentuserinfo();
print_r($current_user->display_name);
This outputs the following error:
Notice: Undefined property: WP_Scoped_User::$display_name
I am assuming that Role Scoper is over-riding this global variable.
Can I work around this? How do I retrieve the user's details?
Thanks.
|
|
|
9:56 am March 15, 2010
| Kevin
Admin
| | | |
|
| posts 2503 |
|
|
You're right that Role Scoper redefines the user with its WP_Scoped_User class. But that custom class is defined as a subclass of WP_User using the "extends" keyword. It inherits the display_name property, and does not override it.
It seems your $current_user is not validly loaded at that point. What does print_r( $current_user ) show? Did you confirm that the display_name can be retrieved if RS is deactivated?
|
|
|
4:07 am March 17, 2010
| beredon
Member
| | | |
|
| posts 4 |
|
|
Hi Kevin, thanks for your reply.
If WP_Scoped_User extends WP_User, then I think I've done something wrong! I hope it is just something silly and you can point me in the right direction.
I'm using WordPress v2.9.2 and Role Scoper v1.1.7.
Here's some example code:
<?php error_reporting(E_ALL); ini_set('display_errors', 1); define('WP_USE_THEMES', false); require('cms/wp-blog-header.php'); start_wp(); global $current_user; print_r($current_user); ?>
Output:
WP_Scoped_User Object
(
[groups] => Array
(
)
[has_user_roles] =>
[blog_roles] => Array
(
[] => Array
(
[rs_post_reader] => 1
[rs_page_reader] => 1
)
)
[term_roles] => Array
(
[category] => Array
(
[] => Array
(
)
)
)
[assigned_blog_roles] => Array
(
[] => Array
(
[rs_post_reader] => 1
[rs_page_reader] => 1
)
)
[assigned_term_roles] => Array
(
)
[qualified_terms] => Array
(
)
[is_administrator] =>
[is_module_administrator] => Array
(
)
[data] =>
[ID] => 0
[id] => 0
[caps] => Array
(
)
[cap_key] =>
[roles] => Array
(
)
[allcaps] => Array
(
)
[first_name] =>
[last_name] =>
[filter] =>
)
|
|
|
4:40 am March 17, 2010
| beredon
Member
| | | |
|
| posts 4 |
|
|
You're right. With Role Scoper de-activated, it outputs this:
WP_User Object
(
[data] =>
[ID] => 0
[id] => 0
[caps] => Array
(
)
[cap_key] =>
[roles] =>
Array
(
)
[allcaps] => Array
(
)
[first_name] =>
[last_name] =>
[filter] =>
)
So I am missing something. From the code I mentioned above, is there another file that I must include prior to getting the user information?
|
|
|
5:33 am March 17, 2010
| beredon
Member
| | | |
|
| posts 4 |
|
|
I've worked it out. It had nothing to do with Role Scoper, so I'm sorry for wasting your time!
When a user logs in to my WordPress installation, the cookie is only valid for the WordPress sub-directory. So I added this to my wp-config.php:
define('COOKIEPATH', '/');
Now my code in the root directory has access to the WordPress cookies.
By the way, in wp-config.php, the define method has to be called prior to:require_once(ABSPATH . 'wp-settings.php');
Thanks.
|
|