Click here to Skip to main content
15,354,423 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
Afzaal Ahmad Zeeshan14-Nov-20 3:17
mveAfzaal Ahmad Zeeshan14-Nov-20 3:17 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
instantmaker16-Nov-20 13:03
Memberinstantmaker16-Nov-20 13:03 
AnswerRe: Design questions about asp.net core website and asp.net core webapi Pin
Leif Simon Goodwin22-Dec-20 7:17
MemberLeif Simon Goodwin22-Dec-20 7:17 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
instantmaker22-Dec-20 7:34
Memberinstantmaker22-Dec-20 7:34 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
Leif Simon Goodwin22-Dec-20 9:07
MemberLeif Simon Goodwin22-Dec-20 9:07 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
instantmaker22-Dec-20 10:39
Memberinstantmaker22-Dec-20 10:39 
QuestionDesign question with asp.net core and asp.net core api Pin
instantmaker13-Nov-20 6:18
Memberinstantmaker13-Nov-20 6:18 
QuestionI keep getting a “Call to undefined function..” error displaying Pin
IAmSirAskAlot9-Nov-20 18:25
MemberIAmSirAskAlot9-Nov-20 18:25 
I am new to PHP programming and I am trying to teach myself WordPress theme development for fun and I am using PhpStorm as my IDE.

I am trying to better understand the inner-workings of WordPress and I am running into a roadblock on something.

I have a sandbox plugin that I created to use to play around with WordPress.

In my wp-content/plugins/sandbox/sandbox.php file, I am just running basic PHP code to help me get used to the language as it relates to WordPress.

Also, I installed both Kint and Whoops using Composer to help with debugging.

Now that I got that out of the way, here is what I am doing:

Code #1
PHP
namespace MyDevPlayground\Sandbox;

add_action( 'loop_start', __NAMESPACE__ . '\process_the_string' );
function process_the_string() {

    $current_user = wp_get_current_user();

    $data_packet = array(
        'id'    => $current_user->ID,
        'email' => $current_user->user_email,
        'name'  => array(
            'first_name' => $current_user->user_firstname,
            'last_name'  => $current_user->user_lastname,
        ),
    );

    render_user_message( $data_packet );
}

function render_user_message( array $current_user ) {

    $user_id = $current_user['id'];

    d( "Welcome {$current_user['name']['first_name']}, your user id is { {$user_id} }." );

    ddd( "Welcome {$current_user['name']['first_name']}, your user id is {$user_id}." );
}

When I run Code #1 above everything is fine and Kint displays the values just fine.

Now for the problem I am having that I don’t understand about WordPress:

Code #2


<pre lang="PHP">namespace MyDevPlayground\Sandbox;

add_action( 'loop_start', __NAMESPACE__ . '\check_logged_in_user' );
function check_logged_in_user(){
    $current_user = wp_get_current_user();
    if ( 0 == $current_user->ID ) {
        d('Not logged in');
    } else {
        ddd('Logged in');
    }
}

check_logged_in_user();

When I run Code #2 above, Whoops reports the following error:

Call to undefined function MyDevPlaygroundSandbox\wp_get_current_user

For some reason when I run Code #1, the wp_get_current_user() function loads just fine, but not with Code #2.

Can someone help me understand why this is in laymen’s terms if possible?

What is the difference between Code #1 and Code #2?

How come the wp_get_current_user() function is not loading in Code #2, but it is in Code #1?

Thank you for your help.
QuestionWeb API Deserialization Problem Pin
Kevin Marois9-Nov-20 8:04
professionalKevin Marois9-Nov-20 8:04 
AnswerRe: Web API Deserialization Problem Pin
Richard Deeming9-Nov-20 22:20
mveRichard Deeming9-Nov-20 22:20 
GeneralRe: Web API Deserialization Problem Pin
Kevin Marois10-Nov-20 7:18
professionalKevin Marois10-Nov-20 7:18 
GeneralRe: Web API Deserialization Problem Pin
Richard Deeming10-Nov-20 21:41
mveRichard Deeming10-Nov-20 21:41 
GeneralRe: Web API Deserialization Problem Pin
Kevin Marois11-Nov-20 7:16
professionalKevin Marois11-Nov-20 7:16 
GeneralRe: Web API Deserialization Problem Pin
Kevin Marois11-Nov-20 7:54
professionalKevin Marois11-Nov-20 7:54 
GeneralRe: Web API Deserialization Problem Pin
Richard Deeming11-Nov-20 22:42
mveRichard Deeming11-Nov-20 22:42 
GeneralRe: Web API Deserialization Problem Pin
Kevin Marois12-Nov-20 6:49
professionalKevin Marois12-Nov-20 6:49 
Question[Solved] Firefox storage get undefined Pin
Valentinor2-Nov-20 21:56
MemberValentinor2-Nov-20 21:56 
AnswerRe: Firefox storage get undefined Pin
Valentinor4-Nov-20 3:02
MemberValentinor4-Nov-20 3:02 
QuestionCallback JS help Pin
Member 149761991-Nov-20 19:35
MemberMember 149761991-Nov-20 19:35 
AnswerRe: Callback JS help Pin
Richard Deeming1-Nov-20 22:20
mveRichard Deeming1-Nov-20 22:20 
QuestionCSS flex help_ circle transform into oval Pin
Member 1497619929-Oct-20 23:30
MemberMember 1497619929-Oct-20 23:30 
QuestionCSS background(url) not working Pin
Member 1497619926-Oct-20 21:40
MemberMember 1497619926-Oct-20 21:40 
AnswerRe: CSS background(url) not working Pin
Richard Deeming26-Oct-20 22:26
mveRichard Deeming26-Oct-20 22:26 
GeneralRe: CSS background(url) not working Pin
Member 1497619926-Oct-20 22:30
MemberMember 1497619926-Oct-20 22:30 
QuestionChanging documentroot in Apache http.conf file causes PHP to stop working Pin
MontanaMan9-Oct-20 16:58
MemberMontanaMan9-Oct-20 16:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.