1

I originally created a single .php file with multiple functions to integrate Gravity Forms into the needs of a website. The plugin grew to 8000 lines before I broke it up into several files in the same folder; it was just too much scrolling and hard to it organized as I worked on it. The functions rely heavily on the user and their roles, affecting nearly every function. Once the functions were split into different files, I'm having to include

$user = is_user_logged_in() ? wp_get_current_user() : null;
if ($user) {
    $roles = $user->roles;
}

and often have to run that $user object through one of several other functions to see if they fall into groups and categories.

I can't tell if WordPress somehow stores the user (and subsequent calls only reference the object), or if each call is a query and creates a new instance. If the latter, is there a smarter way to go about doing this (perhaps creating my own user class to avoid repeatedly hitting those same calls)?

fxrgc
  • 110
  • 8

0 Answers0