Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a problem modifying one of WP plugins, I need to insert some data from an object into a MySQL table, but I have troubles with pulling it out of an object array

Here is a piece of var_export of $current_user

WP_User::__set_state(array(
   'data' =>
  stdClass::__set_state(array(
     'ID' => '1',
     'membership_level' =>
    stdClass::__set_state(array(
       'ID' => '2',

I've tried to do it myself, but I lack knowledge on objective PHP, here is what I tried:

$current_user->WP_User->data->ID
$current_user->WP_User->data->membership_level->ID

Echoing it doesn't show anything

share|improve this question
1  
Just $current_user->data->ID. –  Ja͢ck Feb 18 at 1:18
1  
Are you trying to add membership_level to the user object? I believe you may want to look at codex.wordpress.org/Function_Reference/wp_update_user. Also, php lets you try to get non existing properties with no warning that they don't exist. Try on the command line: php -r '$x = new StdClass(); echo $x->a->b;' –  bryjohns Feb 18 at 1:19
    
I wanted to use some of this data in my own function to give access to people based on the day of the course that they are on, but PaidMembershipsPro doesn't have that option, so I made a MySQL table to hold all the extra information that I need. Yeah, my problem was that I was calling to WP_User which is the name of $current_user object. Thanks guys, I've been struggling on this for an hour believe it or not :P Jack you may want to post it as an answer, as it was exactly what was wrong. –  Mateusz Bartkowski Feb 18 at 1:27
1  
Oh I believe it. A little tip - use something like netbeans, hyperlinking code is invaluable. Especially for wordpress development. Soon as you want to do something out of the norm you're going to be looking at the core code a lot. Also, I find print_r more readable than var_dump –  bryjohns Feb 18 at 1:33
    
Yeah, I've been doing all the coding in PSPad and I've been delaying using better software because I didn't really need anything better, but I will have to do it sooner or later. I don't know why didn't I use print_r, it seems much better for printing objects –  Mateusz Bartkowski Feb 18 at 1:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.