Please clarify where you initiate the object $user in both ways (function.php and header.php).
This is another thread on stack with similar kind of issue, have a look:
Organizing Code in your WordPress Theme’s functions.php File?
Thanks,
Vee
Related Posts:
- Include WP_Query in my own PHP file?
- Include a external PHP file into a WordPress Custom Template
- Include files in functions.php
- load/require specific php files for specific pages/templates/post types
- ob_get_clean returns empty string, ob_get_flush outputs string
- where to include a php file
- nowplaying.include.php Will Not Display Results
- integrating external php library into wordpress- the right way
- Change title and meta description in included page (not template)
- Can I change a variable in a content part while calling it?
- the_author() not working outside the loop
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- Put CSS inside a PHP file and include it the right way
- functions.php is being included twice, creating PHP fatal errors
- Custom theme: Alternatives to long list of ‘include’ in functions.php
- PHP help get_template_directory + PHP include
- code is skipping a div
- Why does abstracting html from plugin code result in loss of access to wordpress functions?
- PHP include is only working in certain places in my custom WP theme
- Correct and safe way to include php content in my page
- What is the proper way to include a PHP framework into my theme?
- php include not working in custom page
- Post’s ID pattern?
- Using WP functions such as the_title() in an included php file
- What’s the best way to include PHP code in pages?
- How to include custom PHP file both in header and footer files
- Include a file that has a function in it
- How do I call an external php non WordPress class into functions.php?
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Before & After Content – After Content directly below Before Content when using require_once
- loading a php file to a specific page id
- How do I fetch a data from an external database into my wordpress homepage
- How do I fetch a data from an external database into my wordpress homepage
- PHP get_category() function redeclared
- How do I / Is it possible to execute an external PHP file / function inside WordPress?
- Include a php file that is above WP installation hierarchically?
- How can I include a file related to blog URL? Nothing seems to work
- WordPress blog set up
- Shortcode not passing variable to included file
- php “use” not working in template [closed]
- How to include a php file in every post and page [duplicate]
- Shortcode to include PHP file, pass various parameters to include?
- wordpress.org disallowing my plugin becuase of loading core files in cron cpanel file
- Should I use include(_once) or require(_once) for loading php-file with customizer settings?
- How to include checkbox in widget backend form?
- Upgrading PHP version results in “Use of undefined constant WP_CONTENT_DIR” warning?
- renaming an admin menu item with decimal array index number
- How to add 2 posts under another post? Formatting should be intact
- Can’t Find a Way to Edit the Home Page Content [closed]
- Fatal error: Call to undefined function wpsc_cart_item_count()
- No wp-config.php file on local install of wordpress – site still displays
- Make first letter of my taxonomy uppercase
- Insert all post IDs in new database table
- Hiding WordPress Plugin Source Code
- Is there a way to enforce the type of an object returned by a function that could return anything?
- Renaming post IDs – Okay to do?
- Add the Name of Products Ordered to Admin New Order Email WooCommerce
- get current product name in functions.php
- Embed html in php code
- Get Post Meta from ID in functions.php
- How can I dynamically update the class in my shortcode?
- Concatenate output of php function into string
- Why File_exists returns true with or without ABSPATH?
- WordPress automatically adds links to uploaded images
- Security for data obtained from the database
- Pull GetOption() variable into jQuery dynamically created html
- get_template_directory_uri() providing wrong path for img
- Shortcode not staying inside div tag
- HTML showing after PHP code in tag
- Adding Author Box Meta Links with Co-Authors
- Lost in trying to create user database system
- Remove   from the_excerpt
- Why is my max_upload_filesize being limited to 2M? [duplicate]
- Can’t pass the variable from a select to PHP query
- Unexpected token ILLEGAL, even on clean install – jquery-issue?
- “if parent category is” conditional?
- Deactivate a plugin on wp version
- the_post_thumbnail issues
- linked php file not executing php
- Add other class content with reference class value
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Slug duplicates once clicking on link
- Find and print first entry from WordPress post in custom excerpt?
- Language does not switch while cache is enabled
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Limit content size by character or word in database
- Set user status to absent on WordPress
- Customizer: How to Sanitize a Decimal Number Range
- Switch position of elements in the footer [closed]
- Problem with ajax request and directory structure after site migration
- Access methods in plugin template
- WordPress HTML Helper
- Adding unique marketing messages between certain products whilst using isotope/Infinite Scroll
- Notice: Undefined index: fix with isset [closed]
- List sibling pages widget, exclude current page
- Amending PHP for WordPress Theme
- get_permalink returning first letter
- Shortcode for Visual Composer Grid fails turning string to integer
- Import js variables loaded via wp_localize_script() into js module without global scope connection