After refactoring/restructuring files in my plug-in, I now get the error
Uncaught Error: Call to undefined function get_userdata()
after code
$current_user_id = get_current_user_id();
$current_user_meta = get_userdata($current_user_id);
in mydomain.local/wp-content/plugins/my-project/my-project.php
I also tried as it was before, in another .php file that was required
by my-project.php
These lines are and were appearing quite early in my plug-in code ... am I missing some dependency before running them?
After refactoring/restructuring files in my plug-in, I now get the error
Uncaught Error: Call to undefined function get_userdata()
after code
$current_user_id = get_current_user_id();
$current_user_meta = get_userdata($current_user_id);
in mydomain.local/wp-content/plugins/my-project/my-project.php
I also tried as it was before, in another .php file that was required
by my-project.php
These lines are and were appearing quite early in my plug-in code ... am I missing some dependency before running them?
Share Improve this question edited Apr 11, 2019 at 13:18 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Apr 11, 2019 at 12:42 TTTTTT 3291 gold badge4 silver badges17 bronze badges 3- Where exactly did you put these lines? – Krzysiek Dróżdż Commented Apr 11, 2019 at 12:43
- Indeed, I forgot this so I have added it in the question. In the plug-in's main php file. – TTT Commented Apr 11, 2019 at 12:48
- I think I found the reason. It may be that the lines are not correctly wrapped anymore ... Looking to check and correct it. – TTT Commented Apr 11, 2019 at 12:54
1 Answer
Reset to default -1Solution found: the reason was that the code including those lines were included in plug-in's main file and were wrapped in the shortcode launch anymore.
I had to put things in another file,like for example
function load_shortcode( $atts ){
require_once(getPluginPath().('my-project.start.php'));
}
add_shortcode( 'my-project', 'load_shortcode' );
and lines had to be in my-project.start.php
getPluginPath()
is NOT a native WordPress function, don't look for it, the only thing to know here is that it generates a path string.