Jump to content

Help retrieving Global Variables


voogah

Recommended Posts

I know this has to do with Wordpress as well, but I have not had much luck with Wordpress Forums like I have this one.

 

I have a custom page that works with the Wordpress P2 theme.  I need to get the global variable $current_id.

 

I have used the following code, and it works great in IE but doesn't show anything in Safari or FireFox.  There are no errors, but it is blank.  So it is not retrieving the Global variable.

 

<?php
require_once '../wp-config.php'; 
global $current_user; 
get_currentuserinfo(); 
$member_online = $user_ID;
?>

 

Any suggestions!!

Thanks!

Link to comment
Share on other sites

global $current_user; 

Might help if $current_user was defined that we can see.

 

However.. why don't you try this?

get_currentuserinfo($current_user); 

function get_currentuserinfo($current_user){
       function stuff  entgiodsgiisdiofjdiosgjsio
}

 

This way you wont need a global. If that don't work, then I can easily say it's not getting the value of $current_user

Link to comment
Share on other sites

Thanks for your help TeddyKiller!

 

Unfortunately that does not help either!

 

I believe the $current_user global is set in the Wordpress pluggable.php file.  Here is the code: (again I believe....somewhat new to this)

 

function wp_set_current_user($id, $name = '') {
global $current_user;

if ( isset($current_user) && ($id == $current_user->ID) )
	return $current_user;

$current_user = new WP_User($id, $name);

setup_userdata($current_user->ID);

do_action('set_current_user');

return $current_user;
}
endif;

if ( !function_exists('wp_get_current_user') ) :

 

 

Again, the code I used in first post works in IE great!!  It is just Safari and FireFox that it doesn't??  The same is true if I try to call the Wordpress Login Cookies.  Works in IE but not Safari or Firefox.

 

It just doesn't seem to find it like I have not connected to Wordpress somehow!

 

Any help is appreciated!

 

Thanks!

Link to comment
Share on other sites

<?php
require_once '../wp-config.php'; 
global $current_user; 
get_currentuserinfo(); 
$member_online = $user_ID;
?>

Try an echo.

 

<?php
require_once '../wp-config.php'; 
echo $current_user;
exit;
//global $current_user; And for this..
//get_currentuserinfo(); commenting out temporarily 
//$member_online = $user_ID; same for this
?>

 

Does that give you values, for all browsers?

Link to comment
Share on other sites

I've even used the following code which seems to be more direct, but it still does not show for Safari or Firefox!

 

<?php

require './wp-config.php';

function wp_get_current_user() {

global $current_user;

 

get_currentuserinfo();

 

return $current_user;

}

$member_online = $user_ID;

 

echo $member_online;

 

?>

 

$user_ID is a string that is part of $current_user.

 

 

Link to comment
Share on other sites

The problem is where $current_user; is defined then. Work your way backwards. Try some troubleshooting until you find out the actual.. stop for it.  $current_user could not actually be the stop, the function to define it may be, or even any of the variables in that function could be, or where those variabels inside that function to define $curent_user are defined.

 

And so on. Being a third party script, it is pretty much impossible. Not many of us will actually install the exact same wordpress version as you and try to duplicate the problem.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.