admin管理员组

文章数量:1425747

I have a simple plugin that Iam trying to use to learn OOP, please bear with me. I am setting up a part of it to show front end account data and want to grab the current user info. I know how to do this procedurally but I'm confused how to do this in OOP, I keep getting undefined function errors.

The structure for the class is set up as follows:

<?php 

class FendAccount {

    public $user;

    public function __construct () {

    }

    public function set_user(){

    }


} //END OF CLASS

$frontend = new FendAccount;
echo $frontend;

?>

This is in a separate class file that is being required by the main plugin PHP file and so should be firing as the plugin is loaded.

Am I rigght in thinking that a method that sets the property $user will be the best way to do this, so that I can call that method/object wherever I want in the plugin whenever I need to work with the current user? or is that overkill because wordpress already provides this functionality.

Or, should I just add a function to my main plugin PHP file that populates a global $current_user with the current user details via wp_get_current_user?

Thanks

本文标签: plugin developmentWordpress OOP get current user question