• Hey there. I need to use 2 WP functions outside of plugin’s main file, let’s call this file functions.php . I need is_user_logged_in() and to get current user id which one get from global variable $current_user.
    What should I include or what else I should do to use these in files other than main plugin file?
    Thanks in advance

Viewing 1 replies (of 1 total)
  • Jay

    (@phyrax)

    Flyer, the only way to do that is include wp-load.php… however, I think it’s best to make your new file and include it in the main, that way you can use WordPress’ functions without loading resources twice.

    Example:

    <?php
         /* FILE: mainPluginFile.php */
         include('userFile.php');
    
         /* The rest of your code here */
    ?>
    <?php
        /* FILE: userFile.php */
        function userData(){
             /* Do your code here */
        }
    
        add_action('init', 'userData');
    ?>

    You might want to also look into the get_currentuserinfo function which you can wrap inside the is_user_logged_in method.

Viewing 1 replies (of 1 total)
  • The topic ‘WP functions in "side" plugin files’ is closed to new replies.