[wp-trac] [WordPress Trac] #42412: Calling get_current_user_id() and setting $current_user gives unexpected behaviour
WordPress Trac
noreply at wordpress.org
Thu Nov 2 01:19:32 UTC 2017
#42412: Calling get_current_user_id() and setting $current_user gives unexpected
behaviour
--------------------------+-----------------------------
Reporter: gertmeeusen | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.8.3
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Steps to reproduce, paste this code in functions.php
{{{#!php
<?php
if ( ! function_exists( 'wp_get_current_user' ) ) {
die('The file with wp_get_current_user() has not loaded yet into
memory.');
}else{
echo '----echo get_current_user_id()----</br>';
echo '$current_user global? ';
echo array_key_exists('current_user',
$GLOBALS)?"true</br>":"false</br>";
echo get_current_user_id() . '</br>';
echo '$current_user global? ';
echo array_key_exists('current_user',
$GLOBALS)?"true</br>":"false</br>";
echo get_current_user_id() . '</br>';
echo get_current_user_id() . '</br>';
echo '----echo $current_user after 1 call----</br>';
$current_user = get_current_user_id();
echo $current_user . '</br>';
echo $current_user . '</br>';
echo $current_user . '</br>';
echo '----echo $current_user, 1 call each time----</br>';
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = get_current_user_id();
echo $current_user . '</br>';
echo '----echo $current_user, $current_user = 5 before each
call----</br>';
$current_user = 5;
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = 5;
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = 5;
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = 5;
$current_user = get_current_user_id();
echo $current_user . '</br>';
$current_user = 5;
$current_user = get_current_user_id();
echo $current_user . '</br>';
echo '----echo $current_user, $current_user = 5 NO call----</br>';
$current_user = 5;
echo $current_user . '</br>';
$current_user = 5;
echo $current_user . '</br>';
$current_user = 5;
echo $current_user . '</br>';
$current_user = 5;
echo $current_user . '</br>';
$current_user = 5;
echo $current_user . '</br>';
echo '----echo $cu, 1 call each time---</br>';
$cu = get_current_user_id();
echo $cu . '</br>';
$cu = get_current_user_id();
echo $cu . '</br>';
$cu = get_current_user_id();
echo $cu . '</br>';
$cu = get_current_user_id();
echo $cu . '</br>';
echo '----echo $current_user_1, 1 call each time----</br>';
$current_user_1 = get_current_user_id();
echo $current_user_1 . '</br>';
$current_user_1 = get_current_user_id();
echo $current_user_1 . '</br>';
$current_user_1 = get_current_user_id();
echo $current_user_1 . '</br>';
$current_user_1 = get_current_user_id();
echo $current_user_1 . '</br>';
echo '----echo $current_user->ID ----</br>';
$current_user = wp_get_current_user();
echo $current_user->ID . '</br>';
$current_user = wp_get_current_user();
echo $current_user->ID . '</br>';
$current_user = wp_get_current_user();
echo $current_user->ID . '</br>';
$current_user = wp_get_current_user();
echo $current_user->ID . '</br>';
echo '----echo $current_user_obj->ID ----</br>';
$current_user_obj = wp_get_current_user();
echo $current_user_obj->ID . '</br>';
$current_user_obj = wp_get_current_user();
echo $current_user_obj->ID . '</br>';
$current_user_obj = wp_get_current_user();
echo $current_user_obj->ID . '</br>';
$current_user_obj = wp_get_current_user();
echo $current_user_obj->ID . '</br>';
}
}}}
That outputs:
{{{
----echo get_current_user_id()----
$current_user global? false
1
$current_user global? true
1
1
----echo $current_user after 1 call----
1
1
1
----echo $current_user, 1 call each time----
0
1
0
1
0
----echo $current_user, $current_user = 5 before each call----
0
0
0
0
0
----echo $current_user, $current_user = 5 NO call----
5
5
5
5
5
----echo $cu, 1 call each time---
0
0
0
0
----echo $current_user_1, 1 call each time----
0
0
0
0
----echo $current_user->ID ----
0
0
0
0
----echo $current_user_obj->ID ----
0
0
0
0
}}}
Issue in _wp_get_current_user() ?
Using php 7.0
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42412>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list