Click here to Skip to main content
15,914,221 members
Home / Discussions / Web Development
   

Web Development

 
QuestionDebugging two ASP.NET projects with Chrome - Failed to launch debug adapter Pin
glen20516-Dec-20 21:55
glen20516-Dec-20 21:55 
AnswerRe: Debugging two ASP.NET projects with Chrome - Failed to launch debug adapter Pin
F-ES Sitecore17-Dec-20 22:51
professionalF-ES Sitecore17-Dec-20 22:51 
QuestionPHP4.3 Mod, coloring table rows Pin
jkirkerx1-Dec-20 9:29
professionaljkirkerx1-Dec-20 9:29 
AnswerRe: PHP4.3 Mod, coloring table rows [solved] Pin
jkirkerx1-Dec-20 9:34
professionaljkirkerx1-Dec-20 9:34 
AnswerRe: PHP4.3 Mod, coloring table rows Pin
Richard Deeming1-Dec-20 21:55
mveRichard Deeming1-Dec-20 21:55 
GeneralRe: PHP4.3 Mod, coloring table rows Pin
jkirkerx2-Dec-20 8:30
professionaljkirkerx2-Dec-20 8:30 
QuestionHow to insert roles in php and mysql? Pin
Nicolas Veloso16-Nov-20 6:04
Nicolas Veloso16-Nov-20 6:04 
SuggestionRe: How to insert roles in php and mysql? Pin
Richard Deeming16-Nov-20 21:51
mveRichard Deeming16-Nov-20 21:51 
QuestionBlazor SPA Pin
Super Lloyd16-Nov-20 1:26
Super Lloyd16-Nov-20 1:26 
QuestionDesign questions about asp.net core website and asp.net core webapi Pin
instantmaker13-Nov-20 9:04
instantmaker13-Nov-20 9:04 
AnswerRe: Design questions about asp.net core website and asp.net core webapi Pin
Afzaal Ahmad Zeeshan14-Nov-20 1:50
professionalAfzaal Ahmad Zeeshan14-Nov-20 1:50 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
instantmaker14-Nov-20 2:49
instantmaker14-Nov-20 2:49 
GeneralRe: Design questions about asp.net core website and asp.net core webapi Pin
Afzaal Ahmad Zeeshan14-Nov-20 3:17
professionalAfzaal 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
instantmaker16-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
Leif 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
instantmaker22-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
Leif 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
instantmaker22-Dec-20 10:39 
QuestionDesign question with asp.net core and asp.net core api Pin
instantmaker13-Nov-20 6:18
instantmaker13-Nov-20 6:18 
QuestionI keep getting a “Call to undefined function..” error displaying Pin
IAmSirAskAlot9-Nov-20 18:25
IAmSirAskAlot9-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 

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.